Skip to content

Commit 3264ce3

Browse files
authored
Revise azkeys API (Azure#18170)
1 parent 6f392c8 commit 3264ce3

File tree

5 files changed

+55
-85
lines changed

5 files changed

+55
-85
lines changed

sdk/keyvault/azkeys/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
* Methods `BeginDeleteKey` and `BeginRecoverDeletedKey` now return a `*runtime.Poller[T]` with their respective response types.
1414
* Option types with a `ResumeToken` field now take the token by value.
1515
* Renamed `CreateECKeyOptions.CurveName` to `.Curve`
16+
* Renamed `ReleaseKeyOptions.Enc` to `.Algorithm`
17+
* Removed redundant fields `DeletedKeyItem.Managed`. and `.Tags`, and `ImportKeyOptions.Tags`.
18+
Use the `DeletedKeyItem.Properties` and `ImportKeyOptions.Properties` fields of the same name instead.
19+
* Changed type of key `Tags` to `map[string]*string`
20+
* Changed type of `ListPropertiesOfKeyVersionsResponse.Keys` to `[]*KeyItem`
21+
* Changed type of `JSONWebKey.KeyOps` to `[]*Operation`
1622

1723
### Bugs Fixed
1824

sdk/keyvault/azkeys/client.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type CreateKeyOptions struct {
9090
PublicExponent *int32 `json:"public_exponent,omitempty"`
9191

9292
// Tags is application specific metadata in the form of key-value pairs.
93-
Tags map[string]string `json:"tags,omitempty"`
93+
Tags map[string]*string `json:"tags,omitempty"`
9494
}
9595

9696
// convert CreateKeyOptions to *generated.KeyVaultClientCreateKeyOptions
@@ -120,7 +120,7 @@ func (c *CreateKeyOptions) toKeyCreateParameters(keyType KeyType) generated.KeyC
120120
KeyOps: ops,
121121
KeySize: c.Size,
122122
PublicExponent: c.PublicExponent,
123-
Tags: convertToGeneratedMap(c.Tags),
123+
Tags: c.Tags,
124124
ReleasePolicy: c.ReleasePolicy.toGenerated(),
125125
}
126126
}
@@ -165,7 +165,7 @@ type CreateECKeyOptions struct {
165165
Curve *CurveName `json:"crv,omitempty"`
166166

167167
// Tags is application specific metadata in the form of key-value pairs.
168-
Tags map[string]string `json:"tags,omitempty"`
168+
Tags map[string]*string `json:"tags,omitempty"`
169169

170170
// HardwareProtected determines whether the key is is created in a hardware security module (HSM).
171171
HardwareProtected *bool
@@ -192,7 +192,7 @@ func (c *CreateECKeyOptions) toKeyCreateParameters(keyType KeyType) generated.Ke
192192
return generated.KeyCreateParameters{
193193
Kty: keyType.toGenerated(),
194194
Curve: (*generated.JSONWebKeyCurveName)(c.Curve),
195-
Tags: convertToGeneratedMap(c.Tags),
195+
Tags: c.Tags,
196196
KeyOps: keyOps,
197197
ReleasePolicy: c.ReleasePolicy.toGenerated(),
198198
KeyAttributes: c.Properties.toGenerated(),
@@ -255,7 +255,7 @@ type CreateOctKeyOptions struct {
255255
ReleasePolicy *ReleasePolicy `json:"release_policy,omitempty"`
256256

257257
// Tags is application specific metadata in the form of key-value pairs.
258-
Tags map[string]string `json:"tags,omitempty"`
258+
Tags map[string]*string `json:"tags,omitempty"`
259259
}
260260

261261
// conver the CreateOctKeyOptions to generated.KeyCreateParameters
@@ -270,7 +270,7 @@ func (c *CreateOctKeyOptions) toKeyCreateParameters(keyType KeyType) generated.K
270270
return generated.KeyCreateParameters{
271271
Kty: keyType.toGenerated(),
272272
KeySize: c.Size,
273-
Tags: convertToGeneratedMap(c.Tags),
273+
Tags: c.Tags,
274274
ReleasePolicy: c.ReleasePolicy.toGenerated(),
275275
KeyAttributes: c.Properties.toGenerated(),
276276
KeyOps: keyOps,
@@ -325,7 +325,7 @@ type CreateRSAKeyOptions struct {
325325
PublicExponent *int32 `json:"public_exponent,omitempty"`
326326

327327
// Tags is application specific metadata in the form of key-value pairs.
328-
Tags map[string]string `json:"tags,omitempty"`
328+
Tags map[string]*string `json:"tags,omitempty"`
329329

330330
// Properties is the key's management properties.
331331
Properties *Properties `json:"attributes,omitempty"`
@@ -350,7 +350,7 @@ func (c CreateRSAKeyOptions) toKeyCreateParameters(k KeyType) generated.KeyCreat
350350
Kty: k.toGenerated(),
351351
KeySize: c.Size,
352352
PublicExponent: c.PublicExponent,
353-
Tags: convertToGeneratedMap(c.Tags),
353+
Tags: c.Tags,
354354
KeyAttributes: c.Properties.toGenerated(),
355355
KeyOps: keyOps,
356356
ReleasePolicy: c.ReleasePolicy.toGenerated(),
@@ -850,15 +850,15 @@ type ListPropertiesOfKeyVersionsResponse struct {
850850
NextLink *string `json:"nextLink,omitempty" azure:"ro"`
851851

852852
// Keys is the page's content.
853-
Keys []KeyItem `json:"value,omitempty" azure:"ro"`
853+
Keys []*KeyItem `json:"value,omitempty" azure:"ro"`
854854
}
855855

856856
// create ListKeysPage from generated pager
857857
func listKeyVersionsPageFromGenerated(i generated.KeyVaultClientGetKeyVersionsResponse) ListPropertiesOfKeyVersionsResponse {
858-
var keys []KeyItem
858+
var keys []*KeyItem
859859
for _, s := range i.Value {
860860
if s != nil {
861-
keys = append(keys, *keyItemFromGenerated(s))
861+
keys = append(keys, keyItemFromGenerated(s))
862862
}
863863
}
864864
return ListPropertiesOfKeyVersionsResponse{
@@ -949,9 +949,6 @@ type ImportKeyOptions struct {
949949

950950
// Properties is the properties of the key.
951951
Properties *Properties `json:"attributes,omitempty"`
952-
953-
// Tags is application specific metadata in the form of key-value pairs.
954-
Tags map[string]string `json:"tags,omitempty"`
955952
}
956953

957954
func (i ImportKeyOptions) toImportKeyParameters(key JSONWebKey) generated.KeyImportParameters {
@@ -963,7 +960,6 @@ func (i ImportKeyOptions) toImportKeyParameters(key JSONWebKey) generated.KeyImp
963960
Key: key.toGenerated(),
964961
Hsm: i.HardwareProtected,
965962
KeyAttributes: attribs,
966-
Tags: convertToGeneratedMap(i.Tags),
967963
}
968964
}
969965

@@ -1138,8 +1134,8 @@ type ReleaseKeyOptions struct {
11381134
// Version is the version of the key to release
11391135
Version string
11401136

1141-
// Enc is the encryption algorithm used to protected exported key material.
1142-
Enc *ExportEncryptionAlg `json:"enc,omitempty"`
1137+
// Algorithm is the encryption algorithm used to protected exported key material.
1138+
Algorithm *ExportEncryptionAlg `json:"algorithm,omitempty"`
11431139

11441140
// Nonce is client-provided nonce for freshness.
11451141
Nonce *string `json:"nonce,omitempty"`
@@ -1164,7 +1160,7 @@ func (c *Client) ReleaseKey(ctx context.Context, name string, targetAttestationT
11641160
options.Version,
11651161
generated.KeyReleaseParameters{
11661162
TargetAttestationToken: &targetAttestationToken,
1167-
Enc: (*generated.KeyEncryptionAlgorithm)(options.Enc),
1163+
Enc: (*generated.KeyEncryptionAlgorithm)(options.Algorithm),
11681164
Nonce: options.Nonce,
11691165
},
11701166
&generated.KeyVaultClientReleaseOptions{},

sdk/keyvault/azkeys/client_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ func TestCreateKeyRSATags(t *testing.T) {
7676
require.NoError(t, err)
7777

7878
resp, err := client.CreateRSAKey(ctx, key, &CreateRSAKeyOptions{
79-
Tags: map[string]string{
80-
"Tag1": "Val1",
79+
Tags: map[string]*string{
80+
"Tag1": to.Ptr("Val1"),
8181
},
8282
})
8383
defer cleanUpKey(t, client, key)
8484
require.NoError(t, err)
8585
validateKey(t, to.Ptr(resp.Key))
8686
require.Equal(t, 1, len(resp.Key.Properties.Tags))
8787

88-
resp.Key.Properties.Tags = map[string]string{}
88+
resp.Key.Properties.Tags = map[string]*string{}
8989
// Remove the tag
9090
resp2, err := client.UpdateKeyProperties(ctx, resp.Key, nil)
9191
require.NoError(t, err)
@@ -442,15 +442,15 @@ func TestUpdateKeyProperties(t *testing.T) {
442442
require.NoError(t, err)
443443
defer cleanUpKey(t, client, key)
444444

445-
createResp.Key.Properties.Tags = map[string]string{
446-
"Tag1": "Val1",
445+
createResp.Key.Properties.Tags = map[string]*string{
446+
"Tag1": to.Ptr("Val1"),
447447
}
448448
createResp.Key.Properties.ExpiresOn = to.Ptr(time.Now().AddDate(1, 0, 0))
449449

450450
resp, err := client.UpdateKeyProperties(ctx, createResp.Key, nil)
451451
require.NoError(t, err)
452452
require.NotNil(t, resp.Properties)
453-
require.Equal(t, resp.Properties.Tags["Tag1"], "Val1")
453+
require.Equal(t, *resp.Properties.Tags["Tag1"], "Val1")
454454
require.NotNil(t, resp.Properties.ExpiresOn)
455455

456456
createResp.Key.Properties.Name = to.Ptr("doesnotexist")
@@ -645,7 +645,7 @@ func TestImportKey(t *testing.T) {
645645

646646
jwk := JSONWebKey{
647647
KeyType: to.Ptr(KeyTypeRSA),
648-
KeyOps: to.SliceOfPtrs("encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey"),
648+
KeyOps: to.SliceOfPtrs(OperationEncrypt, OperationDecrypt, OperationSign, OperationVerify, OperationWrapKey, OperationUnwrapKey),
649649
N: toBytes("00a0914d00234ac683b21b4c15d5bed887bdc959c2e57af54ae734e8f00720d775d275e455207e3784ceeb60a50a4655dd72a7a94d271e8ee8f7959a669ca6e775bf0e23badae991b4529d978528b4bd90521d32dd2656796ba82b6bbfc7668c8f5eeb5053747fd199319d29a8440d08f4412d527ff9311eda71825920b47b1c46b11ab3e91d7316407e89c7f340f7b85a34042ce51743b27d4718403d34c7b438af6181be05e4d11eb985d38253d7fe9bf53fc2f1b002d22d2d793fa79a504b6ab42d0492804d7071d727a06cf3a8893aa542b1503f832b296371b6707d4dc6e372f8fe67d8ded1c908fde45ce03bc086a71487fa75e43aa0e0679aa0d20efe35", t),
650650
E: toBytes("10001", t),
651651
D: toBytes("627c7d24668148fe2252c7fa649ea8a5a9ed44d75c766cda42b29b660e99404f0e862d4561a6c95af6a83d213e0a2244b03cd28576473215073785fb067f015da19084ade9f475e08b040a9a2c7ba00253bb8125508c9df140b75161d266be347a5e0f6900fe1d8bbf78ccc25eeb37e0c9d188d6e1fc15169ba4fe12276193d77790d2326928bd60d0d01d6ead8d6ac4861abadceec95358fd6689c50a1671a4a936d2376440a41445501da4e74bfb98f823bd19c45b94eb01d98fc0d2f284507f018ebd929b8180dbe6381fdd434bffb7800aaabdd973d55f9eaf9bb88a6ea7b28c2a80231e72de1ad244826d665582c2362761019de2e9f10cb8bcc2625649", t),

sdk/keyvault/azkeys/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ func ExampleClient_UpdateKeyProperties() {
108108
panic(err)
109109
}
110110

111-
resp.Key.Properties.Tags = map[string]string{"Tag1": "val1"}
111+
resp.Key.Properties.Tags = map[string]*string{"Tag1": to.Ptr("val1")}
112112
resp.Key.Properties.Enabled = to.Ptr(true)
113113

114114
updateResp, err := client.UpdateKeyProperties(context.TODO(), resp.Key, nil)
115115
if err != nil {
116116
panic(err)
117117
}
118-
fmt.Printf("Enabled: %v\tTag1: %s\n", *updateResp.Key.Properties.Enabled, updateResp.Key.Properties.Tags["Tag1"])
118+
fmt.Printf("Enabled: %v\tTag1: %s\n", *updateResp.Key.Properties.Enabled, *updateResp.Key.Properties.Tags["Tag1"])
119119
}
120120

121121
func ExampleClient_BeginDeleteKey() {

sdk/keyvault/azkeys/models.go

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Properties struct {
4949
RecoveryLevel *string `json:"recoveryLevel,omitempty" azure:"ro"`
5050

5151
// Tags contain application specific metadata in the form of key-value pairs.
52-
Tags map[string]string `json:"tags,omitempty"`
52+
Tags map[string]*string `json:"tags,omitempty"`
5353

5454
// READ-ONLY; Last updated time in UTC.
5555
UpdatedOn *time.Time `json:"updated,omitempty" azure:"ro"`
@@ -86,19 +86,19 @@ func keyPropertiesFromGenerated(i *generated.KeyAttributes, id *string, name *st
8686

8787
return &Properties{
8888
CreatedOn: i.Created,
89-
RecoverableDays: i.RecoverableDays,
90-
RecoveryLevel: to.Ptr(string(*i.RecoveryLevel)),
9189
Enabled: i.Enabled,
9290
ExpiresOn: i.Expires,
93-
NotBefore: i.NotBefore,
94-
UpdatedOn: i.Updated,
9591
Exportable: i.Exportable,
9692
ID: id,
97-
Name: name,
98-
Version: version,
9993
Managed: managed,
100-
Tags: convertGeneratedMap(tags),
94+
Name: name,
95+
NotBefore: i.NotBefore,
96+
RecoverableDays: i.RecoverableDays,
97+
RecoveryLevel: to.Ptr(string(*i.RecoveryLevel)),
98+
Tags: tags,
99+
UpdatedOn: i.Updated,
101100
VaultURL: vaultURL,
101+
Version: version,
102102
}
103103
}
104104

@@ -129,7 +129,7 @@ func (k Key) toKeyUpdateParameters() generated.KeyUpdateParameters {
129129

130130
var tags map[string]*string
131131
if k.Properties != nil && k.Properties.Tags != nil {
132-
tags = convertToGeneratedMap(k.Properties.Tags)
132+
tags = k.Properties.Tags
133133
}
134134

135135
return generated.KeyUpdateParameters{
@@ -157,8 +157,8 @@ type JSONWebKey struct {
157157
E []byte `json:"e,omitempty"`
158158

159159
// Symmetric key.
160-
K []byte `json:"k,omitempty"`
161-
KeyOps []*string `json:"key_ops,omitempty"`
160+
K []byte `json:"k,omitempty"`
161+
KeyOps []*Operation `json:"key_ops,omitempty"`
162162

163163
// ID identifies the key
164164
ID *string `json:"kid,omitempty"`
@@ -194,14 +194,19 @@ func jsonWebKeyFromGenerated(i *generated.JSONWebKey) *JSONWebKey {
194194
return &JSONWebKey{}
195195
}
196196

197+
ops := make([]*Operation, len(i.KeyOps))
198+
for j, op := range i.KeyOps {
199+
ops[j] = (*Operation)(op)
200+
}
201+
197202
return &JSONWebKey{
198203
Crv: (*CurveName)(i.Crv),
199204
D: i.D,
200205
DP: i.DP,
201206
DQ: i.DQ,
202207
E: i.E,
203208
K: i.K,
204-
KeyOps: i.KeyOps,
209+
KeyOps: ops,
205210
ID: i.Kid,
206211
KeyType: (*KeyType)(i.Kty),
207212
N: i.N,
@@ -216,14 +221,18 @@ func jsonWebKeyFromGenerated(i *generated.JSONWebKey) *JSONWebKey {
216221

217222
// converts JSONWebKey to *generated.JSONWebKey
218223
func (j JSONWebKey) toGenerated() *generated.JSONWebKey {
224+
ops := make([]*string, len(j.KeyOps))
225+
for i, op := range j.KeyOps {
226+
ops[i] = (*string)(op)
227+
}
219228
return &generated.JSONWebKey{
220229
Crv: (*generated.JSONWebKeyCurveName)(j.Crv),
221230
D: j.D,
222231
DP: j.DP,
223232
DQ: j.DQ,
224233
E: j.E,
225234
K: j.K,
226-
KeyOps: j.KeyOps,
235+
KeyOps: ops,
227236
Kid: j.ID,
228237
Kty: (*generated.JSONWebKeyType)(j.KeyType),
229238
N: j.N,
@@ -297,16 +306,9 @@ type DeletedKeyItem struct {
297306
// The url of the recovery object, used to identify and recover the deleted key.
298307
RecoveryID *string `json:"recoveryId,omitempty"`
299308

300-
// Tags contain application specific metadata in the form of key-value pairs.
301-
Tags map[string]string `json:"tags,omitempty"`
302-
303309
// READ-ONLY; The time when the key was deleted, in UTC
304310
DeletedOn *time.Time `json:"deletedDate,omitempty" azure:"ro"`
305311

306-
// READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will
307-
// be true.
308-
Managed *bool `json:"managed,omitempty" azure:"ro"`
309-
310312
// READ-ONLY; The time when the key is scheduled to be purged, in UTC
311313
ScheduledPurgeDate *time.Time `json:"scheduledPurgeDate,omitempty" azure:"ro"`
312314
}
@@ -317,24 +319,14 @@ func deletedKeyItemFromGenerated(i *generated.DeletedKeyItem) *DeletedKeyItem {
317319
return nil
318320
}
319321

320-
_, name, _ := shared.ParseID(i.Kid)
322+
vaultURL, name, version := shared.ParseID(i.Kid)
321323
return &DeletedKeyItem{
322324
RecoveryID: i.RecoveryID,
323325
DeletedOn: i.DeletedDate,
324326
ScheduledPurgeDate: i.ScheduledPurgeDate,
325-
Properties: &Properties{
326-
Enabled: i.Attributes.Enabled,
327-
ExpiresOn: i.Attributes.Expires,
328-
NotBefore: i.Attributes.NotBefore,
329-
CreatedOn: i.Attributes.Created,
330-
UpdatedOn: i.Attributes.Updated,
331-
RecoverableDays: i.Attributes.RecoverableDays,
332-
RecoveryLevel: (*string)(i.Attributes.RecoveryLevel),
333-
},
334-
ID: i.Kid,
335-
Name: name,
336-
Tags: convertGeneratedMap(i.Tags),
337-
Managed: i.Managed,
327+
Properties: keyPropertiesFromGenerated(i.Attributes, i.Kid, name, version, i.Managed, vaultURL, i.Tags),
328+
ID: i.Kid,
329+
Name: name,
338330
}
339331
}
340332

@@ -483,27 +475,3 @@ type LifetimeActionsTrigger struct {
483475
// Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D"
484476
TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"`
485477
}
486-
487-
func convertToGeneratedMap(m map[string]string) map[string]*string {
488-
if m == nil {
489-
return nil
490-
}
491-
492-
ret := make(map[string]*string)
493-
for k, v := range m {
494-
ret[k] = &v
495-
}
496-
return ret
497-
}
498-
499-
func convertGeneratedMap(m map[string]*string) map[string]string {
500-
if m == nil {
501-
return nil
502-
}
503-
504-
ret := make(map[string]string)
505-
for k, v := range m {
506-
ret[k] = *v
507-
}
508-
return ret
509-
}

0 commit comments

Comments
 (0)