Skip to content

Commit a83e05e

Browse files
authored
Revise azcertificates models (Azure#18282)
1 parent f736da9 commit a83e05e

File tree

7 files changed

+187
-180
lines changed

7 files changed

+187
-180
lines changed

sdk/keyvault/azcertificates/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
* Methods `BeginCreateCertificate`, `BeginDeleteCertificate`, and `BeginRecoverDeletedCertificate` now return a `*runtime.Poller[T]` with their respective response types.
88
* Options types with a `ResumeToken` field now take the token by value.
99
* The poller for `BeginCreateCertificate` now returns the created certificate from its `PollUntilDone` method.
10+
* Changed type of certificate `Tags` to `map[string]*string`
11+
* Deleted `UpdateCertificatePropertiesOptions` fields
12+
* Renamed types
13+
* `ListIssuersPropertiesOfIssuersResponse` to `ListPropertiesOfIssuersResponse`
14+
* `ListCertificatesOptions` to `ListPropertiesOfCertificatesOptions`
15+
* `ListCertificateVersionsOptions` to `ListPropertiesOfCertificateVersionsOptions`
16+
* Renamed `ListDeletedCertificatesResponse.Certificates` to `.DeletedCertificates`
1017

1118
### Bugs Fixed
1219
* LROs now correctly exit the polling loop in `PollUntilDone()` when the operations reach a terminal state.

sdk/keyvault/azcertificates/client.go

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type BeginCreateCertificateOptions struct {
7070
Enabled *bool `json:"enabled,omitempty"`
7171

7272
// Application specific metadata in the form of key-value pairs
73-
Tags map[string]string `json:"tags,omitempty"`
73+
Tags map[string]*string `json:"tags,omitempty"`
7474

7575
// ResumeToken is a token for resuming long running operations from a previous poller
7676
ResumeToken string
@@ -91,11 +91,6 @@ func (c *Client) BeginCreateCertificate(ctx context.Context, certificateName str
9191
options = &BeginCreateCertificateOptions{}
9292
}
9393

94-
var tags map[string]*string
95-
if options.Tags != nil {
96-
tags = convertToGeneratedMap(options.Tags)
97-
}
98-
9994
handler := beginCreateCertificateOperation{
10095
poll: func(ctx context.Context, endpoint string) (*http.Response, error) {
10196
req, err := runtime.NewRequest(ctx, http.MethodGet, endpoint)
@@ -127,7 +122,7 @@ func (c *Client) BeginCreateCertificate(ctx context.Context, certificateName str
127122
certificateName,
128123
generated.CertificateCreateParameters{
129124
CertificatePolicy: policy.toGeneratedCertificateCreateParameters(),
130-
Tags: tags,
125+
Tags: options.Tags,
131126
CertificateAttributes: &generated.CertificateAttributes{Enabled: options.Enabled},
132127
},
133128
options.toGenerated(),
@@ -170,7 +165,7 @@ func (c *Client) GetCertificate(ctx context.Context, certificateName string, opt
170165

171166
return GetCertificateResponse{
172167
CertificateWithPolicy: CertificateWithPolicy{
173-
Properties: propertiesFromGenerated(resp.Attributes, convertGeneratedMap(resp.Tags), resp.ID, resp.X509Thumbprint),
168+
Properties: propertiesFromGenerated(resp.Attributes, resp.Tags, resp.ID, resp.X509Thumbprint),
174169
CER: resp.Cer,
175170
ContentType: resp.ContentType,
176171
ID: resp.ID,
@@ -240,7 +235,7 @@ func deleteCertificateResponseFromGenerated(g generated.KeyVaultClientDeleteCert
240235
RecoveryID: g.RecoveryID,
241236
DeletedOn: g.DeletedDate,
242237
ScheduledPurgeDate: g.ScheduledPurgeDate,
243-
Properties: propertiesFromGenerated(g.Attributes, convertGeneratedMap(g.Tags), g.ID, g.X509Thumbprint),
238+
Properties: propertiesFromGenerated(g.Attributes, g.Tags, g.ID, g.X509Thumbprint),
244239
CER: g.Cer,
245240
ContentType: g.ContentType,
246241
ID: g.ID,
@@ -340,7 +335,7 @@ func (c *Client) GetDeletedCertificate(ctx context.Context, certificateName stri
340335
RecoveryID: resp.RecoveryID,
341336
DeletedOn: resp.DeletedDate,
342337
ScheduledPurgeDate: resp.ScheduledPurgeDate,
343-
Properties: propertiesFromGenerated(resp.Attributes, convertGeneratedMap(resp.Tags), resp.ID, resp.X509Thumbprint),
338+
Properties: propertiesFromGenerated(resp.Attributes, resp.Tags, resp.ID, resp.X509Thumbprint),
344339
CER: resp.Cer,
345340
ContentType: resp.ContentType,
346341
ID: resp.ID,
@@ -392,7 +387,7 @@ type ImportCertificateOptions struct {
392387
Password *string `json:"pwd,omitempty"`
393388

394389
// Application specific metadata in the form of key-value pairs
395-
Tags map[string]string `json:"tags,omitempty"`
390+
Tags map[string]*string `json:"tags,omitempty"`
396391
}
397392

398393
// ImportCertificateResponse contains response fields for Client.ImportCertificate
@@ -407,10 +402,6 @@ func (c *Client) ImportCertificate(ctx context.Context, certificateName string,
407402
if options == nil {
408403
options = &ImportCertificateOptions{}
409404
}
410-
var tags map[string]*string
411-
if options.Tags != nil {
412-
tags = convertToGeneratedMap(options.Tags)
413-
}
414405
resp, err := c.genClient.ImportCertificate(
415406
ctx,
416407
c.vaultURL,
@@ -422,7 +413,7 @@ func (c *Client) ImportCertificate(ctx context.Context, certificateName string,
422413
},
423414
CertificatePolicy: options.CertificatePolicy.toGeneratedCertificateCreateParameters(),
424415
Password: options.Password,
425-
Tags: tags,
416+
Tags: options.Tags,
426417
},
427418
&generated.KeyVaultClientImportCertificateOptions{},
428419
)
@@ -432,7 +423,7 @@ func (c *Client) ImportCertificate(ctx context.Context, certificateName string,
432423

433424
return ImportCertificateResponse{
434425
CertificateWithPolicy: CertificateWithPolicy{
435-
Properties: propertiesFromGenerated(resp.Attributes, convertGeneratedMap(resp.Tags), resp.ID, resp.X509Thumbprint),
426+
Properties: propertiesFromGenerated(resp.Attributes, resp.Tags, resp.ID, resp.X509Thumbprint),
436427
CER: resp.Cer,
437428
ContentType: resp.ContentType,
438429
ID: resp.ID,
@@ -443,8 +434,8 @@ func (c *Client) ImportCertificate(ctx context.Context, certificateName string,
443434
}, nil
444435
}
445436

446-
// ListCertificatesOptions contains optional parameters for Client.ListCertificates
447-
type ListCertificatesOptions struct {
437+
// ListPropertiesOfCertificatesOptions contains optional parameters for Client.ListCertificates
438+
type ListPropertiesOfCertificatesOptions struct {
448439
// placeholder for future optional parameters.
449440
}
450441

@@ -463,7 +454,7 @@ func listCertsPageFromGenerated(i generated.KeyVaultClientGetCertificatesRespons
463454

464455
for _, v := range i.Value {
465456
vals = append(vals, &CertificateItem{
466-
Properties: propertiesFromGenerated(v.Attributes, convertGeneratedMap(v.Tags), v.ID, v.X509Thumbprint),
457+
Properties: propertiesFromGenerated(v.Attributes, v.Tags, v.ID, v.X509Thumbprint),
467458
ID: v.ID,
468459
})
469460
}
@@ -478,7 +469,7 @@ func listCertsPageFromGenerated(i generated.KeyVaultClientGetCertificatesRespons
478469
// public part of a stored certificate. The LIST operation is applicable to all certificate types, however only the
479470
// base certificate identifier, attributes, and tags are provided in the response. Individual versions of a
480471
// certificate are not listed in the response. This operation requires the certificates/list permission.
481-
func (c *Client) NewListPropertiesOfCertificatesPager(options *ListCertificatesOptions) *runtime.Pager[ListPropertiesOfCertificatesResponse] {
472+
func (c *Client) NewListPropertiesOfCertificatesPager(options *ListPropertiesOfCertificatesOptions) *runtime.Pager[ListPropertiesOfCertificatesResponse] {
482473
pager := c.genClient.NewGetCertificatesPager(c.vaultURL, nil)
483474
return runtime.NewPager(runtime.PagingHandler[ListPropertiesOfCertificatesResponse]{
484475
More: func(page ListPropertiesOfCertificatesResponse) bool {
@@ -494,8 +485,8 @@ func (c *Client) NewListPropertiesOfCertificatesPager(options *ListCertificatesO
494485
})
495486
}
496487

497-
// ListCertificateVersionsOptions contains optional parameters for Client.ListCertificateVersions
498-
type ListCertificateVersionsOptions struct {
488+
// ListPropertiesOfCertificateVersionsOptions contains optional parameters for Client.ListCertificateVersions
489+
type ListPropertiesOfCertificateVersionsOptions struct {
499490
// placeholder for future optional parameters.
500491
}
501492

@@ -513,7 +504,7 @@ func listCertificateVersionsPageFromGenerated(i generated.KeyVaultClientGetCerti
513504
var vals []*CertificateItem
514505
for _, v := range i.Value {
515506
vals = append(vals, &CertificateItem{
516-
Properties: propertiesFromGenerated(v.Attributes, convertGeneratedMap(v.Tags), v.ID, v.X509Thumbprint),
507+
Properties: propertiesFromGenerated(v.Attributes, v.Tags, v.ID, v.X509Thumbprint),
517508
ID: v.ID,
518509
})
519510
}
@@ -527,7 +518,7 @@ func listCertificateVersionsPageFromGenerated(i generated.KeyVaultClientGetCerti
527518
// NewListPropertiesOfCertificateVersionsPager lists all versions of the specified certificate. The full certificate identifer and
528519
// attributes are provided in the response. No values are returned for the certificates. This operation
529520
// requires the certificates/list permission.
530-
func (c *Client) NewListPropertiesOfCertificateVersionsPager(certificateName string, options *ListCertificateVersionsOptions) *runtime.Pager[ListPropertiesOfCertificateVersionsResponse] {
521+
func (c *Client) NewListPropertiesOfCertificateVersionsPager(certificateName string, options *ListPropertiesOfCertificateVersionsOptions) *runtime.Pager[ListPropertiesOfCertificateVersionsResponse] {
531522
pager := c.genClient.NewGetCertificateVersionsPager(c.vaultURL, certificateName, nil)
532523
return runtime.NewPager(runtime.PagingHandler[ListPropertiesOfCertificateVersionsResponse]{
533524
More: func(page ListPropertiesOfCertificateVersionsResponse) bool {
@@ -706,8 +697,8 @@ type ListPropertiesOfIssuersOptions struct {
706697
// placeholder for future optional parameters
707698
}
708699

709-
// ListIssuersPropertiesOfIssuersResponse contains response fields for ListPropertiesOfIssuersPager.NextPage
710-
type ListIssuersPropertiesOfIssuersResponse struct {
700+
// ListPropertiesOfIssuersResponse contains response fields for ListPropertiesOfIssuersPager.NextPage
701+
type ListPropertiesOfIssuersResponse struct {
711702
// READ-ONLY; A response message containing a list of certificates in the key vault along with a link to the next page of certificates.
712703
Issuers []*IssuerItem `json:"value,omitempty" azure:"ro"`
713704

@@ -716,28 +707,28 @@ type ListIssuersPropertiesOfIssuersResponse struct {
716707
}
717708

718709
// convert internal Response to ListPropertiesOfIssuersPage
719-
func listIssuersPageFromGenerated(i generated.KeyVaultClientGetCertificateIssuersResponse) ListIssuersPropertiesOfIssuersResponse {
710+
func listIssuersPageFromGenerated(i generated.KeyVaultClientGetCertificateIssuersResponse) ListPropertiesOfIssuersResponse {
720711
var vals []*IssuerItem
721712

722713
for _, v := range i.Value {
723714
vals = append(vals, certificateIssuerItemFromGenerated(v))
724715
}
725716

726-
return ListIssuersPropertiesOfIssuersResponse{Issuers: vals, NextLink: i.NextLink}
717+
return ListPropertiesOfIssuersResponse{Issuers: vals, NextLink: i.NextLink}
727718
}
728719

729720
// NewListPropertiesOfIssuersPager returns a pager that can be used to get the set of certificate issuer resources in the specified key vault. This operation
730721
// requires the certificates/manageissuers/getissuers permission.
731-
func (c *Client) NewListPropertiesOfIssuersPager(options *ListPropertiesOfIssuersOptions) *runtime.Pager[ListIssuersPropertiesOfIssuersResponse] {
722+
func (c *Client) NewListPropertiesOfIssuersPager(options *ListPropertiesOfIssuersOptions) *runtime.Pager[ListPropertiesOfIssuersResponse] {
732723
pager := c.genClient.NewGetCertificateIssuersPager(c.vaultURL, nil)
733-
return runtime.NewPager(runtime.PagingHandler[ListIssuersPropertiesOfIssuersResponse]{
734-
More: func(page ListIssuersPropertiesOfIssuersResponse) bool {
724+
return runtime.NewPager(runtime.PagingHandler[ListPropertiesOfIssuersResponse]{
725+
More: func(page ListPropertiesOfIssuersResponse) bool {
735726
return pager.More()
736727
},
737-
Fetcher: func(ctx context.Context, cur *ListIssuersPropertiesOfIssuersResponse) (ListIssuersPropertiesOfIssuersResponse, error) {
728+
Fetcher: func(ctx context.Context, cur *ListPropertiesOfIssuersResponse) (ListPropertiesOfIssuersResponse, error) {
738729
page, err := pager.NextPage(ctx)
739730
if err != nil {
740-
return ListIssuersPropertiesOfIssuersResponse{}, err
731+
return ListPropertiesOfIssuersResponse{}, err
741732
}
742733
return listIssuersPageFromGenerated(page), nil
743734
},
@@ -1056,14 +1047,8 @@ func (c *Client) GetCertificatePolicy(ctx context.Context, certificateName strin
10561047

10571048
// UpdateCertificatePropertiesOptions contains optional parameters for Client.UpdateCertificateProperties
10581049
type UpdateCertificatePropertiesOptions struct {
1059-
// The version of the certificate to update
1060-
Version string
1061-
1062-
// The attributes of the certificate (optional).
1063-
Properties *Properties `json:"attributes,omitempty"`
1050+
// placeholder for future optional parameters
10641051

1065-
// The management policy for the certificate.
1066-
CertificatePolicy *Policy `json:"policy,omitempty"`
10671052
}
10681053

10691054
func (u *UpdateCertificatePropertiesOptions) toGenerated() *generated.KeyVaultClientUpdateCertificateOptions {
@@ -1081,18 +1066,18 @@ func (c *Client) UpdateCertificateProperties(ctx context.Context, certificateNam
10811066
if options == nil {
10821067
options = &UpdateCertificatePropertiesOptions{}
10831068
}
1084-
var tags map[string]*string
1085-
if properties.Tags != nil {
1086-
tags = convertToGeneratedMap(properties.Tags)
1069+
version := ""
1070+
if properties.Version != nil {
1071+
version = *properties.Version
10871072
}
10881073
resp, err := c.genClient.UpdateCertificate(
10891074
ctx,
10901075
c.vaultURL,
10911076
certificateName,
1092-
options.Version,
1077+
version,
10931078
generated.CertificateUpdateParameters{
10941079
CertificateAttributes: properties.toGenerated(),
1095-
Tags: tags,
1080+
Tags: properties.Tags,
10961081
},
10971082
options.toGenerated(),
10981083
)
@@ -1126,7 +1111,7 @@ func (c *Client) MergeCertificate(ctx context.Context, certificateName string, c
11261111
}
11271112
var tags map[string]*string
11281113
if options.Properties != nil && options.Properties.Tags != nil {
1129-
tags = convertToGeneratedMap(options.Properties.Tags)
1114+
tags = options.Properties.Tags
11301115
}
11311116
resp, err := c.genClient.MergeCertificate(
11321117
ctx, c.vaultURL,
@@ -1144,7 +1129,7 @@ func (c *Client) MergeCertificate(ctx context.Context, certificateName string, c
11441129

11451130
return MergeCertificateResponse{
11461131
CertificateWithPolicy: CertificateWithPolicy{
1147-
Properties: propertiesFromGenerated(resp.Attributes, convertGeneratedMap(resp.Tags), resp.ID, resp.X509Thumbprint),
1132+
Properties: propertiesFromGenerated(resp.Attributes, resp.Tags, resp.ID, resp.X509Thumbprint),
11481133
CER: resp.Cer,
11491134
ContentType: resp.ContentType,
11501135
ID: resp.ID,
@@ -1185,7 +1170,7 @@ func (c *Client) RestoreCertificateBackup(ctx context.Context, certificateBackup
11851170

11861171
return RestoreCertificateBackupResponse{
11871172
CertificateWithPolicy: CertificateWithPolicy{
1188-
Properties: propertiesFromGenerated(resp.Attributes, convertGeneratedMap(resp.Tags), resp.ID, resp.X509Thumbprint),
1173+
Properties: propertiesFromGenerated(resp.Attributes, resp.Tags, resp.ID, resp.X509Thumbprint),
11891174
CER: resp.Cer,
11901175
ContentType: resp.ContentType,
11911176
ID: resp.ID,
@@ -1255,7 +1240,7 @@ func (c *Client) BeginRecoverDeletedCertificate(ctx context.Context, certificate
12551240
// ListDeletedCertificatesResponse contains response field for ListDeletedCertificatesPager.NextPage
12561241
type ListDeletedCertificatesResponse struct {
12571242
// READ-ONLY; A response message containing a list of deleted certificates in the vault along with a link to the next page of deleted certificates
1258-
Certificates []*DeletedCertificateItem `json:"value,omitempty" azure:"ro"`
1243+
DeletedCertificates []*DeletedCertificateItem `json:"value,omitempty" azure:"ro"`
12591244

12601245
// NextLink gives the next page of items to fetch
12611246
NextLink *string
@@ -1270,7 +1255,7 @@ func listDeletedCertsPageFromGenerated(g generated.KeyVaultClientGetDeletedCerti
12701255
for i, c := range g.Value {
12711256
_, name, _ := shared.ParseID(c.ID)
12721257
certs[i] = &DeletedCertificateItem{
1273-
Properties: propertiesFromGenerated(c.Attributes, convertGeneratedMap(c.Tags), c.ID, c.X509Thumbprint),
1258+
Properties: propertiesFromGenerated(c.Attributes, c.Tags, c.ID, c.X509Thumbprint),
12741259
ID: c.ID,
12751260
Name: name,
12761261
RecoveryID: c.RecoveryID,
@@ -1281,8 +1266,8 @@ func listDeletedCertsPageFromGenerated(g generated.KeyVaultClientGetDeletedCerti
12811266
}
12821267

12831268
return ListDeletedCertificatesResponse{
1284-
Certificates: certs,
1285-
NextLink: g.NextLink,
1269+
DeletedCertificates: certs,
1270+
NextLink: g.NextLink,
12861271
}
12871272
}
12881273

sdk/keyvault/azcertificates/client_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,6 @@ func TestCRUDOperations(t *testing.T) {
586586
// Make sure certificates are the same
587587
require.Equal(t, *finalResp.ID, *received.ID)
588588

589-
// // Make sure we can interface with x509 library
590-
// mid := base64.StdEncoding.EncodeToString(received.Cer)
591-
// cer := fmt.Sprintf("-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----", mid)
592-
// block, _ := pem.Decode([]byte(cer))
593-
// require.NotNil(t, block)
594-
// parsedCert, err := x509.ParseCertificate(block.Bytes)
595-
// require.NoError(t, err)
596-
// require.NotNil(t, parsedCert)
597-
598589
// Update the policy
599590
policy.KeyType = to.Ptr(KeyTypeEC)
600591
policy.KeySize = to.Ptr(int32(256))
@@ -611,13 +602,18 @@ func TestCRUDOperations(t *testing.T) {
611602
require.Equal(t, *policy.KeyCurveName, *updateResp.KeyCurveName)
612603

613604
if received.Properties.Tags == nil {
614-
received.Properties.Tags = map[string]string{}
605+
received.Properties.Tags = map[string]*string{}
615606
}
616-
received.Properties.Tags["tag1"] = "updated_values1"
607+
received.Properties.Tags["tag1"] = to.Ptr("updated_values1")
617608
updatePropsResp, err := client.UpdateCertificateProperties(ctx, certName, *received.Properties, nil)
618609
require.NoError(t, err)
619-
require.Equal(t, "updated_values1", updatePropsResp.Properties.Tags["tag1"])
610+
require.Equal(t, "updated_values1", *updatePropsResp.Properties.Tags["tag1"])
620611
require.Equal(t, *received.ID, *updatePropsResp.ID)
612+
require.True(t, *updatePropsResp.Properties.Enabled)
613+
614+
resp, err := client.UpdateCertificateProperties(ctx, *updatePropsResp.Name, Properties{Enabled: to.Ptr(false)}, nil)
615+
require.NoError(t, err)
616+
require.False(t, *resp.Properties.Enabled)
621617
}
622618

623619
// https://stackoverflow.com/questions/42643048/signing-certificate-request-with-certificate-authority
@@ -889,7 +885,7 @@ func TestClient_ListDeletedCertificates(t *testing.T) {
889885
for pager.More() {
890886
page, err := pager.NextPage(ctx)
891887
require.NoError(t, err)
892-
for _, cert := range page.Certificates {
888+
for _, cert := range page.DeletedCertificates {
893889
purgeCert(t, client, *cert.Name)
894890
deletedCount += 1
895891
}

sdk/keyvault/azcertificates/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func ExampleClient_UpdateCertificateProperties() {
123123
panic(err)
124124
}
125125
getResp.Properties.Enabled = to.Ptr(false)
126-
getResp.Properties.Tags["Tag1"] = "Val1"
126+
getResp.Properties.Tags["Tag1"] = to.Ptr("Val1")
127127

128128
resp, err := client.UpdateCertificateProperties(context.TODO(), "myCertName", *getResp.Properties, nil)
129129
if err != nil {

0 commit comments

Comments
 (0)