Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refetch after creating managed certificate #685

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/cmd/certificate/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func createManaged(s state.State, cmd *cobra.Command) (*hcloud.Certificate, erro
if err := s.ActionProgress(cmd, s, res.Action); err != nil {
return nil, err
}
cmd.Printf("Certificate %d created\n", res.Certificate.ID)
return res.Certificate, nil
defer cmd.Printf("Certificate %d created\n", res.Certificate.ID)
cert, _, err := s.Client().Certificate().GetByID(s, res.Certificate.ID)
if err != nil {
return nil, err
}
return cert, nil
}
40 changes: 34 additions & 6 deletions internal/cmd/certificate/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func TestCreateManaged(t *testing.T) {
}, nil, nil)
fx.ActionWaiter.EXPECT().
ActionProgress(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 321})
fx.Client.CertificateClient.EXPECT().
GetByID(gomock.Any(), int64(123)).
Return(&hcloud.Certificate{
ID: 123,
Name: "test",
Type: hcloud.CertificateTypeManaged,
DomainNames: []string{"example.com"},
}, nil, nil)

out, _, err := fx.Run(cmd, []string{"--name", "test", "--type", "managed", "--domain", "example.com"})

Expand Down Expand Up @@ -71,25 +79,45 @@ func TestCreateManagedJSON(t *testing.T) {
Name: "test",
Type: hcloud.CertificateTypeManaged,
Created: time.Date(2020, 8, 24, 12, 0, 0, 0, time.UTC),
NotValidBefore: time.Date(2020, 8, 24, 12, 0, 0, 0, time.UTC),
NotValidAfter: time.Date(2036, 8, 12, 12, 0, 0, 0, time.UTC),
NotValidBefore: time.Time{},
NotValidAfter: time.Time{},
DomainNames: []string{"example.com"},
Labels: map[string]string{"key": "value"},
UsedBy: []hcloud.CertificateUsedByRef{{
ID: 123,
Type: hcloud.CertificateUsedByRefTypeLoadBalancer,
}},
Status: &hcloud.CertificateStatus{
Error: &hcloud.Error{
Code: "cert_error",
Message: "Certificate error",
},
Issuance: hcloud.CertificateStatusTypePending,
Renewal: hcloud.CertificateStatusTypeUnavailable,
},
},
Action: &hcloud.Action{ID: 321},
}, nil, nil)
fx.ActionWaiter.EXPECT().
ActionProgress(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 321})
fx.Client.CertificateClient.EXPECT().
GetByID(gomock.Any(), int64(123)).
Return(&hcloud.Certificate{
ID: 123,
Name: "test",
Type: hcloud.CertificateTypeManaged,
Created: time.Date(2020, 8, 24, 12, 0, 0, 0, time.UTC),
NotValidBefore: time.Date(2020, 8, 24, 12, 0, 0, 0, time.UTC),
NotValidAfter: time.Date(2036, 8, 12, 12, 0, 0, 0, time.UTC),
DomainNames: []string{"example.com"},
Labels: map[string]string{"key": "value"},
UsedBy: []hcloud.CertificateUsedByRef{{
ID: 123,
Type: hcloud.CertificateUsedByRefTypeLoadBalancer,
}},
Status: &hcloud.CertificateStatus{
Issuance: hcloud.CertificateStatusTypeCompleted,
Renewal: hcloud.CertificateStatusTypeUnavailable,
},
Fingerprint: "fingerprint placeholder",
Certificate: "certificate data placeholder",
}, nil, nil)

jsonOut, out, err := fx.Run(cmd, []string{"-o=json", "--name", "test", "--type", "managed", "--domain", "example.com"})

Expand Down
14 changes: 4 additions & 10 deletions internal/cmd/certificate/testdata/managed_create_response.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"certificate": {
"certificate": "",
"certificate": "certificate data placeholder",
"created": "2020-08-24T12:00:00Z",
"domain_names": [
"example.com"
],
"fingerprint": "",
"fingerprint": "fingerprint placeholder",
"id": 123,
"labels": {
"key": "value"
Expand All @@ -14,14 +14,8 @@
"not_valid_after": "2036-08-12T12:00:00Z",
"not_valid_before": "2020-08-24T12:00:00Z",
"status": {
"error": {
"Details": null,
"code": "cert_error",
"details": null,
"message": "Certificate error"
},
"issuance": "",
"renewal": ""
"issuance": "completed",
"renewal": "unavailable"
},
"type": "managed",
"used_by": [
Expand Down
Loading