From 9401b7bbb8e8dfa7bdbb8005115039da06f7244c Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Tue, 23 May 2023 11:46:53 -0700 Subject: [PATCH 01/10] renames --- sdk/security/keyvault/azkeys/CHANGELOG.md | 27 +- sdk/security/keyvault/azkeys/autorest.md | 157 ++++++-- sdk/security/keyvault/azkeys/client.go | 172 ++++---- sdk/security/keyvault/azkeys/client_test.go | 110 ++--- sdk/security/keyvault/azkeys/constants.go | 343 +++++++--------- sdk/security/keyvault/azkeys/example_test.go | 18 +- sdk/security/keyvault/azkeys/models.go | 208 +++++----- sdk/security/keyvault/azkeys/models_serde.go | 380 +++++++++--------- .../keyvault/azkeys/response_types.go | 36 +- 9 files changed, 765 insertions(+), 686 deletions(-) diff --git a/sdk/security/keyvault/azkeys/CHANGELOG.md b/sdk/security/keyvault/azkeys/CHANGELOG.md index 1bf58ce5eb8d..be9c3dcee1f8 100644 --- a/sdk/security/keyvault/azkeys/CHANGELOG.md +++ b/sdk/security/keyvault/azkeys/CHANGELOG.md @@ -1,6 +1,31 @@ # Release History -## 1.0.0 (2023-05-11) +## 1.0.0 (unreleased) + +### Breaking Changes +* Renamed `GetRandomBytesRequest` to `GetRandomBytesParameters` +* `ListDeletedKey` to `ListDeletedKeyProperties` +* `ListKeys` to `ListKeyProperties` +* `DeletedKeyBundle` to `DeletedKey` +* `KeyBundle` to `KeyVaultKey` +* `RestoreKeyParameters.KeyBundleBackup` to `RestoreKeyParameters.KeyBackup` +* `DeletedKeyItem` to `DeletedKeyProperties` +* `KeyItem` to `KeyProperties` +* `DeletedKeyListResult` to `DeletedKeyPropertiesListResult` +* `KeyListResult` `KeyPropertiesListResult` +* `KeyOperationsParameters` to `KeyOperationParameters` +* `KeyOps` field to `KeyOperations` +* Changed `JSONWebKey.KeyOperations` from type []*string to []*KeyOperation +* `KeyEncryptionAlgorithm` to `KeyExportEncryptionAlgorithm` +* `ReleaseParameters.Enc` to `ReleaseParameters.Algorithm` +* `KeyOperationParameters.AAD` to `KeyOperationParameters.AdditionalAuthenticationData` +* `KeyOperationParameters.Tag` to `KeyOperationParameters.AuthenticationTag` +* `JSONWebKeyOperation` to `KeyOperation` +* `JSONWebKeyCurveName` to `KeyCurveName` +* `JSONWebKeyEncryptionAlgorithm` to `EncryptionAlgorithm` +* `JSONWebKeySignatureAlgorithm` to `SignatureAlgorithm` +* `JSONWebKeyType` to `KeyType` +* Removed `DeletionRecoveryLevel` type ### Other Changes * Updated dependencies diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index 01fd8d810748..a5bbc1938202 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -25,30 +25,6 @@ directive: where: $["x-ms-parameterized-host"] transform: $.parameters[0]["x-ms-parameter-location"] = "client" - # capitalize acronyms - - from: swagger-document - where: $.definitions.KeyImportParameters.properties.Hsm - transform: $["x-ms-client-name"] = "HSM" - - from: swagger-document - where: $.definitions..properties..iv - transform: $["x-ms-client-name"] = "IV" - - from: swagger-document - where: $.definitions..properties..kid - transform: $["x-ms-client-name"] = "KID" - - # Maxresults -> MaxResults - - from: swagger-document - where: $.paths..parameters..[?(@.name=='maxresults')] - transform: $["x-ms-client-name"] = "MaxResults" - - # keyName, keyVersion -> name, version - - from: swagger-document - where: $.paths..parameters..[?(@.name=='key-name')] - transform: $["x-ms-client-name"] = "name" - - from: swagger-document - where: $.paths..parameters..[?(@.name=='key-version')] - transform: $["x-ms-client-name"] = "version" - # rename parameter models to match their methods - rename-model: from: KeyCreateParameters @@ -74,17 +50,144 @@ directive: - rename-model: from: KeyVerifyParameters to: VerifyParameters + - rename-model: + from: GetRandomBytesRequest + to: GetRandomBytesParameters # rename paged operations from Get* to List* - rename-operation: from: GetDeletedKeys - to: ListDeletedKeys + to: ListDeletedKeyProperties - rename-operation: from: GetKeys - to: ListKeys + to: ListKeyProperties - rename-operation: from: GetKeyVersions - to: ListKeyVersions + to: ListKeyPropertiesVersions + + # add in KeyRotation prefix + - rename-model: + from: LifetimeActions + to: KeyRotationLifetimeActions + - rename-model: + from: LifetimeActionsTrigger + to: KeyRotationLifetimeActionsTrigger + - rename-model: + from: LifetimeActionsType + to: KeyRotationLifetimeActionsType + + # rename KeyItem and KeyBundle + - rename-model: + from: DeletedKeyBundle + to: DeletedKey + - rename-model: + from: KeyBundle + to: KeyVaultKey + - rename-model: + from: KeyItem + to: KeyProperties + - rename-model: + from: DeletedKeyItem + to: DeletedKeyProperties + - rename-model: + from: DeletedKeyListResult + to: DeletedKeyPropertiesListResult + - rename-model: + from: KeyListResult + to: KeyPropertiesListResult + - from: swagger-document + where: $.definitions.RestoreKeyParameters.properties.value + transform: $["x-ms-client-name"] = "KeyBackup" + + # Rename KeyOps to KeyOperations and update type + - rename-model: + from: KeyOperationsParameters + to: KeyOperationParameters + - from: swagger-document + where: $.definitions..properties.key_ops + transform: $["x-ms-client-name"] = "KeyOperations" + - from: models.go + where: $ + transform: return $.replace(/KeyOperations \[\]\*string/, "KeyOperations []*KeyOperation"); + + # fix capitalization + - from: swagger-document + where: $.definitions.ImportKeyParameters.properties.Hsm + transform: $["x-ms-client-name"] = "HSM" + - from: swagger-document + where: $.definitions..properties..iv + transform: $["x-ms-client-name"] = "IV" + - from: swagger-document + where: $.definitions..properties..kid + transform: $["x-ms-client-name"] = "KID" + - from: swagger-document + where: $.paths..parameters..[?(@.name=='maxresults')] + transform: $["x-ms-client-name"] = "MaxResults" + + # keyName, keyVersion -> name, version + - from: swagger-document + where: $.paths..parameters..[?(@.name=='key-name')] + transform: $["x-ms-client-name"] = "name" + - from: swagger-document + where: $.paths..parameters..[?(@.name=='key-version')] + transform: $["x-ms-client-name"] = "version" + + # KeyEncryptionAlgorithm renames + - from: swagger-document + where: $.definitions.ReleaseParameters.properties.enc.x-ms-enum + transform: $["name"] = "KeyExportEncryptionAlgorithm" + - from: swagger-document + where: $.definitions.ReleaseParameters.properties.enc + transform: $["x-ms-client-name"] = "algorithm" + + # rename KeyOperationsParameters fields + - from: swagger-document + where: $.definitions.KeyOperationParameters.properties.aad + transform: $["x-ms-client-name"] = "AdditionalAuthenticatedData" + - from: swagger-document + where: $.definitions.KeyOperationParameters.properties.tag + transform: $["x-ms-client-name"] = "AuthenticationTag" + + # remove JSONWeb Prefix + - from: + - models.go + - constants.go + where: $ + transform: return $.replace(/JSONWebKeyOperation/g, "KeyOperation"); + - from: + - models.go + - constants.go + where: $ + transform: return $.replace(/JSONWebKeyCurveName/g, "KeyCurveName"); + - from: + - models.go + - constants.go + where: $ + transform: return $.replace(/JSONWebKeyEncryptionAlgorithm/g, "EncryptionAlgorithm"); + - from: + - models.go + - constants.go + where: $ + transform: return $.replace(/JSONWebKeySignatureAlgorithm/g, "SignatureAlgorithm"); + - from: + - models.go + - constants.go + where: $ + transform: return $.replace(/JSONWebKeyType/g, "KeyType"); + + # remove DeletionRecoveryLevel type + - from: models.go + where: $ + transform: return $.replace(/RecoveryLevel \*DeletionRecoveryLevel/g, "RecoveryLevel *string"); + - from: constants.go + where: $ + transform: return $.replace(/(?:\/\/.*\s)+type DeletionRecoveryLevel string/, ""); + - from: constants.go + where: $ + transform: return $.replace(/(?:\/\/.*\s)+func PossibleDeletionRecovery(?:.+\s)+\}/, ""); + - from: constants.go + where: $ + transform: return $.replace(/const \(\n\s\/\/ DeletionRecoveryLevel(?:.+\s)+\)/, ""); # delete unused error models - from: models.go diff --git a/sdk/security/keyvault/azkeys/client.go b/sdk/security/keyvault/azkeys/client.go index 4cc063c69fd0..5e6f6a8fda5c 100644 --- a/sdk/security/keyvault/azkeys/client.go +++ b/sdk/security/keyvault/azkeys/client.go @@ -132,7 +132,7 @@ func (client *Client) createKeyCreateRequest(ctx context.Context, name string, p // createKeyHandleResponse handles the CreateKey response. func (client *Client) createKeyHandleResponse(resp *http.Response) (CreateKeyResponse, error) { result := CreateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return CreateKeyResponse{}, err } return result, nil @@ -153,7 +153,7 @@ func (client *Client) createKeyHandleResponse(resp *http.Response) (CreateKeyRes // - version - The version of the key. // - parameters - The parameters for the decryption operation. // - options - DecryptOptions contains the optional parameters for the Client.Decrypt method. -func (client *Client) Decrypt(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *DecryptOptions) (DecryptResponse, error) { +func (client *Client) Decrypt(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *DecryptOptions) (DecryptResponse, error) { req, err := client.decryptCreateRequest(ctx, name, version, parameters, options) if err != nil { return DecryptResponse{}, err @@ -169,7 +169,7 @@ func (client *Client) Decrypt(ctx context.Context, name string, version string, } // decryptCreateRequest creates the Decrypt request. -func (client *Client) decryptCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *DecryptOptions) (*policy.Request, error) { +func (client *Client) decryptCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *DecryptOptions) (*policy.Request, error) { urlPath := "/keys/{key-name}/{key-version}/decrypt" if name == "" { return nil, errors.New("parameter name cannot be empty") @@ -240,7 +240,7 @@ func (client *Client) deleteKeyCreateRequest(ctx context.Context, name string, o // deleteKeyHandleResponse handles the DeleteKey response. func (client *Client) deleteKeyHandleResponse(resp *http.Response) (DeleteKeyResponse, error) { result := DeleteKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKey); err != nil { return DeleteKeyResponse{}, err } return result, nil @@ -260,7 +260,7 @@ func (client *Client) deleteKeyHandleResponse(resp *http.Response) (DeleteKeyRes // - version - The version of the key. // - parameters - The parameters for the encryption operation. // - options - EncryptOptions contains the optional parameters for the Client.Encrypt method. -func (client *Client) Encrypt(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *EncryptOptions) (EncryptResponse, error) { +func (client *Client) Encrypt(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *EncryptOptions) (EncryptResponse, error) { req, err := client.encryptCreateRequest(ctx, name, version, parameters, options) if err != nil { return EncryptResponse{}, err @@ -276,7 +276,7 @@ func (client *Client) Encrypt(ctx context.Context, name string, version string, } // encryptCreateRequest creates the Encrypt request. -func (client *Client) encryptCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *EncryptOptions) (*policy.Request, error) { +func (client *Client) encryptCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *EncryptOptions) (*policy.Request, error) { urlPath := "/keys/{key-name}/{key-version}/encrypt" if name == "" { return nil, errors.New("parameter name cannot be empty") @@ -347,7 +347,7 @@ func (client *Client) getDeletedKeyCreateRequest(ctx context.Context, name strin // getDeletedKeyHandleResponse handles the GetDeletedKey response. func (client *Client) getDeletedKeyHandleResponse(resp *http.Response) (GetDeletedKeyResponse, error) { result := GetDeletedKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKey); err != nil { return GetDeletedKeyResponse{}, err } return result, nil @@ -399,7 +399,7 @@ func (client *Client) getKeyCreateRequest(ctx context.Context, name string, vers // getKeyHandleResponse handles the GetKey response. func (client *Client) getKeyHandleResponse(resp *http.Response) (GetKeyResponse, error) { result := GetKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return GetKeyResponse{}, err } return result, nil @@ -460,7 +460,7 @@ func (client *Client) getKeyRotationPolicyHandleResponse(resp *http.Response) (G // Generated from API version 7.4 // - parameters - The request object to get random bytes. // - options - GetRandomBytesOptions contains the optional parameters for the Client.GetRandomBytes method. -func (client *Client) GetRandomBytes(ctx context.Context, parameters GetRandomBytesRequest, options *GetRandomBytesOptions) (GetRandomBytesResponse, error) { +func (client *Client) GetRandomBytes(ctx context.Context, parameters GetRandomBytesParameters, options *GetRandomBytesOptions) (GetRandomBytesResponse, error) { req, err := client.getRandomBytesCreateRequest(ctx, parameters, options) if err != nil { return GetRandomBytesResponse{}, err @@ -476,7 +476,7 @@ func (client *Client) GetRandomBytes(ctx context.Context, parameters GetRandomBy } // getRandomBytesCreateRequest creates the GetRandomBytes request. -func (client *Client) getRandomBytesCreateRequest(ctx context.Context, parameters GetRandomBytesRequest, options *GetRandomBytesOptions) (*policy.Request, error) { +func (client *Client) getRandomBytesCreateRequest(ctx context.Context, parameters GetRandomBytesParameters, options *GetRandomBytesOptions) (*policy.Request, error) { urlPath := "/rng" req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.endpoint, urlPath)) if err != nil { @@ -544,50 +544,51 @@ func (client *Client) importKeyCreateRequest(ctx context.Context, name string, p // importKeyHandleResponse handles the ImportKey response. func (client *Client) importKeyHandleResponse(resp *http.Response) (ImportKeyResponse, error) { result := ImportKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return ImportKeyResponse{}, err } return result, nil } -// NewListDeletedKeysPager - Retrieves a list of the keys in the Key Vault as JSON Web Key structures that contain the public -// part of a deleted key. This operation includes deletion-specific information. The Get Deleted Keys +// NewListDeletedKeyPropertiesPager - Retrieves a list of the keys in the Key Vault as JSON Web Key structures that contain +// the public part of a deleted key. This operation includes deletion-specific information. The Get Deleted Keys // operation is applicable for vaults enabled for soft-delete. While the operation can be invoked on any vault, it will return // an error if invoked on a non soft-delete enabled vault. This operation // requires the keys/list permission. // // Generated from API version 7.4 -// - options - ListDeletedKeysOptions contains the optional parameters for the Client.NewListDeletedKeysPager method. -func (client *Client) NewListDeletedKeysPager(options *ListDeletedKeysOptions) *runtime.Pager[ListDeletedKeysResponse] { - return runtime.NewPager(runtime.PagingHandler[ListDeletedKeysResponse]{ - More: func(page ListDeletedKeysResponse) bool { +// - options - ListDeletedKeyPropertiesOptions contains the optional parameters for the Client.NewListDeletedKeyPropertiesPager +// method. +func (client *Client) NewListDeletedKeyPropertiesPager(options *ListDeletedKeyPropertiesOptions) *runtime.Pager[ListDeletedKeyPropertiesResponse] { + return runtime.NewPager(runtime.PagingHandler[ListDeletedKeyPropertiesResponse]{ + More: func(page ListDeletedKeyPropertiesResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *ListDeletedKeysResponse) (ListDeletedKeysResponse, error) { + Fetcher: func(ctx context.Context, page *ListDeletedKeyPropertiesResponse) (ListDeletedKeyPropertiesResponse, error) { var req *policy.Request var err error if page == nil { - req, err = client.listDeletedKeysCreateRequest(ctx, options) + req, err = client.listDeletedKeyPropertiesCreateRequest(ctx, options) } else { req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) } if err != nil { - return ListDeletedKeysResponse{}, err + return ListDeletedKeyPropertiesResponse{}, err } resp, err := client.internal.Pipeline().Do(req) if err != nil { - return ListDeletedKeysResponse{}, err + return ListDeletedKeyPropertiesResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return ListDeletedKeysResponse{}, runtime.NewResponseError(resp) + return ListDeletedKeyPropertiesResponse{}, runtime.NewResponseError(resp) } - return client.listDeletedKeysHandleResponse(resp) + return client.listDeletedKeyPropertiesHandleResponse(resp) }, }) } -// listDeletedKeysCreateRequest creates the ListDeletedKeys request. -func (client *Client) listDeletedKeysCreateRequest(ctx context.Context, options *ListDeletedKeysOptions) (*policy.Request, error) { +// listDeletedKeyPropertiesCreateRequest creates the ListDeletedKeyProperties request. +func (client *Client) listDeletedKeyPropertiesCreateRequest(ctx context.Context, options *ListDeletedKeyPropertiesOptions) (*policy.Request, error) { urlPath := "/deletedkeys" req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) if err != nil { @@ -603,56 +604,53 @@ func (client *Client) listDeletedKeysCreateRequest(ctx context.Context, options return req, nil } -// listDeletedKeysHandleResponse handles the ListDeletedKeys response. -func (client *Client) listDeletedKeysHandleResponse(resp *http.Response) (ListDeletedKeysResponse, error) { - result := ListDeletedKeysResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKeyListResult); err != nil { - return ListDeletedKeysResponse{}, err +// listDeletedKeyPropertiesHandleResponse handles the ListDeletedKeyProperties response. +func (client *Client) listDeletedKeyPropertiesHandleResponse(resp *http.Response) (ListDeletedKeyPropertiesResponse, error) { + result := ListDeletedKeyPropertiesResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.DeletedKeyPropertiesListResult); err != nil { + return ListDeletedKeyPropertiesResponse{}, err } return result, nil } -// NewListKeyVersionsPager - The full key identifier, attributes, and tags are provided in the response. This operation requires -// the keys/list permission. +// NewListKeyPropertiesPager - Retrieves a list of the keys in the Key Vault as JSON Web Key structures that contain the public +// part of a stored key. The LIST operation is applicable to all key types, however only the base key +// identifier, attributes, and tags are provided in the response. Individual versions of a key are not listed in the response. +// This operation requires the keys/list permission. // // Generated from API version 7.4 -// - name - The name of the key. -// - options - ListKeyVersionsOptions contains the optional parameters for the Client.NewListKeyVersionsPager method. -func (client *Client) NewListKeyVersionsPager(name string, options *ListKeyVersionsOptions) *runtime.Pager[ListKeyVersionsResponse] { - return runtime.NewPager(runtime.PagingHandler[ListKeyVersionsResponse]{ - More: func(page ListKeyVersionsResponse) bool { +// - options - ListKeyPropertiesOptions contains the optional parameters for the Client.NewListKeyPropertiesPager method. +func (client *Client) NewListKeyPropertiesPager(options *ListKeyPropertiesOptions) *runtime.Pager[ListKeyPropertiesResponse] { + return runtime.NewPager(runtime.PagingHandler[ListKeyPropertiesResponse]{ + More: func(page ListKeyPropertiesResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *ListKeyVersionsResponse) (ListKeyVersionsResponse, error) { + Fetcher: func(ctx context.Context, page *ListKeyPropertiesResponse) (ListKeyPropertiesResponse, error) { var req *policy.Request var err error if page == nil { - req, err = client.listKeyVersionsCreateRequest(ctx, name, options) + req, err = client.listKeyPropertiesCreateRequest(ctx, options) } else { req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) } if err != nil { - return ListKeyVersionsResponse{}, err + return ListKeyPropertiesResponse{}, err } resp, err := client.internal.Pipeline().Do(req) if err != nil { - return ListKeyVersionsResponse{}, err + return ListKeyPropertiesResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return ListKeyVersionsResponse{}, runtime.NewResponseError(resp) + return ListKeyPropertiesResponse{}, runtime.NewResponseError(resp) } - return client.listKeyVersionsHandleResponse(resp) + return client.listKeyPropertiesHandleResponse(resp) }, }) } -// listKeyVersionsCreateRequest creates the ListKeyVersions request. -func (client *Client) listKeyVersionsCreateRequest(ctx context.Context, name string, options *ListKeyVersionsOptions) (*policy.Request, error) { - urlPath := "/keys/{key-name}/versions" - if name == "" { - return nil, errors.New("parameter name cannot be empty") - } - urlPath = strings.ReplaceAll(urlPath, "{key-name}", url.PathEscape(name)) +// listKeyPropertiesCreateRequest creates the ListKeyProperties request. +func (client *Client) listKeyPropertiesCreateRequest(ctx context.Context, options *ListKeyPropertiesOptions) (*policy.Request, error) { + urlPath := "/keys" req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) if err != nil { return nil, err @@ -667,53 +665,57 @@ func (client *Client) listKeyVersionsCreateRequest(ctx context.Context, name str return req, nil } -// listKeyVersionsHandleResponse handles the ListKeyVersions response. -func (client *Client) listKeyVersionsHandleResponse(resp *http.Response) (ListKeyVersionsResponse, error) { - result := ListKeyVersionsResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyListResult); err != nil { - return ListKeyVersionsResponse{}, err +// listKeyPropertiesHandleResponse handles the ListKeyProperties response. +func (client *Client) listKeyPropertiesHandleResponse(resp *http.Response) (ListKeyPropertiesResponse, error) { + result := ListKeyPropertiesResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.KeyPropertiesListResult); err != nil { + return ListKeyPropertiesResponse{}, err } return result, nil } -// NewListKeysPager - Retrieves a list of the keys in the Key Vault as JSON Web Key structures that contain the public part -// of a stored key. The LIST operation is applicable to all key types, however only the base key -// identifier, attributes, and tags are provided in the response. Individual versions of a key are not listed in the response. -// This operation requires the keys/list permission. +// NewListKeyPropertiesVersionsPager - The full key identifier, attributes, and tags are provided in the response. This operation +// requires the keys/list permission. // // Generated from API version 7.4 -// - options - ListKeysOptions contains the optional parameters for the Client.NewListKeysPager method. -func (client *Client) NewListKeysPager(options *ListKeysOptions) *runtime.Pager[ListKeysResponse] { - return runtime.NewPager(runtime.PagingHandler[ListKeysResponse]{ - More: func(page ListKeysResponse) bool { +// - name - The name of the key. +// - options - ListKeyPropertiesVersionsOptions contains the optional parameters for the Client.NewListKeyPropertiesVersionsPager +// method. +func (client *Client) NewListKeyPropertiesVersionsPager(name string, options *ListKeyPropertiesVersionsOptions) *runtime.Pager[ListKeyPropertiesVersionsResponse] { + return runtime.NewPager(runtime.PagingHandler[ListKeyPropertiesVersionsResponse]{ + More: func(page ListKeyPropertiesVersionsResponse) bool { return page.NextLink != nil && len(*page.NextLink) > 0 }, - Fetcher: func(ctx context.Context, page *ListKeysResponse) (ListKeysResponse, error) { + Fetcher: func(ctx context.Context, page *ListKeyPropertiesVersionsResponse) (ListKeyPropertiesVersionsResponse, error) { var req *policy.Request var err error if page == nil { - req, err = client.listKeysCreateRequest(ctx, options) + req, err = client.listKeyPropertiesVersionsCreateRequest(ctx, name, options) } else { req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) } if err != nil { - return ListKeysResponse{}, err + return ListKeyPropertiesVersionsResponse{}, err } resp, err := client.internal.Pipeline().Do(req) if err != nil { - return ListKeysResponse{}, err + return ListKeyPropertiesVersionsResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return ListKeysResponse{}, runtime.NewResponseError(resp) + return ListKeyPropertiesVersionsResponse{}, runtime.NewResponseError(resp) } - return client.listKeysHandleResponse(resp) + return client.listKeyPropertiesVersionsHandleResponse(resp) }, }) } -// listKeysCreateRequest creates the ListKeys request. -func (client *Client) listKeysCreateRequest(ctx context.Context, options *ListKeysOptions) (*policy.Request, error) { - urlPath := "/keys" +// listKeyPropertiesVersionsCreateRequest creates the ListKeyPropertiesVersions request. +func (client *Client) listKeyPropertiesVersionsCreateRequest(ctx context.Context, name string, options *ListKeyPropertiesVersionsOptions) (*policy.Request, error) { + urlPath := "/keys/{key-name}/versions" + if name == "" { + return nil, errors.New("parameter name cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{key-name}", url.PathEscape(name)) req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath)) if err != nil { return nil, err @@ -728,11 +730,11 @@ func (client *Client) listKeysCreateRequest(ctx context.Context, options *ListKe return req, nil } -// listKeysHandleResponse handles the ListKeys response. -func (client *Client) listKeysHandleResponse(resp *http.Response) (ListKeysResponse, error) { - result := ListKeysResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyListResult); err != nil { - return ListKeysResponse{}, err +// listKeyPropertiesVersionsHandleResponse handles the ListKeyPropertiesVersions response. +func (client *Client) listKeyPropertiesVersionsHandleResponse(resp *http.Response) (ListKeyPropertiesVersionsResponse, error) { + result := ListKeyPropertiesVersionsResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.KeyPropertiesListResult); err != nil { + return ListKeyPropertiesVersionsResponse{}, err } return result, nil } @@ -823,7 +825,7 @@ func (client *Client) recoverDeletedKeyCreateRequest(ctx context.Context, name s // recoverDeletedKeyHandleResponse handles the RecoverDeletedKey response. func (client *Client) recoverDeletedKeyHandleResponse(resp *http.Response) (RecoverDeletedKeyResponse, error) { result := RecoverDeletedKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RecoverDeletedKeyResponse{}, err } return result, nil @@ -927,7 +929,7 @@ func (client *Client) restoreKeyCreateRequest(ctx context.Context, parameters Re // restoreKeyHandleResponse handles the RestoreKey response. func (client *Client) restoreKeyHandleResponse(resp *http.Response) (RestoreKeyResponse, error) { result := RestoreKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RestoreKeyResponse{}, err } return result, nil @@ -975,7 +977,7 @@ func (client *Client) rotateKeyCreateRequest(ctx context.Context, name string, o // rotateKeyHandleResponse handles the RotateKey response. func (client *Client) rotateKeyHandleResponse(resp *http.Response) (RotateKeyResponse, error) { result := RotateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RotateKeyResponse{}, err } return result, nil @@ -1044,7 +1046,7 @@ func (client *Client) signHandleResponse(resp *http.Response) (SignResponse, err // - version - The version of the key. // - parameters - The parameters for the key operation. // - options - UnwrapKeyOptions contains the optional parameters for the Client.UnwrapKey method. -func (client *Client) UnwrapKey(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *UnwrapKeyOptions) (UnwrapKeyResponse, error) { +func (client *Client) UnwrapKey(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *UnwrapKeyOptions) (UnwrapKeyResponse, error) { req, err := client.unwrapKeyCreateRequest(ctx, name, version, parameters, options) if err != nil { return UnwrapKeyResponse{}, err @@ -1060,7 +1062,7 @@ func (client *Client) UnwrapKey(ctx context.Context, name string, version string } // unwrapKeyCreateRequest creates the UnwrapKey request. -func (client *Client) unwrapKeyCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *UnwrapKeyOptions) (*policy.Request, error) { +func (client *Client) unwrapKeyCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *UnwrapKeyOptions) (*policy.Request, error) { urlPath := "/keys/{key-name}/{key-version}/unwrapkey" if name == "" { return nil, errors.New("parameter name cannot be empty") @@ -1133,7 +1135,7 @@ func (client *Client) updateKeyCreateRequest(ctx context.Context, name string, v // updateKeyHandleResponse handles the UpdateKey response. func (client *Client) updateKeyHandleResponse(resp *http.Response) (UpdateKeyResponse, error) { result := UpdateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return UpdateKeyResponse{}, err } return result, nil @@ -1258,7 +1260,7 @@ func (client *Client) verifyHandleResponse(resp *http.Response) (VerifyResponse, // - version - The version of the key. // - parameters - The parameters for wrap operation. // - options - WrapKeyOptions contains the optional parameters for the Client.WrapKey method. -func (client *Client) WrapKey(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *WrapKeyOptions) (WrapKeyResponse, error) { +func (client *Client) WrapKey(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *WrapKeyOptions) (WrapKeyResponse, error) { req, err := client.wrapKeyCreateRequest(ctx, name, version, parameters, options) if err != nil { return WrapKeyResponse{}, err @@ -1274,7 +1276,7 @@ func (client *Client) WrapKey(ctx context.Context, name string, version string, } // wrapKeyCreateRequest creates the WrapKey request. -func (client *Client) wrapKeyCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationsParameters, options *WrapKeyOptions) (*policy.Request, error) { +func (client *Client) wrapKeyCreateRequest(ctx context.Context, name string, version string, parameters KeyOperationParameters, options *WrapKeyOptions) (*policy.Request, error) { urlPath := "/keys/{key-name}/{key-version}/wrapkey" if name == "" { return nil, errors.New("parameter name cannot be empty") diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index e0c034b68a3f..819d6eaa0ab1 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -80,7 +80,7 @@ func TestBackupRestore(t *testing.T) { client := startTest(t, mhsm) keyName := createRandomName(t, "testbackuprestore") - createResp, err := client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA)}, nil) + createResp, err := client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) require.Equal(t, keyName, createResp.Key.KID.Name()) require.NotEmpty(t, createResp.Key.KID.Version()) @@ -108,7 +108,7 @@ func TestBackupRestore(t *testing.T) { require.NoError(t, err) var restoreResp azkeys.RestoreKeyResponse - restoreParams := azkeys.RestoreKeyParameters{KeyBundleBackup: backupResp.Value} + restoreParams := azkeys.RestoreKeyParameters{KeyBackup: backupResp.Value} pollStatus(t, 409, func() error { restoreResp, err = client.RestoreKey(context.Background(), restoreParams, nil) return err @@ -136,13 +136,13 @@ func TestCRUD(t *testing.T) { for _, mhsm := range []bool{false, true} { for _, params := range []azkeys.CreateKeyParameters{ { - Kty: to.Ptr(azkeys.JSONWebKeyTypeEC), - Curve: to.Ptr(azkeys.JSONWebKeyCurveNameP256K), + Kty: to.Ptr(azkeys.KeyTypeEC), + Curve: to.Ptr(azkeys.KeyCurveNameP256K), KeyAttributes: attributes, Tags: tags, }, { - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), + Kty: to.Ptr(azkeys.KeyTypeRSA), KeyAttributes: attributes, KeySize: to.Ptr(int32(2048)), PublicExponent: to.Ptr(int32(65537)), @@ -171,7 +171,7 @@ func TestCRUD(t *testing.T) { requireEqualAttributes(t, createResp.Attributes, getResp.Attributes) require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) - testSerde(t, &getResp.KeyBundle) + testSerde(t, &getResp.KeyVaultKey) updateParams := azkeys.UpdateKeyParameters{ KeyAttributes: &azkeys.KeyAttributes{ @@ -190,7 +190,7 @@ func TestCRUD(t *testing.T) { require.Equal(t, createResp.Key.KID.Name(), deleteResp.Key.KID.Name()) require.Equal(t, createResp.Key.KID.Version(), deleteResp.Key.KID.Version()) requireEqualAttributes(t, updateResp.Attributes, deleteResp.Attributes) - testSerde(t, &deleteResp.DeletedKeyBundle) + testSerde(t, &deleteResp.DeletedKey) pollStatus(t, 404, func() error { _, err := client.GetDeletedKey(context.Background(), keyName, nil) return err @@ -242,7 +242,7 @@ func TestDisableChallengeResourceVerification(t *testing.T) { } client, err := azkeys.NewClient(vaultURL, &FakeCredential{}, options) require.NoError(t, err) - pager := client.NewListKeysPager(nil) + pager := client.NewListKeyPropertiesPager(nil) _, err = pager.NextPage(context.Background()) if test.err { require.Error(t, err) @@ -265,14 +265,14 @@ func TestEncryptDecrypt(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSAHSM), - KeyOps: to.SliceOfPtrs(azkeys.JSONWebKeyOperationEncrypt, azkeys.JSONWebKeyOperationDecrypt), + Kty: to.Ptr(azkeys.KeyTypeRSAHSM), + KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), } createResp, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) - encryptParams := azkeys.KeyOperationsParameters{ - Algorithm: to.Ptr(azkeys.JSONWebKeyEncryptionAlgorithmRSAOAEP256), + encryptParams := azkeys.KeyOperationParameters{ + Algorithm: to.Ptr(azkeys.EncryptionAlgorithmRSAOAEP256), Value: []byte("plaintext"), } testSerde(t, &encryptParams) @@ -281,7 +281,7 @@ func TestEncryptDecrypt(t *testing.T) { require.NotEmpty(t, encryptResponse.Result) testSerde(t, &encryptResponse.KeyOperationResult) - decryptParams := azkeys.KeyOperationsParameters{ + decryptParams := azkeys.KeyOperationParameters{ Algorithm: encryptParams.Algorithm, Value: encryptResponse.Result, } @@ -299,15 +299,15 @@ func TestEncryptDecryptSymmetric(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Kty: to.Ptr(azkeys.JSONWebKeyTypeOct), - KeyOps: to.SliceOfPtrs(azkeys.JSONWebKeyOperationEncrypt, azkeys.JSONWebKeyOperationDecrypt), - KeySize: to.Ptr(int32(256)), + Kty: to.Ptr(azkeys.KeyTypeOct), + KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), + KeySize: to.Ptr(int32(256)), } createResp, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) - encryptParams := azkeys.KeyOperationsParameters{ - Algorithm: to.Ptr(azkeys.JSONWebKeyEncryptionAlgorithmA256CBCPAD), + encryptParams := azkeys.KeyOperationParameters{ + Algorithm: to.Ptr(azkeys.EncryptionAlgorithmA256CBCPAD), // IV must be random in real usage. This value is static only to ensure it matches in playback. IV: []byte("0123456789ABCDEF"), Value: []byte("plaintext"), @@ -317,7 +317,7 @@ func TestEncryptDecryptSymmetric(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, encryptResponse.Result) - decryptParams := azkeys.KeyOperationsParameters{ + decryptParams := azkeys.KeyOperationParameters{ Algorithm: encryptParams.Algorithm, IV: encryptResponse.IV, Value: encryptResponse.Result, @@ -330,7 +330,7 @@ func TestEncryptDecryptSymmetric(t *testing.T) { func TestGetRandomBytes(t *testing.T) { client := startTest(t, true) - req := azkeys.GetRandomBytesRequest{Count: to.Ptr(int32(100))} + req := azkeys.GetRandomBytesParameters{Count: to.Ptr(int32(100))} testSerde(t, &req) resp, err := client.GetRandomBytes(context.Background(), req, nil) require.NoError(t, err) @@ -360,23 +360,23 @@ func TestImportKey(t *testing.T) { t.Run(name, func(t *testing.T) { client := startTest(t, mhsm) jwk := &azkeys.JSONWebKey{ - KeyOps: to.SliceOfPtrs(string(azkeys.JSONWebKeyOperationEncrypt)), - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), - N: toBytes("a0914d00234ac683b21b4c15d5bed887bdc959c2e57af54ae734e8f00720d775d275e455207e3784ceeb60a50a4655dd72a7a94d271e8ee8f7959a669ca6e775bf0e23badae991b4529d978528b4bd90521d32dd2656796ba82b6bbfc7668c8f5eeb5053747fd199319d29a8440d08f4412d527ff9311eda71825920b47b1c46b11ab3e91d7316407e89c7f340f7b85a34042ce51743b27d4718403d34c7b438af6181be05e4d11eb985d38253d7fe9bf53fc2f1b002d22d2d793fa79a504b6ab42d0492804d7071d727a06cf3a8893aa542b1503f832b296371b6707d4dc6e372f8fe67d8ded1c908fde45ce03bc086a71487fa75e43aa0e0679aa0d20efe35", t), - E: toBytes("10001", t), - D: toBytes("627c7d24668148fe2252c7fa649ea8a5a9ed44d75c766cda42b29b660e99404f0e862d4561a6c95af6a83d213e0a2244b03cd28576473215073785fb067f015da19084ade9f475e08b040a9a2c7ba00253bb8125508c9df140b75161d266be347a5e0f6900fe1d8bbf78ccc25eeb37e0c9d188d6e1fc15169ba4fe12276193d77790d2326928bd60d0d01d6ead8d6ac4861abadceec95358fd6689c50a1671a4a936d2376440a41445501da4e74bfb98f823bd19c45b94eb01d98fc0d2f284507f018ebd929b8180dbe6381fdd434bffb7800aaabdd973d55f9eaf9bb88a6ea7b28c2a80231e72de1ad244826d665582c2362761019de2e9f10cb8bcc2625649", t), - P: toBytes("00d1deac8d68ddd2c1fd52d5999655b2cf1565260de5269e43fd2a85f39280e1708ffff0682166cb6106ee5ea5e9ffd9f98d0becc9ff2cda2febc97259215ad84b9051e563e14a051dce438bc6541a24ac4f014cf9732d36ebfc1e61a00d82cbe412090f7793cfbd4b7605be133dfc3991f7e1bed5786f337de5036fc1e2df4cf3", t), - Q: toBytes("00c3dc66b641a9b73cd833bc439cd34fc6574465ab5b7e8a92d32595a224d56d911e74624225b48c15a670282a51c40d1dad4bc2e9a3c8dab0c76f10052dfb053bc6ed42c65288a8e8bace7a8881184323f94d7db17ea6dfba651218f931a93b8f738f3d8fd3f6ba218d35b96861a0f584b0ab88ddcf446b9815f4d287d83a3237", t), - DP: toBytes("00c9a159be7265cbbabc9afcc4967eb74fe58a4c4945431902d1142da599b760e03838f8cbd26b64324fea6bdc9338503f459793636e59b5361d1e6951e08ddb089e1b507be952a81fbeaf7e76890ea4f536e25505c3f648b1e88377dfc19b4c304e738dfca07211b792286a392a704d0f444c0a802539110b7f1f121c00cff0a9", t), - DQ: toBytes("00a0bd4c0a3d9f64436a082374b5caf2488bac1568696153a6a5e4cd85d186db31e2f58f024c617d29f37b4e6b54c97a1e25efec59c4d1fd3061ac33509ce8cae5c11f4cd2e83f41a8264f785e78dc0996076ee23dfdfc43d67c463afaa0180c4a718357f9a6f270d542479a0f213870e661fb950abca4a14ca290570ba7983347", t), - QI: toBytes("009fe7ae42e92bc04fcd5780464bd21d0c8ac0c599f9af020fde6ab0a7e7d1d39902f5d8fb6c614184c4c1b103fb46e94cd10a6c8a40f9991a1f28269f326435b6c50276fda6493353c650a833f724d80c7d522ba16c79f0eb61f672736b68fb8be3243d10943c4ab7028d09e76cfb5892222e38bc4d35585bf35a88cd68c73b07", t), + KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt), + Kty: to.Ptr(azkeys.KeyTypeRSA), + N: toBytes("a0914d00234ac683b21b4c15d5bed887bdc959c2e57af54ae734e8f00720d775d275e455207e3784ceeb60a50a4655dd72a7a94d271e8ee8f7959a669ca6e775bf0e23badae991b4529d978528b4bd90521d32dd2656796ba82b6bbfc7668c8f5eeb5053747fd199319d29a8440d08f4412d527ff9311eda71825920b47b1c46b11ab3e91d7316407e89c7f340f7b85a34042ce51743b27d4718403d34c7b438af6181be05e4d11eb985d38253d7fe9bf53fc2f1b002d22d2d793fa79a504b6ab42d0492804d7071d727a06cf3a8893aa542b1503f832b296371b6707d4dc6e372f8fe67d8ded1c908fde45ce03bc086a71487fa75e43aa0e0679aa0d20efe35", t), + E: toBytes("10001", t), + D: toBytes("627c7d24668148fe2252c7fa649ea8a5a9ed44d75c766cda42b29b660e99404f0e862d4561a6c95af6a83d213e0a2244b03cd28576473215073785fb067f015da19084ade9f475e08b040a9a2c7ba00253bb8125508c9df140b75161d266be347a5e0f6900fe1d8bbf78ccc25eeb37e0c9d188d6e1fc15169ba4fe12276193d77790d2326928bd60d0d01d6ead8d6ac4861abadceec95358fd6689c50a1671a4a936d2376440a41445501da4e74bfb98f823bd19c45b94eb01d98fc0d2f284507f018ebd929b8180dbe6381fdd434bffb7800aaabdd973d55f9eaf9bb88a6ea7b28c2a80231e72de1ad244826d665582c2362761019de2e9f10cb8bcc2625649", t), + P: toBytes("00d1deac8d68ddd2c1fd52d5999655b2cf1565260de5269e43fd2a85f39280e1708ffff0682166cb6106ee5ea5e9ffd9f98d0becc9ff2cda2febc97259215ad84b9051e563e14a051dce438bc6541a24ac4f014cf9732d36ebfc1e61a00d82cbe412090f7793cfbd4b7605be133dfc3991f7e1bed5786f337de5036fc1e2df4cf3", t), + Q: toBytes("00c3dc66b641a9b73cd833bc439cd34fc6574465ab5b7e8a92d32595a224d56d911e74624225b48c15a670282a51c40d1dad4bc2e9a3c8dab0c76f10052dfb053bc6ed42c65288a8e8bace7a8881184323f94d7db17ea6dfba651218f931a93b8f738f3d8fd3f6ba218d35b96861a0f584b0ab88ddcf446b9815f4d287d83a3237", t), + DP: toBytes("00c9a159be7265cbbabc9afcc4967eb74fe58a4c4945431902d1142da599b760e03838f8cbd26b64324fea6bdc9338503f459793636e59b5361d1e6951e08ddb089e1b507be952a81fbeaf7e76890ea4f536e25505c3f648b1e88377dfc19b4c304e738dfca07211b792286a392a704d0f444c0a802539110b7f1f121c00cff0a9", t), + DQ: toBytes("00a0bd4c0a3d9f64436a082374b5caf2488bac1568696153a6a5e4cd85d186db31e2f58f024c617d29f37b4e6b54c97a1e25efec59c4d1fd3061ac33509ce8cae5c11f4cd2e83f41a8264f785e78dc0996076ee23dfdfc43d67c463afaa0180c4a718357f9a6f270d542479a0f213870e661fb950abca4a14ca290570ba7983347", t), + QI: toBytes("009fe7ae42e92bc04fcd5780464bd21d0c8ac0c599f9af020fde6ab0a7e7d1d39902f5d8fb6c614184c4c1b103fb46e94cd10a6c8a40f9991a1f28269f326435b6c50276fda6493353c650a833f724d80c7d522ba16c79f0eb61f672736b68fb8be3243d10943c4ab7028d09e76cfb5892222e38bc4d35585bf35a88cd68c73b07", t), } params := azkeys.ImportKeyParameters{HSM: to.Ptr(true), Key: jwk} testSerde(t, ¶ms) resp, err := client.ImportKey(context.Background(), createRandomName(t, "testimport"), params, nil) require.NoError(t, err) defer cleanUpKey(t, client, resp.Key.KID) - require.Equal(t, jwk.KeyOps, resp.Key.KeyOps) + require.Equal(t, jwk.KeyOperations, resp.Key.KeyOperations) require.Equal(t, jwk.N, resp.Key.N) require.Equal(t, jwk.E, resp.Key.E) }) @@ -394,7 +394,7 @@ func TestListDeletedKeys(t *testing.T) { count := 4 keyNames := make([]string, count) createParams := azkeys.CreateKeyParameters{ - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), + Kty: to.Ptr(azkeys.KeyTypeRSA), Tags: map[string]*string{"count-this-key": to.Ptr("yes")}, } for i := 0; i < len(keyNames); i++ { @@ -410,11 +410,11 @@ func TestListDeletedKeys(t *testing.T) { return err }) } - pager := client.NewListDeletedKeysPager(&azkeys.ListDeletedKeysOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListDeletedKeyPropertiesPager(&azkeys.ListDeletedKeyPropertiesOptions{MaxResults: to.Ptr(int32(1))}) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) - testSerde(t, &resp.DeletedKeyListResult) + testSerde(t, &resp.DeletedKeyPropertiesListResult) for _, key := range resp.Value { require.NotEmpty(t, key.Attributes) require.NotNil(t, key.DeletedDate) @@ -447,17 +447,17 @@ func TestListKeys(t *testing.T) { keyNamePrefix := "testlistkeys" for i := 0; i < 4; i++ { n := createRandomName(t, fmt.Sprintf("%s-%d", keyNamePrefix, i)) - resp, err := client.CreateKey(context.Background(), n, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA)}, nil) + resp, err := client.CreateKey(context.Background(), n, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) defer cleanUpKey(t, client, resp.Key.KID) count++ } - pager := client.NewListKeysPager(&azkeys.ListKeysOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListKeyPropertiesPager(&azkeys.ListKeyPropertiesOptions{MaxResults: to.Ptr(int32(1))}) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) - testSerde(t, &resp.KeyListResult) + testSerde(t, &resp.KeyPropertiesListResult) for _, key := range resp.Value { require.NotNil(t, key) require.NotNil(t, key.Attributes) @@ -487,17 +487,17 @@ func TestListKeyVersions(t *testing.T) { keyName := createRandomName(t, "listkeyversions") expectedVersions := make(map[string]struct{}, 4) for i := 0; i < 4; i++ { - createResp, err = client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA)}, nil) + createResp, err = client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) expectedVersions[createResp.Key.KID.Version()] = struct{}{} require.NoError(t, err) } defer cleanUpKey(t, client, createResp.Key.KID) - pager := client.NewListKeyVersionsPager(keyName, &azkeys.ListKeyVersionsOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListKeyPropertiesVersionsPager(keyName, &azkeys.ListKeyPropertiesVersionsOptions{MaxResults: to.Ptr(int32(1))}) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) - testSerde(t, &resp.KeyListResult) + testSerde(t, &resp.KeyPropertiesListResult) for _, key := range resp.Value { testSerde(t, key) require.NotNil(t, key) @@ -525,7 +525,7 @@ func TestRecoverDeletedKey(t *testing.T) { client := startTest(t, mhsm) key := createRandomName(t, "key") - createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeEC)}, nil) + createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeEC)}, nil) require.NoError(t, err) _, err = client.DeleteKey(context.Background(), key, nil) @@ -564,11 +564,11 @@ func TestReleaseKey(t *testing.T) { var err error for i := 0; i < 5; i++ { params := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.JSONWebKeyCurveNameP256K), + Curve: to.Ptr(azkeys.KeyCurveNameP256K), KeyAttributes: &azkeys.KeyAttributes{ Exportable: to.Ptr(true), }, - Kty: to.Ptr(azkeys.JSONWebKeyTypeECHSM), + Kty: to.Ptr(azkeys.KeyTypeECHSM), ReleasePolicy: &azkeys.KeyReleasePolicy{ EncodedPolicy: getMarshalledReleasePolicy(attestationURL), Immutable: to.Ptr(true), @@ -623,7 +623,7 @@ func TestRotateKey(t *testing.T) { t.Run(name, func(t *testing.T) { client := startTest(t, mhsm) key := createRandomName(t, "testrotatekey") - createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeECHSM)}, nil) + createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeECHSM)}, nil) require.NoError(t, err) defer cleanUpKey(t, client, createResp.Key.KID) @@ -632,12 +632,12 @@ func TestRotateKey(t *testing.T) { Attributes: &azkeys.KeyRotationPolicyAttributes{ ExpiryTime: to.Ptr("P90D"), }, - LifetimeActions: []*azkeys.LifetimeActions{ + LifetimeActions: []*azkeys.KeyRotationLifetimeActions{ { - Action: &azkeys.LifetimeActionsType{ + Action: &azkeys.KeyRotationLifetimeActionsType{ Type: to.Ptr(azkeys.KeyRotationPolicyActionRotate), }, - Trigger: &azkeys.LifetimeActionsTrigger{ + Trigger: &azkeys.KeyRotationLifetimeActionsTrigger{ TimeAfterCreate: timeAfterCreate, }, }, @@ -683,9 +683,9 @@ func TestSignVerify(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.JSONWebKeyCurveNameP256K), - KeyOps: to.SliceOfPtrs(azkeys.JSONWebKeyOperationSign, azkeys.JSONWebKeyOperationVerify), - Kty: to.Ptr(azkeys.JSONWebKeyTypeEC), + Curve: to.Ptr(azkeys.KeyCurveNameP256K), + KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationSign, azkeys.KeyOperationVerify), + Kty: to.Ptr(azkeys.KeyTypeEC), } _, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) @@ -695,7 +695,7 @@ func TestSignVerify(t *testing.T) { require.NoError(t, err) digest := hasher.Sum(nil) - signParams := azkeys.SignParameters{Algorithm: to.Ptr(azkeys.JSONWebKeySignatureAlgorithmES256K), Value: digest} + signParams := azkeys.SignParameters{Algorithm: to.Ptr(azkeys.SignatureAlgorithmES256K), Value: digest} testSerde(t, &signParams) signResponse, err := client.Sign(context.Background(), keyName, "", signParams, nil) require.NoError(t, err) @@ -723,19 +723,19 @@ func TestWrapUnwrap(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - KeyOps: to.SliceOfPtrs(azkeys.JSONWebKeyOperationWrapKey, azkeys.JSONWebKeyOperationUnwrapKey), - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), + KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationWrapKey, azkeys.KeyOperationUnwrapKey), + Kty: to.Ptr(azkeys.KeyTypeRSA), } _, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) keyBytes := []byte("5063e6aaa845f150200547944fd199679c98ed6f99da0a0b2dafeaf1f4684496fd532c1c229968cb9dee44957fcef7ccef59ceda0b362e56bcd78fd3faee5781c623c0bb22b35beabde0664fd30e0e824aba3dd1b0afffc4a3d955ede20cf6a854d52cfd") - wrapParams := azkeys.KeyOperationsParameters{Algorithm: to.Ptr(azkeys.JSONWebKeyEncryptionAlgorithmRSAOAEP), Value: keyBytes} + wrapParams := azkeys.KeyOperationParameters{Algorithm: to.Ptr(azkeys.EncryptionAlgorithmRSAOAEP), Value: keyBytes} wrapResp, err := client.WrapKey(context.Background(), keyName, "", wrapParams, nil) require.NoError(t, err) - unwrapResp, err := client.UnwrapKey(context.Background(), keyName, "", azkeys.KeyOperationsParameters{Algorithm: wrapParams.Algorithm, Value: wrapResp.Result}, nil) + unwrapResp, err := client.UnwrapKey(context.Background(), keyName, "", azkeys.KeyOperationParameters{Algorithm: wrapParams.Algorithm, Value: wrapResp.Result}, nil) require.NoError(t, err) require.Equal(t, keyBytes, unwrapResp.Result) }) diff --git a/sdk/security/keyvault/azkeys/constants.go b/sdk/security/keyvault/azkeys/constants.go index 464b9a67cebd..94985790745d 100644 --- a/sdk/security/keyvault/azkeys/constants.go +++ b/sdk/security/keyvault/azkeys/constants.go @@ -9,244 +9,191 @@ package azkeys -// DeletionRecoveryLevel - Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains -// 'Purgeable' the key can be permanently deleted by a privileged user; otherwise, only the system -// can purge the key, at the end of the retention interval. -type DeletionRecoveryLevel string +// KeyCurveName - Elliptic curve name. For valid values, see JsonWebKeyCurveName. +type KeyCurveName string const ( - // DeletionRecoveryLevelCustomizedRecoverable - Denotes a vault state in which deletion is recoverable without the possibility - // for immediate and permanent deletion (i.e. purge when 7<= SoftDeleteRetentionInDays < 90).This level guarantees the recoverability - // of the deleted entity during the retention interval and while the subscription is still available. - DeletionRecoveryLevelCustomizedRecoverable DeletionRecoveryLevel = "CustomizedRecoverable" - // DeletionRecoveryLevelCustomizedRecoverableProtectedSubscription - Denotes a vault and subscription state in which deletion - // is recoverable, immediate and permanent deletion (i.e. purge) is not permitted, and in which the subscription itself cannot - // be permanently canceled when 7<= SoftDeleteRetentionInDays < 90. This level guarantees the recoverability of the deleted - // entity during the retention interval, and also reflects the fact that the subscription itself cannot be cancelled. - DeletionRecoveryLevelCustomizedRecoverableProtectedSubscription DeletionRecoveryLevel = "CustomizedRecoverable+ProtectedSubscription" - // DeletionRecoveryLevelCustomizedRecoverablePurgeable - Denotes a vault state in which deletion is recoverable, and which - // also permits immediate and permanent deletion (i.e. purge when 7<= SoftDeleteRetentionInDays < 90). This level guarantees - // the recoverability of the deleted entity during the retention interval, unless a Purge operation is requested, or the subscription - // is cancelled. - DeletionRecoveryLevelCustomizedRecoverablePurgeable DeletionRecoveryLevel = "CustomizedRecoverable+Purgeable" - // DeletionRecoveryLevelPurgeable - Denotes a vault state in which deletion is an irreversible operation, without the possibility - // for recovery. This level corresponds to no protection being available against a Delete operation; the data is irretrievably - // lost upon accepting a Delete operation at the entity level or higher (vault, resource group, subscription etc.) - DeletionRecoveryLevelPurgeable DeletionRecoveryLevel = "Purgeable" - // DeletionRecoveryLevelRecoverable - Denotes a vault state in which deletion is recoverable without the possibility for immediate - // and permanent deletion (i.e. purge). This level guarantees the recoverability of the deleted entity during the retention - // interval(90 days) and while the subscription is still available. System wil permanently delete it after 90 days, if not - // recovered - DeletionRecoveryLevelRecoverable DeletionRecoveryLevel = "Recoverable" - // DeletionRecoveryLevelRecoverableProtectedSubscription - Denotes a vault and subscription state in which deletion is recoverable - // within retention interval (90 days), immediate and permanent deletion (i.e. purge) is not permitted, and in which the subscription - // itself cannot be permanently canceled. System wil permanently delete it after 90 days, if not recovered - DeletionRecoveryLevelRecoverableProtectedSubscription DeletionRecoveryLevel = "Recoverable+ProtectedSubscription" - // DeletionRecoveryLevelRecoverablePurgeable - Denotes a vault state in which deletion is recoverable, and which also permits - // immediate and permanent deletion (i.e. purge). This level guarantees the recoverability of the deleted entity during the - // retention interval (90 days), unless a Purge operation is requested, or the subscription is cancelled. System wil permanently - // delete it after 90 days, if not recovered - DeletionRecoveryLevelRecoverablePurgeable DeletionRecoveryLevel = "Recoverable+Purgeable" + // KeyCurveNameP256 - The NIST P-256 elliptic curve, AKA SECG curve SECP256R1. + KeyCurveNameP256 KeyCurveName = "P-256" + // KeyCurveNameP256K - The SECG SECP256K1 elliptic curve. + KeyCurveNameP256K KeyCurveName = "P-256K" + // KeyCurveNameP384 - The NIST P-384 elliptic curve, AKA SECG curve SECP384R1. + KeyCurveNameP384 KeyCurveName = "P-384" + // KeyCurveNameP521 - The NIST P-521 elliptic curve, AKA SECG curve SECP521R1. + KeyCurveNameP521 KeyCurveName = "P-521" ) -// PossibleDeletionRecoveryLevelValues returns the possible values for the DeletionRecoveryLevel const type. -func PossibleDeletionRecoveryLevelValues() []DeletionRecoveryLevel { - return []DeletionRecoveryLevel{ - DeletionRecoveryLevelCustomizedRecoverable, - DeletionRecoveryLevelCustomizedRecoverableProtectedSubscription, - DeletionRecoveryLevelCustomizedRecoverablePurgeable, - DeletionRecoveryLevelPurgeable, - DeletionRecoveryLevelRecoverable, - DeletionRecoveryLevelRecoverableProtectedSubscription, - DeletionRecoveryLevelRecoverablePurgeable, +// PossibleKeyCurveNameValues returns the possible values for the KeyCurveName const type. +func PossibleKeyCurveNameValues() []KeyCurveName { + return []KeyCurveName{ + KeyCurveNameP256, + KeyCurveNameP256K, + KeyCurveNameP384, + KeyCurveNameP521, } } -// JSONWebKeyCurveName - Elliptic curve name. For valid values, see JsonWebKeyCurveName. -type JSONWebKeyCurveName string +// EncryptionAlgorithm - algorithm identifier +type EncryptionAlgorithm string const ( - // JSONWebKeyCurveNameP256 - The NIST P-256 elliptic curve, AKA SECG curve SECP256R1. - JSONWebKeyCurveNameP256 JSONWebKeyCurveName = "P-256" - // JSONWebKeyCurveNameP256K - The SECG SECP256K1 elliptic curve. - JSONWebKeyCurveNameP256K JSONWebKeyCurveName = "P-256K" - // JSONWebKeyCurveNameP384 - The NIST P-384 elliptic curve, AKA SECG curve SECP384R1. - JSONWebKeyCurveNameP384 JSONWebKeyCurveName = "P-384" - // JSONWebKeyCurveNameP521 - The NIST P-521 elliptic curve, AKA SECG curve SECP521R1. - JSONWebKeyCurveNameP521 JSONWebKeyCurveName = "P-521" + EncryptionAlgorithmA128CBC EncryptionAlgorithm = "A128CBC" + EncryptionAlgorithmA128CBCPAD EncryptionAlgorithm = "A128CBCPAD" + EncryptionAlgorithmA128GCM EncryptionAlgorithm = "A128GCM" + EncryptionAlgorithmA128KW EncryptionAlgorithm = "A128KW" + EncryptionAlgorithmA192CBC EncryptionAlgorithm = "A192CBC" + EncryptionAlgorithmA192CBCPAD EncryptionAlgorithm = "A192CBCPAD" + EncryptionAlgorithmA192GCM EncryptionAlgorithm = "A192GCM" + EncryptionAlgorithmA192KW EncryptionAlgorithm = "A192KW" + EncryptionAlgorithmA256CBC EncryptionAlgorithm = "A256CBC" + EncryptionAlgorithmA256CBCPAD EncryptionAlgorithm = "A256CBCPAD" + EncryptionAlgorithmA256GCM EncryptionAlgorithm = "A256GCM" + EncryptionAlgorithmA256KW EncryptionAlgorithm = "A256KW" + EncryptionAlgorithmRSA15 EncryptionAlgorithm = "RSA1_5" + EncryptionAlgorithmRSAOAEP EncryptionAlgorithm = "RSA-OAEP" + EncryptionAlgorithmRSAOAEP256 EncryptionAlgorithm = "RSA-OAEP-256" ) -// PossibleJSONWebKeyCurveNameValues returns the possible values for the JSONWebKeyCurveName const type. -func PossibleJSONWebKeyCurveNameValues() []JSONWebKeyCurveName { - return []JSONWebKeyCurveName{ - JSONWebKeyCurveNameP256, - JSONWebKeyCurveNameP256K, - JSONWebKeyCurveNameP384, - JSONWebKeyCurveNameP521, +// PossibleEncryptionAlgorithmValues returns the possible values for the EncryptionAlgorithm const type. +func PossibleEncryptionAlgorithmValues() []EncryptionAlgorithm { + return []EncryptionAlgorithm{ + EncryptionAlgorithmA128CBC, + EncryptionAlgorithmA128CBCPAD, + EncryptionAlgorithmA128GCM, + EncryptionAlgorithmA128KW, + EncryptionAlgorithmA192CBC, + EncryptionAlgorithmA192CBCPAD, + EncryptionAlgorithmA192GCM, + EncryptionAlgorithmA192KW, + EncryptionAlgorithmA256CBC, + EncryptionAlgorithmA256CBCPAD, + EncryptionAlgorithmA256GCM, + EncryptionAlgorithmA256KW, + EncryptionAlgorithmRSA15, + EncryptionAlgorithmRSAOAEP, + EncryptionAlgorithmRSAOAEP256, } } -// JSONWebKeyEncryptionAlgorithm - algorithm identifier -type JSONWebKeyEncryptionAlgorithm string +// KeyOperation - JSON web key operations. For more information, see JsonWebKeyOperation. +type KeyOperation string const ( - JSONWebKeyEncryptionAlgorithmA128CBC JSONWebKeyEncryptionAlgorithm = "A128CBC" - JSONWebKeyEncryptionAlgorithmA128CBCPAD JSONWebKeyEncryptionAlgorithm = "A128CBCPAD" - JSONWebKeyEncryptionAlgorithmA128GCM JSONWebKeyEncryptionAlgorithm = "A128GCM" - JSONWebKeyEncryptionAlgorithmA128KW JSONWebKeyEncryptionAlgorithm = "A128KW" - JSONWebKeyEncryptionAlgorithmA192CBC JSONWebKeyEncryptionAlgorithm = "A192CBC" - JSONWebKeyEncryptionAlgorithmA192CBCPAD JSONWebKeyEncryptionAlgorithm = "A192CBCPAD" - JSONWebKeyEncryptionAlgorithmA192GCM JSONWebKeyEncryptionAlgorithm = "A192GCM" - JSONWebKeyEncryptionAlgorithmA192KW JSONWebKeyEncryptionAlgorithm = "A192KW" - JSONWebKeyEncryptionAlgorithmA256CBC JSONWebKeyEncryptionAlgorithm = "A256CBC" - JSONWebKeyEncryptionAlgorithmA256CBCPAD JSONWebKeyEncryptionAlgorithm = "A256CBCPAD" - JSONWebKeyEncryptionAlgorithmA256GCM JSONWebKeyEncryptionAlgorithm = "A256GCM" - JSONWebKeyEncryptionAlgorithmA256KW JSONWebKeyEncryptionAlgorithm = "A256KW" - JSONWebKeyEncryptionAlgorithmRSA15 JSONWebKeyEncryptionAlgorithm = "RSA1_5" - JSONWebKeyEncryptionAlgorithmRSAOAEP JSONWebKeyEncryptionAlgorithm = "RSA-OAEP" - JSONWebKeyEncryptionAlgorithmRSAOAEP256 JSONWebKeyEncryptionAlgorithm = "RSA-OAEP-256" + KeyOperationDecrypt KeyOperation = "decrypt" + KeyOperationEncrypt KeyOperation = "encrypt" + KeyOperationExport KeyOperation = "export" + KeyOperationImport KeyOperation = "import" + KeyOperationSign KeyOperation = "sign" + KeyOperationUnwrapKey KeyOperation = "unwrapKey" + KeyOperationVerify KeyOperation = "verify" + KeyOperationWrapKey KeyOperation = "wrapKey" ) -// PossibleJSONWebKeyEncryptionAlgorithmValues returns the possible values for the JSONWebKeyEncryptionAlgorithm const type. -func PossibleJSONWebKeyEncryptionAlgorithmValues() []JSONWebKeyEncryptionAlgorithm { - return []JSONWebKeyEncryptionAlgorithm{ - JSONWebKeyEncryptionAlgorithmA128CBC, - JSONWebKeyEncryptionAlgorithmA128CBCPAD, - JSONWebKeyEncryptionAlgorithmA128GCM, - JSONWebKeyEncryptionAlgorithmA128KW, - JSONWebKeyEncryptionAlgorithmA192CBC, - JSONWebKeyEncryptionAlgorithmA192CBCPAD, - JSONWebKeyEncryptionAlgorithmA192GCM, - JSONWebKeyEncryptionAlgorithmA192KW, - JSONWebKeyEncryptionAlgorithmA256CBC, - JSONWebKeyEncryptionAlgorithmA256CBCPAD, - JSONWebKeyEncryptionAlgorithmA256GCM, - JSONWebKeyEncryptionAlgorithmA256KW, - JSONWebKeyEncryptionAlgorithmRSA15, - JSONWebKeyEncryptionAlgorithmRSAOAEP, - JSONWebKeyEncryptionAlgorithmRSAOAEP256, +// PossibleKeyOperationValues returns the possible values for the KeyOperation const type. +func PossibleKeyOperationValues() []KeyOperation { + return []KeyOperation{ + KeyOperationDecrypt, + KeyOperationEncrypt, + KeyOperationExport, + KeyOperationImport, + KeyOperationSign, + KeyOperationUnwrapKey, + KeyOperationVerify, + KeyOperationWrapKey, } } -// JSONWebKeyOperation - JSON web key operations. For more information, see JsonWebKeyOperation. -type JSONWebKeyOperation string - -const ( - JSONWebKeyOperationDecrypt JSONWebKeyOperation = "decrypt" - JSONWebKeyOperationEncrypt JSONWebKeyOperation = "encrypt" - JSONWebKeyOperationExport JSONWebKeyOperation = "export" - JSONWebKeyOperationImport JSONWebKeyOperation = "import" - JSONWebKeyOperationSign JSONWebKeyOperation = "sign" - JSONWebKeyOperationUnwrapKey JSONWebKeyOperation = "unwrapKey" - JSONWebKeyOperationVerify JSONWebKeyOperation = "verify" - JSONWebKeyOperationWrapKey JSONWebKeyOperation = "wrapKey" -) - -// PossibleJSONWebKeyOperationValues returns the possible values for the JSONWebKeyOperation const type. -func PossibleJSONWebKeyOperationValues() []JSONWebKeyOperation { - return []JSONWebKeyOperation{ - JSONWebKeyOperationDecrypt, - JSONWebKeyOperationEncrypt, - JSONWebKeyOperationExport, - JSONWebKeyOperationImport, - JSONWebKeyOperationSign, - JSONWebKeyOperationUnwrapKey, - JSONWebKeyOperationVerify, - JSONWebKeyOperationWrapKey, - } -} - -// JSONWebKeySignatureAlgorithm - The signing/verification algorithm identifier. For more information on possible algorithm +// SignatureAlgorithm - The signing/verification algorithm identifier. For more information on possible algorithm // types, see JsonWebKeySignatureAlgorithm. -type JSONWebKeySignatureAlgorithm string +type SignatureAlgorithm string const ( - // JSONWebKeySignatureAlgorithmES256 - ECDSA using P-256 and SHA-256, as described in https://tools.ietf.org/html/rfc7518. - JSONWebKeySignatureAlgorithmES256 JSONWebKeySignatureAlgorithm = "ES256" - // JSONWebKeySignatureAlgorithmES256K - ECDSA using P-256K and SHA-256, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmES256K JSONWebKeySignatureAlgorithm = "ES256K" - // JSONWebKeySignatureAlgorithmES384 - ECDSA using P-384 and SHA-384, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmES384 JSONWebKeySignatureAlgorithm = "ES384" - // JSONWebKeySignatureAlgorithmES512 - ECDSA using P-521 and SHA-512, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmES512 JSONWebKeySignatureAlgorithm = "ES512" - // JSONWebKeySignatureAlgorithmPS256 - RSASSA-PSS using SHA-256 and MGF1 with SHA-256, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmPS256 JSONWebKeySignatureAlgorithm = "PS256" - // JSONWebKeySignatureAlgorithmPS384 - RSASSA-PSS using SHA-384 and MGF1 with SHA-384, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmPS384 JSONWebKeySignatureAlgorithm = "PS384" - // JSONWebKeySignatureAlgorithmPS512 - RSASSA-PSS using SHA-512 and MGF1 with SHA-512, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmPS512 JSONWebKeySignatureAlgorithm = "PS512" - // JSONWebKeySignatureAlgorithmRS256 - RSASSA-PKCS1-v1_5 using SHA-256, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmRS256 JSONWebKeySignatureAlgorithm = "RS256" - // JSONWebKeySignatureAlgorithmRS384 - RSASSA-PKCS1-v1_5 using SHA-384, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmRS384 JSONWebKeySignatureAlgorithm = "RS384" - // JSONWebKeySignatureAlgorithmRS512 - RSASSA-PKCS1-v1_5 using SHA-512, as described in https://tools.ietf.org/html/rfc7518 - JSONWebKeySignatureAlgorithmRS512 JSONWebKeySignatureAlgorithm = "RS512" - // JSONWebKeySignatureAlgorithmRSNULL - Reserved - JSONWebKeySignatureAlgorithmRSNULL JSONWebKeySignatureAlgorithm = "RSNULL" + // SignatureAlgorithmES256 - ECDSA using P-256 and SHA-256, as described in https://tools.ietf.org/html/rfc7518. + SignatureAlgorithmES256 SignatureAlgorithm = "ES256" + // SignatureAlgorithmES256K - ECDSA using P-256K and SHA-256, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmES256K SignatureAlgorithm = "ES256K" + // SignatureAlgorithmES384 - ECDSA using P-384 and SHA-384, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmES384 SignatureAlgorithm = "ES384" + // SignatureAlgorithmES512 - ECDSA using P-521 and SHA-512, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmES512 SignatureAlgorithm = "ES512" + // SignatureAlgorithmPS256 - RSASSA-PSS using SHA-256 and MGF1 with SHA-256, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmPS256 SignatureAlgorithm = "PS256" + // SignatureAlgorithmPS384 - RSASSA-PSS using SHA-384 and MGF1 with SHA-384, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmPS384 SignatureAlgorithm = "PS384" + // SignatureAlgorithmPS512 - RSASSA-PSS using SHA-512 and MGF1 with SHA-512, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmPS512 SignatureAlgorithm = "PS512" + // SignatureAlgorithmRS256 - RSASSA-PKCS1-v1_5 using SHA-256, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmRS256 SignatureAlgorithm = "RS256" + // SignatureAlgorithmRS384 - RSASSA-PKCS1-v1_5 using SHA-384, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmRS384 SignatureAlgorithm = "RS384" + // SignatureAlgorithmRS512 - RSASSA-PKCS1-v1_5 using SHA-512, as described in https://tools.ietf.org/html/rfc7518 + SignatureAlgorithmRS512 SignatureAlgorithm = "RS512" + // SignatureAlgorithmRSNULL - Reserved + SignatureAlgorithmRSNULL SignatureAlgorithm = "RSNULL" ) -// PossibleJSONWebKeySignatureAlgorithmValues returns the possible values for the JSONWebKeySignatureAlgorithm const type. -func PossibleJSONWebKeySignatureAlgorithmValues() []JSONWebKeySignatureAlgorithm { - return []JSONWebKeySignatureAlgorithm{ - JSONWebKeySignatureAlgorithmES256, - JSONWebKeySignatureAlgorithmES256K, - JSONWebKeySignatureAlgorithmES384, - JSONWebKeySignatureAlgorithmES512, - JSONWebKeySignatureAlgorithmPS256, - JSONWebKeySignatureAlgorithmPS384, - JSONWebKeySignatureAlgorithmPS512, - JSONWebKeySignatureAlgorithmRS256, - JSONWebKeySignatureAlgorithmRS384, - JSONWebKeySignatureAlgorithmRS512, - JSONWebKeySignatureAlgorithmRSNULL, +// PossibleSignatureAlgorithmValues returns the possible values for the SignatureAlgorithm const type. +func PossibleSignatureAlgorithmValues() []SignatureAlgorithm { + return []SignatureAlgorithm{ + SignatureAlgorithmES256, + SignatureAlgorithmES256K, + SignatureAlgorithmES384, + SignatureAlgorithmES512, + SignatureAlgorithmPS256, + SignatureAlgorithmPS384, + SignatureAlgorithmPS512, + SignatureAlgorithmRS256, + SignatureAlgorithmRS384, + SignatureAlgorithmRS512, + SignatureAlgorithmRSNULL, } } -// JSONWebKeyType - JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. -type JSONWebKeyType string +// KeyType - JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. +type KeyType string const ( - // JSONWebKeyTypeEC - Elliptic Curve. - JSONWebKeyTypeEC JSONWebKeyType = "EC" - // JSONWebKeyTypeECHSM - Elliptic Curve with a private key which is stored in the HSM. - JSONWebKeyTypeECHSM JSONWebKeyType = "EC-HSM" - // JSONWebKeyTypeOct - Octet sequence (used to represent symmetric keys) - JSONWebKeyTypeOct JSONWebKeyType = "oct" - // JSONWebKeyTypeOctHSM - Octet sequence (used to represent symmetric keys) which is stored the HSM. - JSONWebKeyTypeOctHSM JSONWebKeyType = "oct-HSM" - // JSONWebKeyTypeRSA - RSA (https://tools.ietf.org/html/rfc3447) - JSONWebKeyTypeRSA JSONWebKeyType = "RSA" - // JSONWebKeyTypeRSAHSM - RSA with a private key which is stored in the HSM. - JSONWebKeyTypeRSAHSM JSONWebKeyType = "RSA-HSM" + // KeyTypeEC - Elliptic Curve. + KeyTypeEC KeyType = "EC" + // KeyTypeECHSM - Elliptic Curve with a private key which is stored in the HSM. + KeyTypeECHSM KeyType = "EC-HSM" + // KeyTypeOct - Octet sequence (used to represent symmetric keys) + KeyTypeOct KeyType = "oct" + // KeyTypeOctHSM - Octet sequence (used to represent symmetric keys) which is stored the HSM. + KeyTypeOctHSM KeyType = "oct-HSM" + // KeyTypeRSA - RSA (https://tools.ietf.org/html/rfc3447) + KeyTypeRSA KeyType = "RSA" + // KeyTypeRSAHSM - RSA with a private key which is stored in the HSM. + KeyTypeRSAHSM KeyType = "RSA-HSM" ) -// PossibleJSONWebKeyTypeValues returns the possible values for the JSONWebKeyType const type. -func PossibleJSONWebKeyTypeValues() []JSONWebKeyType { - return []JSONWebKeyType{ - JSONWebKeyTypeEC, - JSONWebKeyTypeECHSM, - JSONWebKeyTypeOct, - JSONWebKeyTypeOctHSM, - JSONWebKeyTypeRSA, - JSONWebKeyTypeRSAHSM, +// PossibleKeyTypeValues returns the possible values for the KeyType const type. +func PossibleKeyTypeValues() []KeyType { + return []KeyType{ + KeyTypeEC, + KeyTypeECHSM, + KeyTypeOct, + KeyTypeOctHSM, + KeyTypeRSA, + KeyTypeRSAHSM, } } -// KeyEncryptionAlgorithm - The encryption algorithm to use to protected the exported key material -type KeyEncryptionAlgorithm string +// KeyExportEncryptionAlgorithm - The encryption algorithm to use to protected the exported key material +type KeyExportEncryptionAlgorithm string const ( - KeyEncryptionAlgorithmCKMRSAAESKEYWRAP KeyEncryptionAlgorithm = "CKM_RSA_AES_KEY_WRAP" - KeyEncryptionAlgorithmRSAAESKEYWRAP256 KeyEncryptionAlgorithm = "RSA_AES_KEY_WRAP_256" - KeyEncryptionAlgorithmRSAAESKEYWRAP384 KeyEncryptionAlgorithm = "RSA_AES_KEY_WRAP_384" + KeyExportEncryptionAlgorithmCKMRSAAESKEYWRAP KeyExportEncryptionAlgorithm = "CKM_RSA_AES_KEY_WRAP" + KeyExportEncryptionAlgorithmRSAAESKEYWRAP256 KeyExportEncryptionAlgorithm = "RSA_AES_KEY_WRAP_256" + KeyExportEncryptionAlgorithmRSAAESKEYWRAP384 KeyExportEncryptionAlgorithm = "RSA_AES_KEY_WRAP_384" ) -// PossibleKeyEncryptionAlgorithmValues returns the possible values for the KeyEncryptionAlgorithm const type. -func PossibleKeyEncryptionAlgorithmValues() []KeyEncryptionAlgorithm { - return []KeyEncryptionAlgorithm{ - KeyEncryptionAlgorithmCKMRSAAESKEYWRAP, - KeyEncryptionAlgorithmRSAAESKEYWRAP256, - KeyEncryptionAlgorithmRSAAESKEYWRAP384, +// PossibleKeyExportEncryptionAlgorithmValues returns the possible values for the KeyExportEncryptionAlgorithm const type. +func PossibleKeyExportEncryptionAlgorithmValues() []KeyExportEncryptionAlgorithm { + return []KeyExportEncryptionAlgorithm{ + KeyExportEncryptionAlgorithmCKMRSAAESKEYWRAP, + KeyExportEncryptionAlgorithmRSAAESKEYWRAP256, + KeyExportEncryptionAlgorithmRSAAESKEYWRAP384, } } diff --git a/sdk/security/keyvault/azkeys/example_test.go b/sdk/security/keyvault/azkeys/example_test.go index e3173a455c20..f627e9634854 100644 --- a/sdk/security/keyvault/azkeys/example_test.go +++ b/sdk/security/keyvault/azkeys/example_test.go @@ -36,7 +36,7 @@ func ExampleNewClient() { func ExampleClient_CreateKey_rsa() { params := azkeys.CreateKeyParameters{ KeySize: to.Ptr(int32(2048)), - Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), + Kty: to.Ptr(azkeys.KeyTypeRSA), } // if a key with the same name already exists, a new version of that key is created resp, err := client.CreateKey(context.TODO(), "key-name", params, nil) @@ -48,8 +48,8 @@ func ExampleClient_CreateKey_rsa() { func ExampleClient_CreateKey_ec() { params := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.JSONWebKeyCurveNameP256K), - Kty: to.Ptr(azkeys.JSONWebKeyTypeEC), + Curve: to.Ptr(azkeys.KeyCurveNameP256K), + Kty: to.Ptr(azkeys.KeyTypeEC), } // if a key with the same name already exists, a new version of that key is created resp, err := client.CreateKey(context.TODO(), "key-name", params, nil) @@ -74,7 +74,7 @@ func ExampleClient_DeleteKey() { func ExampleClient_PurgeDeletedKey() { // this loop purges all the deleted keys in the vault - pager := client.NewListDeletedKeysPager(nil) + pager := client.NewListDeletedKeyPropertiesPager(nil) for pager.More() { page, err := pager.NextPage(context.TODO()) if err != nil { @@ -123,12 +123,12 @@ func ExampleClient_UpdateKey() { func ExampleClient_UpdateKeyRotationPolicy() { // this policy rotates the key every 18 months policy := azkeys.KeyRotationPolicy{ - LifetimeActions: []*azkeys.LifetimeActions{ + LifetimeActions: []*azkeys.KeyRotationLifetimeActions{ { - Action: &azkeys.LifetimeActionsType{ + Action: &azkeys.KeyRotationLifetimeActionsType{ Type: to.Ptr(azkeys.KeyRotationPolicyActionRotate), }, - Trigger: &azkeys.LifetimeActionsTrigger{ + Trigger: &azkeys.KeyRotationLifetimeActionsTrigger{ TimeAfterCreate: to.Ptr("P18M"), }, }, @@ -141,8 +141,8 @@ func ExampleClient_UpdateKeyRotationPolicy() { fmt.Printf("Updated key rotation policy at: %v", resp.Attributes.Updated) } -func ExampleClient_NewListKeysPager() { - pager := client.NewListKeysPager(nil) +func ExampleClient_NewListKeyPropertiesPager() { + pager := client.NewListKeyPropertiesPager(nil) for pager.More() { resp, err := pager.NextPage(context.TODO()) if err != nil { diff --git a/sdk/security/keyvault/azkeys/models.go b/sdk/security/keyvault/azkeys/models.go index 7561561ad087..08fb5418445c 100644 --- a/sdk/security/keyvault/azkeys/models.go +++ b/sdk/security/keyvault/azkeys/models.go @@ -67,20 +67,22 @@ type ImportKeyOptions struct { // placeholder for future optional parameters } -// ListDeletedKeysOptions contains the optional parameters for the Client.NewListDeletedKeysPager method. -type ListDeletedKeysOptions struct { +// ListDeletedKeyPropertiesOptions contains the optional parameters for the Client.NewListDeletedKeyPropertiesPager +// method. +type ListDeletedKeyPropertiesOptions struct { // Maximum number of results to return in a page. If not specified the service will return up to 25 results. MaxResults *int32 } -// ListKeyVersionsOptions contains the optional parameters for the Client.NewListKeyVersionsPager method. -type ListKeyVersionsOptions struct { +// ListKeyPropertiesOptions contains the optional parameters for the Client.NewListKeyPropertiesPager method. +type ListKeyPropertiesOptions struct { // Maximum number of results to return in a page. If not specified the service will return up to 25 results. MaxResults *int32 } -// ListKeysOptions contains the optional parameters for the Client.NewListKeysPager method. -type ListKeysOptions struct { +// ListKeyPropertiesVersionsOptions contains the optional parameters for the Client.NewListKeyPropertiesVersionsPager +// method. +type ListKeyPropertiesVersionsOptions struct { // Maximum number of results to return in a page. If not specified the service will return up to 25 results. MaxResults *int32 } @@ -143,14 +145,14 @@ type WrapKeyOptions struct { // CreateKeyParameters - The key create parameters. type CreateKeyParameters struct { // REQUIRED; The type of key to create. For valid values, see JsonWebKeyType. - Kty *JSONWebKeyType `json:"kty,omitempty"` + Kty *KeyType `json:"kty,omitempty"` // Elliptic curve name. For valid values, see JsonWebKeyCurveName. - Curve *JSONWebKeyCurveName `json:"crv,omitempty"` + Curve *KeyCurveName `json:"crv,omitempty"` // The attributes of a key managed by the key vault service. - KeyAttributes *KeyAttributes `json:"attributes,omitempty"` - KeyOps []*JSONWebKeyOperation `json:"key_ops,omitempty"` + KeyAttributes *KeyAttributes `json:"attributes,omitempty"` + KeyOperations []*KeyOperation `json:"key_ops,omitempty"` // The key size in bits. For example: 2048, 3072, or 4096 for RSA. KeySize *int32 `json:"key_size,omitempty"` @@ -165,8 +167,8 @@ type CreateKeyParameters struct { Tags map[string]*string `json:"tags,omitempty"` } -// DeletedKeyBundle - A DeletedKeyBundle consisting of a WebKey plus its Attributes and deletion info -type DeletedKeyBundle struct { +// DeletedKey - A DeletedKeyBundle consisting of a WebKey plus its Attributes and deletion info +type DeletedKey struct { // The key management attributes. Attributes *KeyAttributes `json:"attributes,omitempty"` @@ -193,8 +195,8 @@ type DeletedKeyBundle struct { ScheduledPurgeDate *time.Time `json:"scheduledPurgeDate,omitempty" azure:"ro"` } -// DeletedKeyItem - The deleted key item containing the deleted key metadata and information about deletion. -type DeletedKeyItem struct { +// DeletedKeyProperties - The deleted key item containing the deleted key metadata and information about deletion. +type DeletedKeyProperties struct { // The key management attributes. Attributes *KeyAttributes `json:"attributes,omitempty"` @@ -218,18 +220,18 @@ type DeletedKeyItem struct { ScheduledPurgeDate *time.Time `json:"scheduledPurgeDate,omitempty" azure:"ro"` } -// DeletedKeyListResult - A list of keys that have been deleted in this vault. -type DeletedKeyListResult struct { +// DeletedKeyPropertiesListResult - A list of keys that have been deleted in this vault. +type DeletedKeyPropertiesListResult struct { // READ-ONLY; The URL to get the next set of deleted keys. NextLink *string `json:"nextLink,omitempty" azure:"ro"` // READ-ONLY; A response message containing a list of deleted keys in the vault along with a link to the next page of deleted // keys - Value []*DeletedKeyItem `json:"value,omitempty" azure:"ro"` + Value []*DeletedKeyProperties `json:"value,omitempty" azure:"ro"` } -// GetRandomBytesRequest - The get random bytes request object. -type GetRandomBytesRequest struct { +// GetRandomBytesParameters - The get random bytes request object. +type GetRandomBytesParameters struct { // REQUIRED; The requested number of random bytes. Count *int32 `json:"count,omitempty"` } @@ -255,7 +257,7 @@ type ImportKeyParameters struct { // JSONWebKey - As of http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18 type JSONWebKey struct { // Elliptic curve name. For valid values, see JsonWebKeyCurveName. - Crv *JSONWebKeyCurveName `json:"crv,omitempty"` + Crv *KeyCurveName `json:"crv,omitempty"` // RSA private exponent, or the D component of an EC private key. D []byte `json:"d,omitempty"` @@ -273,11 +275,11 @@ type JSONWebKey struct { K []byte `json:"k,omitempty"` // Key identifier. - KID *ID `json:"kid,omitempty"` - KeyOps []*string `json:"key_ops,omitempty"` + KID *ID `json:"kid,omitempty"` + KeyOperations []*KeyOperation `json:"key_ops,omitempty"` // JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. - Kty *JSONWebKeyType `json:"kty,omitempty"` + Kty *KeyType `json:"kty,omitempty"` // RSA modulus. N []byte `json:"n,omitempty"` @@ -325,54 +327,28 @@ type KeyAttributes struct { // READ-ONLY; Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains 'Purgeable' // the key can be permanently deleted by a privileged user; otherwise, only the system // can purge the key, at the end of the retention interval. - RecoveryLevel *DeletionRecoveryLevel `json:"recoveryLevel,omitempty" azure:"ro"` + RecoveryLevel *string `json:"recoveryLevel,omitempty" azure:"ro"` // READ-ONLY; Last updated time in UTC. Updated *time.Time `json:"updated,omitempty" azure:"ro"` } -// KeyBundle - A KeyBundle consisting of a WebKey plus its attributes. -type KeyBundle struct { - // The key management attributes. - Attributes *KeyAttributes `json:"attributes,omitempty"` - - // The Json web key. - Key *JSONWebKey `json:"key,omitempty"` - - // The policy rules under which the key can be exported. - ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` - - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags,omitempty"` - - // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will - // be true. - Managed *bool `json:"managed,omitempty" azure:"ro"` -} - -// KeyItem - The key item containing key metadata. -type KeyItem struct { - // The key management attributes. - Attributes *KeyAttributes `json:"attributes,omitempty"` - - // Key identifier. - KID *ID `json:"kid,omitempty"` +// KeyOperationParameters - The key operations parameters. +type KeyOperationParameters struct { + // REQUIRED; algorithm identifier + Algorithm *EncryptionAlgorithm `json:"alg,omitempty"` - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags,omitempty"` + // REQUIRED + Value []byte `json:"value,omitempty"` - // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will - // be true. - Managed *bool `json:"managed,omitempty" azure:"ro"` -} + // Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms. + AdditionalAuthenticatedData []byte `json:"aad,omitempty"` -// KeyListResult - The key list result. -type KeyListResult struct { - // READ-ONLY; The URL to get the next set of keys. - NextLink *string `json:"nextLink,omitempty" azure:"ro"` + // The tag to authenticate when performing decryption with an authenticated algorithm. + AuthenticationTag []byte `json:"tag,omitempty"` - // READ-ONLY; A response message containing a list of keys in the key vault along with a link to the next page of keys. - Value []*KeyItem `json:"value,omitempty" azure:"ro"` + // Cryptographically random, non-repeating initialization vector for symmetric algorithms. + IV []byte `json:"iv,omitempty"` } // KeyOperationResult - The key operation result. @@ -393,22 +369,29 @@ type KeyOperationResult struct { Result []byte `json:"value,omitempty" azure:"ro"` } -// KeyOperationsParameters - The key operations parameters. -type KeyOperationsParameters struct { - // REQUIRED; algorithm identifier - Algorithm *JSONWebKeyEncryptionAlgorithm `json:"alg,omitempty"` +// KeyProperties - The key item containing key metadata. +type KeyProperties struct { + // The key management attributes. + Attributes *KeyAttributes `json:"attributes,omitempty"` - // REQUIRED - Value []byte `json:"value,omitempty"` + // Key identifier. + KID *ID `json:"kid,omitempty"` - // Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms. - AAD []byte `json:"aad,omitempty"` + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` - // Cryptographically random, non-repeating initialization vector for symmetric algorithms. - IV []byte `json:"iv,omitempty"` + // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will + // be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` +} - // The tag to authenticate when performing decryption with an authenticated algorithm. - Tag []byte `json:"tag,omitempty"` +// KeyPropertiesListResult - The key list result. +type KeyPropertiesListResult struct { + // READ-ONLY; The URL to get the next set of keys. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; A response message containing a list of keys in the key vault along with a link to the next page of keys. + Value []*KeyProperties `json:"value,omitempty" azure:"ro"` } // KeyReleasePolicy - The policy rules under which the key can be exported. @@ -430,6 +413,31 @@ type KeyReleaseResult struct { Value *string `json:"value,omitempty" azure:"ro"` } +// KeyRotationLifetimeActions - Action and its trigger that will be performed by Key Vault over the lifetime of a key. +type KeyRotationLifetimeActions struct { + // The action that will be executed. + Action *KeyRotationLifetimeActionsType `json:"action,omitempty"` + + // The condition that will execute the action. + Trigger *KeyRotationLifetimeActionsTrigger `json:"trigger,omitempty"` +} + +// KeyRotationLifetimeActionsTrigger - A condition to be satisfied for an action to be executed. +type KeyRotationLifetimeActionsTrigger struct { + // Time after creation to attempt to rotate. It only applies to rotate. It will be in ISO 8601 duration format. Example: 90 + // days : "P90D" + TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` + + // Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D" + TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` +} + +// KeyRotationLifetimeActionsType - The action that will be executed. +type KeyRotationLifetimeActionsType struct { + // The type of the action. + Type *KeyRotationPolicyAction `json:"type,omitempty"` +} + // KeyRotationPolicy - Management policy for a key. type KeyRotationPolicy struct { // The key rotation policy attributes. @@ -438,7 +446,7 @@ type KeyRotationPolicy struct { // Actions that will be performed by Key Vault over the lifetime of a key. For preview, lifetimeActions can only have two // items at maximum: one for rotate, one for notify. Notification time would be // default to 30 days before expiry and it is not configurable. - LifetimeActions []*LifetimeActions `json:"lifetimeActions,omitempty"` + LifetimeActions []*KeyRotationLifetimeActions `json:"lifetimeActions,omitempty"` // READ-ONLY; The key policy id. ID *string `json:"id,omitempty" azure:"ro"` @@ -457,35 +465,29 @@ type KeyRotationPolicyAttributes struct { Updated *time.Time `json:"updated,omitempty" azure:"ro"` } -// KeyVerifyResult - The key verify result. -type KeyVerifyResult struct { - // READ-ONLY; True if the signature is verified, otherwise false. - Value *bool `json:"value,omitempty" azure:"ro"` -} +// KeyVaultKey - A KeyBundle consisting of a WebKey plus its attributes. +type KeyVaultKey struct { + // The key management attributes. + Attributes *KeyAttributes `json:"attributes,omitempty"` -// LifetimeActions - Action and its trigger that will be performed by Key Vault over the lifetime of a key. -type LifetimeActions struct { - // The action that will be executed. - Action *LifetimeActionsType `json:"action,omitempty"` + // The Json web key. + Key *JSONWebKey `json:"key,omitempty"` - // The condition that will execute the action. - Trigger *LifetimeActionsTrigger `json:"trigger,omitempty"` -} + // The policy rules under which the key can be exported. + ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` -// LifetimeActionsTrigger - A condition to be satisfied for an action to be executed. -type LifetimeActionsTrigger struct { - // Time after creation to attempt to rotate. It only applies to rotate. It will be in ISO 8601 duration format. Example: 90 - // days : "P90D" - TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` - // Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D" - TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` + // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will + // be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` } -// LifetimeActionsType - The action that will be executed. -type LifetimeActionsType struct { - // The type of the action. - Type *KeyRotationPolicyAction `json:"type,omitempty"` +// KeyVerifyResult - The key verify result. +type KeyVerifyResult struct { + // READ-ONLY; True if the signature is verified, otherwise false. + Value *bool `json:"value,omitempty" azure:"ro"` } // RandomBytes - The get random bytes response object containing the bytes. @@ -500,7 +502,7 @@ type ReleaseParameters struct { TargetAttestationToken *string `json:"target,omitempty"` // The encryption algorithm to use to protected the exported key material - Enc *KeyEncryptionAlgorithm `json:"enc,omitempty"` + Algorithm *KeyExportEncryptionAlgorithm `json:"enc,omitempty"` // A client provided nonce for freshness. Nonce *string `json:"nonce,omitempty"` @@ -509,13 +511,13 @@ type ReleaseParameters struct { // RestoreKeyParameters - The key restore parameters. type RestoreKeyParameters struct { // REQUIRED; The backup blob associated with a key bundle. - KeyBundleBackup []byte `json:"value,omitempty"` + KeyBackup []byte `json:"value,omitempty"` } // SignParameters - The key operations parameters. type SignParameters struct { // REQUIRED; The signing/verification algorithm identifier. For more information on possible algorithm types, see JsonWebKeySignatureAlgorithm. - Algorithm *JSONWebKeySignatureAlgorithm `json:"alg,omitempty"` + Algorithm *SignatureAlgorithm `json:"alg,omitempty"` // REQUIRED Value []byte `json:"value,omitempty"` @@ -527,7 +529,7 @@ type UpdateKeyParameters struct { KeyAttributes *KeyAttributes `json:"attributes,omitempty"` // Json web key operations. For more information on possible key operations, see JsonWebKeyOperation. - KeyOps []*JSONWebKeyOperation `json:"key_ops,omitempty"` + KeyOperations []*KeyOperation `json:"key_ops,omitempty"` // The policy rules under which the key can be exported. ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` @@ -539,7 +541,7 @@ type UpdateKeyParameters struct { // VerifyParameters - The key verify parameters. type VerifyParameters struct { // REQUIRED; The signing/verification algorithm. For more information on possible algorithm types, see JsonWebKeySignatureAlgorithm. - Algorithm *JSONWebKeySignatureAlgorithm `json:"alg,omitempty"` + Algorithm *SignatureAlgorithm `json:"alg,omitempty"` // REQUIRED; The digest used for signing. Digest []byte `json:"digest,omitempty"` diff --git a/sdk/security/keyvault/azkeys/models_serde.go b/sdk/security/keyvault/azkeys/models_serde.go index dddb1732a677..aef453d77457 100644 --- a/sdk/security/keyvault/azkeys/models_serde.go +++ b/sdk/security/keyvault/azkeys/models_serde.go @@ -49,7 +49,7 @@ func (c CreateKeyParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "crv", c.Curve) populate(objectMap, "attributes", c.KeyAttributes) - populate(objectMap, "key_ops", c.KeyOps) + populate(objectMap, "key_ops", c.KeyOperations) populate(objectMap, "key_size", c.KeySize) populate(objectMap, "kty", c.Kty) populate(objectMap, "public_exponent", c.PublicExponent) @@ -74,7 +74,7 @@ func (c *CreateKeyParameters) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KeyAttributes", &c.KeyAttributes) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOps", &c.KeyOps) + err = unpopulate(val, "KeyOperations", &c.KeyOperations) delete(rawMsg, key) case "key_size": err = unpopulate(val, "KeySize", &c.KeySize) @@ -99,8 +99,8 @@ func (c *CreateKeyParameters) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type DeletedKeyBundle. -func (d DeletedKeyBundle) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type DeletedKey. +func (d DeletedKey) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "attributes", d.Attributes) populateTimeUnix(objectMap, "deletedDate", d.DeletedDate) @@ -113,8 +113,8 @@ func (d DeletedKeyBundle) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKeyBundle. -func (d *DeletedKeyBundle) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKey. +func (d *DeletedKey) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", d, err) @@ -154,8 +154,8 @@ func (d *DeletedKeyBundle) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type DeletedKeyItem. -func (d DeletedKeyItem) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type DeletedKeyProperties. +func (d DeletedKeyProperties) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "attributes", d.Attributes) populateTimeUnix(objectMap, "deletedDate", d.DeletedDate) @@ -167,8 +167,8 @@ func (d DeletedKeyItem) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKeyItem. -func (d *DeletedKeyItem) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKeyProperties. +func (d *DeletedKeyProperties) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", d, err) @@ -205,16 +205,16 @@ func (d *DeletedKeyItem) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type DeletedKeyListResult. -func (d DeletedKeyListResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type DeletedKeyPropertiesListResult. +func (d DeletedKeyPropertiesListResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "nextLink", d.NextLink) populate(objectMap, "value", d.Value) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKeyListResult. -func (d *DeletedKeyListResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type DeletedKeyPropertiesListResult. +func (d *DeletedKeyPropertiesListResult) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", d, err) @@ -236,15 +236,15 @@ func (d *DeletedKeyListResult) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type GetRandomBytesRequest. -func (g GetRandomBytesRequest) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type GetRandomBytesParameters. +func (g GetRandomBytesParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "count", g.Count) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type GetRandomBytesRequest. -func (g *GetRandomBytesRequest) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type GetRandomBytesParameters. +func (g *GetRandomBytesParameters) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", g, err) @@ -316,7 +316,7 @@ func (j JSONWebKey) MarshalJSON() ([]byte, error) { populateByteArray(objectMap, "e", j.E, runtime.Base64URLFormat) populateByteArray(objectMap, "k", j.K, runtime.Base64URLFormat) populate(objectMap, "kid", j.KID) - populate(objectMap, "key_ops", j.KeyOps) + populate(objectMap, "key_ops", j.KeyOperations) populate(objectMap, "kty", j.Kty) populateByteArray(objectMap, "n", j.N, runtime.Base64URLFormat) populateByteArray(objectMap, "p", j.P, runtime.Base64URLFormat) @@ -359,7 +359,7 @@ func (j *JSONWebKey) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KID", &j.KID) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOps", &j.KeyOps) + err = unpopulate(val, "KeyOperations", &j.KeyOperations) delete(rawMsg, key) case "kty": err = unpopulate(val, "Kty", &j.Kty) @@ -448,19 +448,19 @@ func (k *KeyAttributes) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyBundle. -func (k KeyBundle) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyOperationParameters. +func (k KeyOperationParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "attributes", k.Attributes) - populate(objectMap, "key", k.Key) - populate(objectMap, "managed", k.Managed) - populate(objectMap, "release_policy", k.ReleasePolicy) - populate(objectMap, "tags", k.Tags) + populateByteArray(objectMap, "aad", k.AdditionalAuthenticatedData, runtime.Base64URLFormat) + populate(objectMap, "alg", k.Algorithm) + populateByteArray(objectMap, "tag", k.AuthenticationTag, runtime.Base64URLFormat) + populateByteArray(objectMap, "iv", k.IV, runtime.Base64URLFormat) + populateByteArray(objectMap, "value", k.Value, runtime.Base64URLFormat) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyBundle. -func (k *KeyBundle) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyOperationParameters. +func (k *KeyOperationParameters) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -468,20 +468,20 @@ func (k *KeyBundle) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "attributes": - err = unpopulate(val, "Attributes", &k.Attributes) + case "aad": + err = runtime.DecodeByteArray(string(val), &k.AdditionalAuthenticatedData, runtime.Base64URLFormat) delete(rawMsg, key) - case "key": - err = unpopulate(val, "Key", &k.Key) + case "alg": + err = unpopulate(val, "Algorithm", &k.Algorithm) delete(rawMsg, key) - case "managed": - err = unpopulate(val, "Managed", &k.Managed) + case "tag": + err = runtime.DecodeByteArray(string(val), &k.AuthenticationTag, runtime.Base64URLFormat) delete(rawMsg, key) - case "release_policy": - err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) + case "iv": + err = runtime.DecodeByteArray(string(val), &k.IV, runtime.Base64URLFormat) delete(rawMsg, key) - case "tags": - err = unpopulate(val, "Tags", &k.Tags) + case "value": + err = runtime.DecodeByteArray(string(val), &k.Value, runtime.Base64URLFormat) delete(rawMsg, key) } if err != nil { @@ -491,8 +491,51 @@ func (k *KeyBundle) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyItem. -func (k KeyItem) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyOperationResult. +func (k KeyOperationResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateByteArray(objectMap, "aad", k.AdditionalAuthenticatedData, runtime.Base64URLFormat) + populateByteArray(objectMap, "tag", k.AuthenticationTag, runtime.Base64URLFormat) + populateByteArray(objectMap, "iv", k.IV, runtime.Base64URLFormat) + populate(objectMap, "kid", k.KID) + populateByteArray(objectMap, "value", k.Result, runtime.Base64URLFormat) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyOperationResult. +func (k *KeyOperationResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "aad": + err = runtime.DecodeByteArray(string(val), &k.AdditionalAuthenticatedData, runtime.Base64URLFormat) + delete(rawMsg, key) + case "tag": + err = runtime.DecodeByteArray(string(val), &k.AuthenticationTag, runtime.Base64URLFormat) + delete(rawMsg, key) + case "iv": + err = runtime.DecodeByteArray(string(val), &k.IV, runtime.Base64URLFormat) + delete(rawMsg, key) + case "kid": + err = unpopulate(val, "KID", &k.KID) + delete(rawMsg, key) + case "value": + err = runtime.DecodeByteArray(string(val), &k.Result, runtime.Base64URLFormat) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type KeyProperties. +func (k KeyProperties) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "attributes", k.Attributes) populate(objectMap, "kid", k.KID) @@ -501,8 +544,8 @@ func (k KeyItem) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyItem. -func (k *KeyItem) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyProperties. +func (k *KeyProperties) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -530,16 +573,16 @@ func (k *KeyItem) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyListResult. -func (k KeyListResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyPropertiesListResult. +func (k KeyPropertiesListResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "nextLink", k.NextLink) populate(objectMap, "value", k.Value) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyListResult. -func (k *KeyListResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyPropertiesListResult. +func (k *KeyPropertiesListResult) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -561,19 +604,17 @@ func (k *KeyListResult) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyOperationResult. -func (k KeyOperationResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyReleasePolicy. +func (k KeyReleasePolicy) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateByteArray(objectMap, "aad", k.AdditionalAuthenticatedData, runtime.Base64URLFormat) - populateByteArray(objectMap, "tag", k.AuthenticationTag, runtime.Base64URLFormat) - populateByteArray(objectMap, "iv", k.IV, runtime.Base64URLFormat) - populate(objectMap, "kid", k.KID) - populateByteArray(objectMap, "value", k.Result, runtime.Base64URLFormat) + populate(objectMap, "contentType", k.ContentType) + populateByteArray(objectMap, "data", k.EncodedPolicy, runtime.Base64URLFormat) + populate(objectMap, "immutable", k.Immutable) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyOperationResult. -func (k *KeyOperationResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyReleasePolicy. +func (k *KeyReleasePolicy) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -581,20 +622,41 @@ func (k *KeyOperationResult) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "aad": - err = runtime.DecodeByteArray(string(val), &k.AdditionalAuthenticatedData, runtime.Base64URLFormat) - delete(rawMsg, key) - case "tag": - err = runtime.DecodeByteArray(string(val), &k.AuthenticationTag, runtime.Base64URLFormat) + case "contentType": + err = unpopulate(val, "ContentType", &k.ContentType) delete(rawMsg, key) - case "iv": - err = runtime.DecodeByteArray(string(val), &k.IV, runtime.Base64URLFormat) + case "data": + err = runtime.DecodeByteArray(string(val), &k.EncodedPolicy, runtime.Base64URLFormat) delete(rawMsg, key) - case "kid": - err = unpopulate(val, "KID", &k.KID) + case "immutable": + err = unpopulate(val, "Immutable", &k.Immutable) delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type KeyReleaseResult. +func (k KeyReleaseResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", k.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyReleaseResult. +func (k *KeyReleaseResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + for key, val := range rawMsg { + var err error + switch key { case "value": - err = runtime.DecodeByteArray(string(val), &k.Result, runtime.Base64URLFormat) + err = unpopulate(val, "Value", &k.Value) delete(rawMsg, key) } if err != nil { @@ -604,19 +666,16 @@ func (k *KeyOperationResult) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyOperationsParameters. -func (k KeyOperationsParameters) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActions. +func (k KeyRotationLifetimeActions) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateByteArray(objectMap, "aad", k.AAD, runtime.Base64URLFormat) - populate(objectMap, "alg", k.Algorithm) - populateByteArray(objectMap, "iv", k.IV, runtime.Base64URLFormat) - populateByteArray(objectMap, "tag", k.Tag, runtime.Base64URLFormat) - populateByteArray(objectMap, "value", k.Value, runtime.Base64URLFormat) + populate(objectMap, "action", k.Action) + populate(objectMap, "trigger", k.Trigger) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyOperationsParameters. -func (k *KeyOperationsParameters) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActions. +func (k *KeyRotationLifetimeActions) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -624,20 +683,11 @@ func (k *KeyOperationsParameters) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "aad": - err = runtime.DecodeByteArray(string(val), &k.AAD, runtime.Base64URLFormat) - delete(rawMsg, key) - case "alg": - err = unpopulate(val, "Algorithm", &k.Algorithm) - delete(rawMsg, key) - case "iv": - err = runtime.DecodeByteArray(string(val), &k.IV, runtime.Base64URLFormat) - delete(rawMsg, key) - case "tag": - err = runtime.DecodeByteArray(string(val), &k.Tag, runtime.Base64URLFormat) + case "action": + err = unpopulate(val, "Action", &k.Action) delete(rawMsg, key) - case "value": - err = runtime.DecodeByteArray(string(val), &k.Value, runtime.Base64URLFormat) + case "trigger": + err = unpopulate(val, "Trigger", &k.Trigger) delete(rawMsg, key) } if err != nil { @@ -647,17 +697,16 @@ func (k *KeyOperationsParameters) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyReleasePolicy. -func (k KeyReleasePolicy) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActionsTrigger. +func (k KeyRotationLifetimeActionsTrigger) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "contentType", k.ContentType) - populateByteArray(objectMap, "data", k.EncodedPolicy, runtime.Base64URLFormat) - populate(objectMap, "immutable", k.Immutable) + populate(objectMap, "timeAfterCreate", k.TimeAfterCreate) + populate(objectMap, "timeBeforeExpiry", k.TimeBeforeExpiry) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyReleasePolicy. -func (k *KeyReleasePolicy) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActionsTrigger. +func (k *KeyRotationLifetimeActionsTrigger) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -665,14 +714,11 @@ func (k *KeyReleasePolicy) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "contentType": - err = unpopulate(val, "ContentType", &k.ContentType) - delete(rawMsg, key) - case "data": - err = runtime.DecodeByteArray(string(val), &k.EncodedPolicy, runtime.Base64URLFormat) + case "timeAfterCreate": + err = unpopulate(val, "TimeAfterCreate", &k.TimeAfterCreate) delete(rawMsg, key) - case "immutable": - err = unpopulate(val, "Immutable", &k.Immutable) + case "timeBeforeExpiry": + err = unpopulate(val, "TimeBeforeExpiry", &k.TimeBeforeExpiry) delete(rawMsg, key) } if err != nil { @@ -682,15 +728,15 @@ func (k *KeyReleasePolicy) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyReleaseResult. -func (k KeyReleaseResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActionsType. +func (k KeyRotationLifetimeActionsType) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "value", k.Value) + populate(objectMap, "type", k.Type) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyReleaseResult. -func (k *KeyReleaseResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActionsType. +func (k *KeyRotationLifetimeActionsType) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -698,8 +744,8 @@ func (k *KeyReleaseResult) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "value": - err = unpopulate(val, "Value", &k.Value) + case "type": + err = unpopulate(val, "Type", &k.Type) delete(rawMsg, key) } if err != nil { @@ -779,15 +825,19 @@ func (k *KeyRotationPolicyAttributes) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. -func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyVaultKey. +func (k KeyVaultKey) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "value", k.Value) + populate(objectMap, "attributes", k.Attributes) + populate(objectMap, "key", k.Key) + populate(objectMap, "managed", k.Managed) + populate(objectMap, "release_policy", k.ReleasePolicy) + populate(objectMap, "tags", k.Tags) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVerifyResult. -func (k *KeyVerifyResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVaultKey. +func (k *KeyVaultKey) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -795,101 +845,51 @@ func (k *KeyVerifyResult) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "value": - err = unpopulate(val, "Value", &k.Value) + case "attributes": + err = unpopulate(val, "Attributes", &k.Attributes) delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - } - return nil -} - -// MarshalJSON implements the json.Marshaller interface for type LifetimeActions. -func (l LifetimeActions) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "action", l.Action) - populate(objectMap, "trigger", l.Trigger) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActions. -func (l *LifetimeActions) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "action": - err = unpopulate(val, "Action", &l.Action) + case "key": + err = unpopulate(val, "Key", &k.Key) delete(rawMsg, key) - case "trigger": - err = unpopulate(val, "Trigger", &l.Trigger) + case "managed": + err = unpopulate(val, "Managed", &k.Managed) delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) - } - } - return nil -} - -// MarshalJSON implements the json.Marshaller interface for type LifetimeActionsTrigger. -func (l LifetimeActionsTrigger) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "timeAfterCreate", l.TimeAfterCreate) - populate(objectMap, "timeBeforeExpiry", l.TimeBeforeExpiry) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActionsTrigger. -func (l *LifetimeActionsTrigger) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "timeAfterCreate": - err = unpopulate(val, "TimeAfterCreate", &l.TimeAfterCreate) + case "release_policy": + err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) delete(rawMsg, key) - case "timeBeforeExpiry": - err = unpopulate(val, "TimeBeforeExpiry", &l.TimeBeforeExpiry) + case "tags": + err = unpopulate(val, "Tags", &k.Tags) delete(rawMsg, key) } if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) + return fmt.Errorf("unmarshalling type %T: %v", k, err) } } return nil } -// MarshalJSON implements the json.Marshaller interface for type LifetimeActionsType. -func (l LifetimeActionsType) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. +func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "type", l.Type) + populate(objectMap, "value", k.Value) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActionsType. -func (l *LifetimeActionsType) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVerifyResult. +func (k *KeyVerifyResult) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) + return fmt.Errorf("unmarshalling type %T: %v", k, err) } for key, val := range rawMsg { var err error switch key { - case "type": - err = unpopulate(val, "Type", &l.Type) + case "value": + err = unpopulate(val, "Value", &k.Value) delete(rawMsg, key) } if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", l, err) + return fmt.Errorf("unmarshalling type %T: %v", k, err) } } return nil @@ -925,7 +925,7 @@ func (r *RandomBytes) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type ReleaseParameters. func (r ReleaseParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "enc", r.Enc) + populate(objectMap, "enc", r.Algorithm) populate(objectMap, "nonce", r.Nonce) populate(objectMap, "target", r.TargetAttestationToken) return json.Marshal(objectMap) @@ -941,7 +941,7 @@ func (r *ReleaseParameters) UnmarshalJSON(data []byte) error { var err error switch key { case "enc": - err = unpopulate(val, "Enc", &r.Enc) + err = unpopulate(val, "Algorithm", &r.Algorithm) delete(rawMsg, key) case "nonce": err = unpopulate(val, "Nonce", &r.Nonce) @@ -960,7 +960,7 @@ func (r *ReleaseParameters) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type RestoreKeyParameters. func (r RestoreKeyParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateByteArray(objectMap, "value", r.KeyBundleBackup, runtime.Base64URLFormat) + populateByteArray(objectMap, "value", r.KeyBackup, runtime.Base64URLFormat) return json.Marshal(objectMap) } @@ -974,7 +974,7 @@ func (r *RestoreKeyParameters) UnmarshalJSON(data []byte) error { var err error switch key { case "value": - err = runtime.DecodeByteArray(string(val), &r.KeyBundleBackup, runtime.Base64URLFormat) + err = runtime.DecodeByteArray(string(val), &r.KeyBackup, runtime.Base64URLFormat) delete(rawMsg, key) } if err != nil { @@ -1019,7 +1019,7 @@ func (s *SignParameters) UnmarshalJSON(data []byte) error { func (u UpdateKeyParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "attributes", u.KeyAttributes) - populate(objectMap, "key_ops", u.KeyOps) + populate(objectMap, "key_ops", u.KeyOperations) populate(objectMap, "release_policy", u.ReleasePolicy) populate(objectMap, "tags", u.Tags) return json.Marshal(objectMap) @@ -1038,7 +1038,7 @@ func (u *UpdateKeyParameters) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KeyAttributes", &u.KeyAttributes) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOps", &u.KeyOps) + err = unpopulate(val, "KeyOperations", &u.KeyOperations) delete(rawMsg, key) case "release_policy": err = unpopulate(val, "ReleasePolicy", &u.ReleasePolicy) diff --git a/sdk/security/keyvault/azkeys/response_types.go b/sdk/security/keyvault/azkeys/response_types.go index 62eaefa5e3a7..d1adaed1cef1 100644 --- a/sdk/security/keyvault/azkeys/response_types.go +++ b/sdk/security/keyvault/azkeys/response_types.go @@ -16,7 +16,7 @@ type BackupKeyResponse struct { // CreateKeyResponse contains the response from method Client.CreateKey. type CreateKeyResponse struct { - KeyBundle + KeyVaultKey } // DecryptResponse contains the response from method Client.Decrypt. @@ -26,7 +26,7 @@ type DecryptResponse struct { // DeleteKeyResponse contains the response from method Client.DeleteKey. type DeleteKeyResponse struct { - DeletedKeyBundle + DeletedKey } // EncryptResponse contains the response from method Client.Encrypt. @@ -36,12 +36,12 @@ type EncryptResponse struct { // GetDeletedKeyResponse contains the response from method Client.GetDeletedKey. type GetDeletedKeyResponse struct { - DeletedKeyBundle + DeletedKey } // GetKeyResponse contains the response from method Client.GetKey. type GetKeyResponse struct { - KeyBundle + KeyVaultKey } // GetKeyRotationPolicyResponse contains the response from method Client.GetKeyRotationPolicy. @@ -56,22 +56,22 @@ type GetRandomBytesResponse struct { // ImportKeyResponse contains the response from method Client.ImportKey. type ImportKeyResponse struct { - KeyBundle + KeyVaultKey } -// ListDeletedKeysResponse contains the response from method Client.NewListDeletedKeysPager. -type ListDeletedKeysResponse struct { - DeletedKeyListResult +// ListDeletedKeyPropertiesResponse contains the response from method Client.NewListDeletedKeyPropertiesPager. +type ListDeletedKeyPropertiesResponse struct { + DeletedKeyPropertiesListResult } -// ListKeyVersionsResponse contains the response from method Client.NewListKeyVersionsPager. -type ListKeyVersionsResponse struct { - KeyListResult +// ListKeyPropertiesResponse contains the response from method Client.NewListKeyPropertiesPager. +type ListKeyPropertiesResponse struct { + KeyPropertiesListResult } -// ListKeysResponse contains the response from method Client.NewListKeysPager. -type ListKeysResponse struct { - KeyListResult +// ListKeyPropertiesVersionsResponse contains the response from method Client.NewListKeyPropertiesVersionsPager. +type ListKeyPropertiesVersionsResponse struct { + KeyPropertiesListResult } // PurgeDeletedKeyResponse contains the response from method Client.PurgeDeletedKey. @@ -81,7 +81,7 @@ type PurgeDeletedKeyResponse struct { // RecoverDeletedKeyResponse contains the response from method Client.RecoverDeletedKey. type RecoverDeletedKeyResponse struct { - KeyBundle + KeyVaultKey } // ReleaseResponse contains the response from method Client.Release. @@ -91,12 +91,12 @@ type ReleaseResponse struct { // RestoreKeyResponse contains the response from method Client.RestoreKey. type RestoreKeyResponse struct { - KeyBundle + KeyVaultKey } // RotateKeyResponse contains the response from method Client.RotateKey. type RotateKeyResponse struct { - KeyBundle + KeyVaultKey } // SignResponse contains the response from method Client.Sign. @@ -111,7 +111,7 @@ type UnwrapKeyResponse struct { // UpdateKeyResponse contains the response from method Client.UpdateKey. type UpdateKeyResponse struct { - KeyBundle + KeyVaultKey } // UpdateKeyRotationPolicyResponse contains the response from method Client.UpdateKeyRotationPolicy. From 32aa94ebe88ab92dc34714c5556764b79dd26d87 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Tue, 23 May 2023 12:36:39 -0700 Subject: [PATCH 02/10] update perf tests --- sdk/security/keyvault/azkeys/testdata/perf/get_key.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/security/keyvault/azkeys/testdata/perf/get_key.go b/sdk/security/keyvault/azkeys/testdata/perf/get_key.go index 18c1ad2654f2..0f3a97a43186 100644 --- a/sdk/security/keyvault/azkeys/testdata/perf/get_key.go +++ b/sdk/security/keyvault/azkeys/testdata/perf/get_key.go @@ -47,8 +47,11 @@ func newGetKeyTest(ctx context.Context, options perf.PerfTestOptions) (perf.Glob Transport: options.Transporter, }, }) + if err != nil { + panic(err) + } - _, err = client.CreateKey(ctx, d.keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.JSONWebKeyTypeRSA), KeySize: to.Ptr(int32(2048))}, nil) + _, err = client.CreateKey(ctx, d.keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA), KeySize: to.Ptr(int32(2048))}, nil) if err != nil { return nil, err } From d3e5847dc35e15f32129680c73bc92400c7e93c7 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Thu, 25 May 2023 12:41:02 -0700 Subject: [PATCH 03/10] Charles feedback --- sdk/security/keyvault/azkeys/testdata/perf/get_key.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/security/keyvault/azkeys/testdata/perf/get_key.go b/sdk/security/keyvault/azkeys/testdata/perf/get_key.go index 0f3a97a43186..0bf41a62be84 100644 --- a/sdk/security/keyvault/azkeys/testdata/perf/get_key.go +++ b/sdk/security/keyvault/azkeys/testdata/perf/get_key.go @@ -39,7 +39,7 @@ func newGetKeyTest(ctx context.Context, options perf.PerfTestOptions) (perf.Glob cred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { - panic(err) + return nil, err } client, err := azkeys.NewClient(vaultURL, cred, &azkeys.ClientOptions{ @@ -48,7 +48,7 @@ func newGetKeyTest(ctx context.Context, options perf.PerfTestOptions) (perf.Glob }, }) if err != nil { - panic(err) + return nil, err } _, err = client.CreateKey(ctx, d.keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA), KeySize: to.Ptr(int32(2048))}, nil) From 6eb8c22e41825a190c2df4fdd2f2361e26f93280 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Thu, 25 May 2023 12:41:27 -0700 Subject: [PATCH 04/10] charles feedback --- sdk/security/keyvault/azkeys/autorest.md | 7 +- sdk/security/keyvault/azkeys/client.go | 14 +-- sdk/security/keyvault/azkeys/client_test.go | 74 ++++++++-------- sdk/security/keyvault/azkeys/constants.go | 56 ++++++------ sdk/security/keyvault/azkeys/example_test.go | 10 +-- sdk/security/keyvault/azkeys/models.go | 44 +++++----- sdk/security/keyvault/azkeys/models_serde.go | 86 +++++++++---------- .../keyvault/azkeys/response_types.go | 14 +-- 8 files changed, 151 insertions(+), 154 deletions(-) diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index a5bbc1938202..e2c280ba44d7 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -82,7 +82,7 @@ directive: to: DeletedKey - rename-model: from: KeyBundle - to: KeyVaultKey + to: Key - rename-model: from: KeyItem to: KeyProperties @@ -133,9 +133,6 @@ directive: transform: $["x-ms-client-name"] = "version" # KeyEncryptionAlgorithm renames - - from: swagger-document - where: $.definitions.ReleaseParameters.properties.enc.x-ms-enum - transform: $["name"] = "KeyExportEncryptionAlgorithm" - from: swagger-document where: $.definitions.ReleaseParameters.properties.enc transform: $["x-ms-client-name"] = "algorithm" @@ -158,7 +155,7 @@ directive: - models.go - constants.go where: $ - transform: return $.replace(/JSONWebKeyCurveName/g, "KeyCurveName"); + transform: return $.replace(/JSONWebKeyCurveName/g, "CurveName"); - from: - models.go - constants.go diff --git a/sdk/security/keyvault/azkeys/client.go b/sdk/security/keyvault/azkeys/client.go index 5e6f6a8fda5c..7a88cec61ba0 100644 --- a/sdk/security/keyvault/azkeys/client.go +++ b/sdk/security/keyvault/azkeys/client.go @@ -132,7 +132,7 @@ func (client *Client) createKeyCreateRequest(ctx context.Context, name string, p // createKeyHandleResponse handles the CreateKey response. func (client *Client) createKeyHandleResponse(resp *http.Response) (CreateKeyResponse, error) { result := CreateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return CreateKeyResponse{}, err } return result, nil @@ -399,7 +399,7 @@ func (client *Client) getKeyCreateRequest(ctx context.Context, name string, vers // getKeyHandleResponse handles the GetKey response. func (client *Client) getKeyHandleResponse(resp *http.Response) (GetKeyResponse, error) { result := GetKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return GetKeyResponse{}, err } return result, nil @@ -544,7 +544,7 @@ func (client *Client) importKeyCreateRequest(ctx context.Context, name string, p // importKeyHandleResponse handles the ImportKey response. func (client *Client) importKeyHandleResponse(resp *http.Response) (ImportKeyResponse, error) { result := ImportKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return ImportKeyResponse{}, err } return result, nil @@ -825,7 +825,7 @@ func (client *Client) recoverDeletedKeyCreateRequest(ctx context.Context, name s // recoverDeletedKeyHandleResponse handles the RecoverDeletedKey response. func (client *Client) recoverDeletedKeyHandleResponse(resp *http.Response) (RecoverDeletedKeyResponse, error) { result := RecoverDeletedKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return RecoverDeletedKeyResponse{}, err } return result, nil @@ -929,7 +929,7 @@ func (client *Client) restoreKeyCreateRequest(ctx context.Context, parameters Re // restoreKeyHandleResponse handles the RestoreKey response. func (client *Client) restoreKeyHandleResponse(resp *http.Response) (RestoreKeyResponse, error) { result := RestoreKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return RestoreKeyResponse{}, err } return result, nil @@ -977,7 +977,7 @@ func (client *Client) rotateKeyCreateRequest(ctx context.Context, name string, o // rotateKeyHandleResponse handles the RotateKey response. func (client *Client) rotateKeyHandleResponse(resp *http.Response) (RotateKeyResponse, error) { result := RotateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return RotateKeyResponse{}, err } return result, nil @@ -1135,7 +1135,7 @@ func (client *Client) updateKeyCreateRequest(ctx context.Context, name string, v // updateKeyHandleResponse handles the UpdateKey response. func (client *Client) updateKeyHandleResponse(resp *http.Response) (UpdateKeyResponse, error) { result := UpdateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { return UpdateKeyResponse{}, err } return result, nil diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index 819d6eaa0ab1..d5da3bb87feb 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -82,8 +82,8 @@ func TestBackupRestore(t *testing.T) { keyName := createRandomName(t, "testbackuprestore") createResp, err := client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) - require.Equal(t, keyName, createResp.Key.KID.Name()) - require.NotEmpty(t, createResp.Key.KID.Version()) + require.Equal(t, keyName, createResp.Key.Key.KID.Name()) + require.NotEmpty(t, createResp.Key.Key.KID.Version()) require.NotNil(t, createResp.Attributes) require.NotNil(t, createResp.Key) @@ -93,8 +93,8 @@ func TestBackupRestore(t *testing.T) { deleteResp, err := client.DeleteKey(context.Background(), keyName, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.KID.Name(), deleteResp.Key.KID.Name()) - require.Equal(t, createResp.Key.KID.Version(), deleteResp.Key.KID.Version()) + require.Equal(t, createResp.Key.Key.KID.Name(), deleteResp.Key.KID.Name()) + require.Equal(t, createResp.Key.Key.KID.Version(), deleteResp.Key.KID.Version()) requireEqualAttributes(t, createResp.Attributes, deleteResp.Attributes) require.NotNil(t, deleteResp.Key) require.NotEmpty(t, deleteResp.RecoveryID) @@ -114,15 +114,15 @@ func TestBackupRestore(t *testing.T) { return err }) require.NoError(t, err) - defer cleanUpKey(t, client, restoreResp.Key.KID) + defer cleanUpKey(t, client, restoreResp.Key.Key.KID) require.NotNil(t, restoreResp.Key) testSerde(t, &restoreParams) getResp, err := client.GetKey(context.Background(), keyName, "", nil) require.NoError(t, err) require.Equal(t, restoreResp.Attributes, getResp.Attributes) - require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) - require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) + require.Equal(t, createResp.Key.Key.KID.Name(), getResp.Key.Key.KID.Name()) + require.Equal(t, createResp.Key.Key.KID.Version(), getResp.Key.Key.KID.Version()) }) } } @@ -137,7 +137,7 @@ func TestCRUD(t *testing.T) { for _, params := range []azkeys.CreateKeyParameters{ { Kty: to.Ptr(azkeys.KeyTypeEC), - Curve: to.Ptr(azkeys.KeyCurveNameP256K), + Curve: to.Ptr(azkeys.CurveNameP256K), KeyAttributes: attributes, Tags: tags, }, @@ -160,8 +160,8 @@ func TestCRUD(t *testing.T) { keyName := createRandomName(t, "testcrud") createResp, err := client.CreateKey(context.Background(), keyName, params, nil) require.NoError(t, err) - require.Equal(t, keyName, createResp.Key.KID.Name()) - require.NotEmpty(t, createResp.Key.KID.Version()) + require.Equal(t, keyName, createResp.Key.Key.KID.Name()) + require.NotEmpty(t, createResp.Key.Key.KID.Version()) require.NotNil(t, createResp.Attributes) require.NotNil(t, createResp.Key) require.True(t, *createResp.Attributes.Enabled) @@ -169,9 +169,9 @@ func TestCRUD(t *testing.T) { getResp, err := client.GetKey(context.Background(), keyName, "", nil) require.NoError(t, err) requireEqualAttributes(t, createResp.Attributes, getResp.Attributes) - require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) - require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) - testSerde(t, &getResp.KeyVaultKey) + require.Equal(t, createResp.Key.Key.KID.Name(), getResp.Key.Key.KID.Name()) + require.Equal(t, createResp.Key.Key.KID.Version(), getResp.Key.Key.KID.Version()) + testSerde(t, &getResp.Key) updateParams := azkeys.UpdateKeyParameters{ KeyAttributes: &azkeys.KeyAttributes{ @@ -179,16 +179,16 @@ func TestCRUD(t *testing.T) { }, } testSerde(t, &updateParams) - updateResp, err := client.UpdateKey(context.Background(), keyName, createResp.Key.KID.Version(), updateParams, nil) + updateResp, err := client.UpdateKey(context.Background(), keyName, createResp.Key.Key.KID.Version(), updateParams, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.KID.Name(), updateResp.Key.KID.Name()) - require.Equal(t, createResp.Key.KID.Version(), updateResp.Key.KID.Version()) + require.Equal(t, createResp.Key.Key.KID.Name(), updateResp.Key.Key.KID.Name()) + require.Equal(t, createResp.Key.Key.KID.Version(), updateResp.Key.Key.KID.Version()) require.False(t, *updateResp.Attributes.Enabled) deleteResp, err := client.DeleteKey(context.Background(), keyName, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.KID.Name(), deleteResp.Key.KID.Name()) - require.Equal(t, createResp.Key.KID.Version(), deleteResp.Key.KID.Version()) + require.Equal(t, createResp.Key.Key.KID.Name(), deleteResp.Key.KID.Name()) + require.Equal(t, createResp.Key.Key.KID.Version(), deleteResp.Key.KID.Version()) requireEqualAttributes(t, updateResp.Attributes, deleteResp.Attributes) testSerde(t, &deleteResp.DeletedKey) pollStatus(t, 404, func() error { @@ -276,7 +276,7 @@ func TestEncryptDecrypt(t *testing.T) { Value: []byte("plaintext"), } testSerde(t, &encryptParams) - encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.KID.Version(), encryptParams, nil) + encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.Key.KID.Version(), encryptParams, nil) require.NoError(t, err) require.NotEmpty(t, encryptResponse.Result) testSerde(t, &encryptResponse.KeyOperationResult) @@ -313,7 +313,7 @@ func TestEncryptDecryptSymmetric(t *testing.T) { Value: []byte("plaintext"), } testSerde(t, &encryptParams) - encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.KID.Version(), encryptParams, nil) + encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.Key.KID.Version(), encryptParams, nil) require.NoError(t, err) require.NotEmpty(t, encryptResponse.Result) @@ -375,10 +375,10 @@ func TestImportKey(t *testing.T) { testSerde(t, ¶ms) resp, err := client.ImportKey(context.Background(), createRandomName(t, "testimport"), params, nil) require.NoError(t, err) - defer cleanUpKey(t, client, resp.Key.KID) - require.Equal(t, jwk.KeyOperations, resp.Key.KeyOperations) - require.Equal(t, jwk.N, resp.Key.N) - require.Equal(t, jwk.E, resp.Key.E) + defer cleanUpKey(t, client, resp.Key.Key.KID) + require.Equal(t, jwk.KeyOperations, resp.Key.Key.KeyOperations) + require.Equal(t, jwk.N, resp.Key.Key.N) + require.Equal(t, jwk.E, resp.Key.Key.E) }) } } @@ -402,7 +402,7 @@ func TestListDeletedKeys(t *testing.T) { keyNames[i] = n createResp, err := client.CreateKey(context.Background(), n, createParams, nil) require.NoError(t, err) - cleanUpKey(t, client, createResp.Key.KID) + cleanUpKey(t, client, createResp.Key.Key.KID) } for i := 0; i < len(keyNames); i++ { pollStatus(t, 404, func() error { @@ -449,7 +449,7 @@ func TestListKeys(t *testing.T) { n := createRandomName(t, fmt.Sprintf("%s-%d", keyNamePrefix, i)) resp, err := client.CreateKey(context.Background(), n, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) - defer cleanUpKey(t, client, resp.Key.KID) + defer cleanUpKey(t, client, resp.Key.Key.KID) count++ } @@ -488,10 +488,10 @@ func TestListKeyVersions(t *testing.T) { expectedVersions := make(map[string]struct{}, 4) for i := 0; i < 4; i++ { createResp, err = client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) - expectedVersions[createResp.Key.KID.Version()] = struct{}{} + expectedVersions[createResp.Key.Key.KID.Version()] = struct{}{} require.NoError(t, err) } - defer cleanUpKey(t, client, createResp.Key.KID) + defer cleanUpKey(t, client, createResp.Key.Key.KID) pager := client.NewListKeyPropertiesVersionsPager(keyName, &azkeys.ListKeyPropertiesVersionsOptions{MaxResults: to.Ptr(int32(1))}) for pager.More() { @@ -538,11 +538,11 @@ func TestRecoverDeletedKey(t *testing.T) { recoverResp, err := client.RecoverDeletedKey(context.Background(), key, nil) require.NoError(t, err) pollStatus(t, 404, func() error { - _, err := client.GetKey(context.Background(), key, createResp.Key.KID.Version(), nil) + _, err := client.GetKey(context.Background(), key, createResp.Key.Key.KID.Version(), nil) return err }) - cleanUpKey(t, client, createResp.Key.KID) - require.Equal(t, createResp.Key.KID, recoverResp.Key.KID) + cleanUpKey(t, client, createResp.Key.Key.KID) + require.Equal(t, createResp.Key.Key.KID, recoverResp.Key.Key.KID) require.NotNil(t, recoverResp.Attributes) }) } @@ -564,7 +564,7 @@ func TestReleaseKey(t *testing.T) { var err error for i := 0; i < 5; i++ { params := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.KeyCurveNameP256K), + Curve: to.Ptr(azkeys.CurveNameP256K), KeyAttributes: &azkeys.KeyAttributes{ Exportable: to.Ptr(true), }, @@ -583,8 +583,8 @@ func TestReleaseKey(t *testing.T) { } } require.NoError(t, err) - require.NotNil(t, createResp.Key.KID) - defer cleanUpKey(t, client, createResp.Key.KID) + require.NotNil(t, createResp.Key.Key.KID) + defer cleanUpKey(t, client, createResp.Key.Key.KID) attestationClient, err := recording.NewRecordingHTTPClient(t, nil) require.NoError(t, err) @@ -625,7 +625,7 @@ func TestRotateKey(t *testing.T) { key := createRandomName(t, "testrotatekey") createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeECHSM)}, nil) require.NoError(t, err) - defer cleanUpKey(t, client, createResp.Key.KID) + defer cleanUpKey(t, client, createResp.Key.Key.KID) timeAfterCreate := to.Ptr("P30D") policy := azkeys.KeyRotationPolicy{ @@ -662,7 +662,7 @@ func TestRotateKey(t *testing.T) { rotateResp, err := client.RotateKey(context.Background(), key, nil) require.NoError(t, err) - require.NotNil(t, rotateResp.Key.KID) + require.NotNil(t, rotateResp.Key.Key.KID) invalid, err := client.RotateKey(context.Background(), "keynonexistent", nil) require.Error(t, err) @@ -683,7 +683,7 @@ func TestSignVerify(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.KeyCurveNameP256K), + Curve: to.Ptr(azkeys.CurveNameP256K), KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationSign, azkeys.KeyOperationVerify), Kty: to.Ptr(azkeys.KeyTypeEC), } diff --git a/sdk/security/keyvault/azkeys/constants.go b/sdk/security/keyvault/azkeys/constants.go index 94985790745d..4bf3199df302 100644 --- a/sdk/security/keyvault/azkeys/constants.go +++ b/sdk/security/keyvault/azkeys/constants.go @@ -9,27 +9,27 @@ package azkeys -// KeyCurveName - Elliptic curve name. For valid values, see JsonWebKeyCurveName. -type KeyCurveName string +// CurveName - Elliptic curve name. For valid values, see JsonWebKeyCurveName. +type CurveName string const ( - // KeyCurveNameP256 - The NIST P-256 elliptic curve, AKA SECG curve SECP256R1. - KeyCurveNameP256 KeyCurveName = "P-256" - // KeyCurveNameP256K - The SECG SECP256K1 elliptic curve. - KeyCurveNameP256K KeyCurveName = "P-256K" - // KeyCurveNameP384 - The NIST P-384 elliptic curve, AKA SECG curve SECP384R1. - KeyCurveNameP384 KeyCurveName = "P-384" - // KeyCurveNameP521 - The NIST P-521 elliptic curve, AKA SECG curve SECP521R1. - KeyCurveNameP521 KeyCurveName = "P-521" + // CurveNameP256 - The NIST P-256 elliptic curve, AKA SECG curve SECP256R1. + CurveNameP256 CurveName = "P-256" + // CurveNameP256K - The SECG SECP256K1 elliptic curve. + CurveNameP256K CurveName = "P-256K" + // CurveNameP384 - The NIST P-384 elliptic curve, AKA SECG curve SECP384R1. + CurveNameP384 CurveName = "P-384" + // CurveNameP521 - The NIST P-521 elliptic curve, AKA SECG curve SECP521R1. + CurveNameP521 CurveName = "P-521" ) -// PossibleKeyCurveNameValues returns the possible values for the KeyCurveName const type. -func PossibleKeyCurveNameValues() []KeyCurveName { - return []KeyCurveName{ - KeyCurveNameP256, - KeyCurveNameP256K, - KeyCurveNameP384, - KeyCurveNameP521, +// PossibleCurveNameValues returns the possible values for the CurveName const type. +func PossibleCurveNameValues() []CurveName { + return []CurveName{ + CurveNameP256, + CurveNameP256K, + CurveNameP384, + CurveNameP521, } } @@ -179,21 +179,21 @@ func PossibleKeyTypeValues() []KeyType { } } -// KeyExportEncryptionAlgorithm - The encryption algorithm to use to protected the exported key material -type KeyExportEncryptionAlgorithm string +// KeyEncryptionAlgorithm - The encryption algorithm to use to protected the exported key material +type KeyEncryptionAlgorithm string const ( - KeyExportEncryptionAlgorithmCKMRSAAESKEYWRAP KeyExportEncryptionAlgorithm = "CKM_RSA_AES_KEY_WRAP" - KeyExportEncryptionAlgorithmRSAAESKEYWRAP256 KeyExportEncryptionAlgorithm = "RSA_AES_KEY_WRAP_256" - KeyExportEncryptionAlgorithmRSAAESKEYWRAP384 KeyExportEncryptionAlgorithm = "RSA_AES_KEY_WRAP_384" + KeyEncryptionAlgorithmCKMRSAAESKEYWRAP KeyEncryptionAlgorithm = "CKM_RSA_AES_KEY_WRAP" + KeyEncryptionAlgorithmRSAAESKEYWRAP256 KeyEncryptionAlgorithm = "RSA_AES_KEY_WRAP_256" + KeyEncryptionAlgorithmRSAAESKEYWRAP384 KeyEncryptionAlgorithm = "RSA_AES_KEY_WRAP_384" ) -// PossibleKeyExportEncryptionAlgorithmValues returns the possible values for the KeyExportEncryptionAlgorithm const type. -func PossibleKeyExportEncryptionAlgorithmValues() []KeyExportEncryptionAlgorithm { - return []KeyExportEncryptionAlgorithm{ - KeyExportEncryptionAlgorithmCKMRSAAESKEYWRAP, - KeyExportEncryptionAlgorithmRSAAESKEYWRAP256, - KeyExportEncryptionAlgorithmRSAAESKEYWRAP384, +// PossibleKeyEncryptionAlgorithmValues returns the possible values for the KeyEncryptionAlgorithm const type. +func PossibleKeyEncryptionAlgorithmValues() []KeyEncryptionAlgorithm { + return []KeyEncryptionAlgorithm{ + KeyEncryptionAlgorithmCKMRSAAESKEYWRAP, + KeyEncryptionAlgorithmRSAAESKEYWRAP256, + KeyEncryptionAlgorithmRSAAESKEYWRAP384, } } diff --git a/sdk/security/keyvault/azkeys/example_test.go b/sdk/security/keyvault/azkeys/example_test.go index f627e9634854..38f898ab8562 100644 --- a/sdk/security/keyvault/azkeys/example_test.go +++ b/sdk/security/keyvault/azkeys/example_test.go @@ -43,12 +43,12 @@ func ExampleClient_CreateKey_rsa() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.KID) + fmt.Println(*resp.Key.Key.KID) } func ExampleClient_CreateKey_ec() { params := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.KeyCurveNameP256K), + Curve: to.Ptr(azkeys.CurveNameP256K), Kty: to.Ptr(azkeys.KeyTypeEC), } // if a key with the same name already exists, a new version of that key is created @@ -56,7 +56,7 @@ func ExampleClient_CreateKey_ec() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.KID) + fmt.Println(*resp.Key.Key.KID) } func ExampleClient_DeleteKey() { @@ -95,7 +95,7 @@ func ExampleClient_GetKey() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.KID) + fmt.Println(*resp.Key.Key.KID) } // UpdateKey updates the properties of a key previously stored in the key vault @@ -112,7 +112,7 @@ func ExampleClient_UpdateKey() { if err != nil { // TODO: handle error } - fmt.Printf("Enabled key %s", *updateResp.Key.KID) + fmt.Printf("Enabled key %s", *updateResp.Key.Key.KID) } // UpdateKeyRotationPolicy allows you to configure automatic key rotation for a key by specifying a rotation policy, and diff --git a/sdk/security/keyvault/azkeys/models.go b/sdk/security/keyvault/azkeys/models.go index 08fb5418445c..3fce25dcfe3d 100644 --- a/sdk/security/keyvault/azkeys/models.go +++ b/sdk/security/keyvault/azkeys/models.go @@ -148,7 +148,7 @@ type CreateKeyParameters struct { Kty *KeyType `json:"kty,omitempty"` // Elliptic curve name. For valid values, see JsonWebKeyCurveName. - Curve *KeyCurveName `json:"crv,omitempty"` + Curve *CurveName `json:"crv,omitempty"` // The attributes of a key managed by the key vault service. KeyAttributes *KeyAttributes `json:"attributes,omitempty"` @@ -257,7 +257,7 @@ type ImportKeyParameters struct { // JSONWebKey - As of http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18 type JSONWebKey struct { // Elliptic curve name. For valid values, see JsonWebKeyCurveName. - Crv *KeyCurveName `json:"crv,omitempty"` + Crv *CurveName `json:"crv,omitempty"` // RSA private exponent, or the D component of an EC private key. D []byte `json:"d,omitempty"` @@ -303,6 +303,25 @@ type JSONWebKey struct { Y []byte `json:"y,omitempty"` } +// Key - A KeyBundle consisting of a WebKey plus its attributes. +type Key struct { + // The key management attributes. + Attributes *KeyAttributes `json:"attributes,omitempty"` + + // The Json web key. + Key *JSONWebKey `json:"key,omitempty"` + + // The policy rules under which the key can be exported. + ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` + + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will + // be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` +} + // KeyAttributes - The attributes of a key managed by the key vault service. type KeyAttributes struct { // Determines whether the object is enabled. @@ -465,25 +484,6 @@ type KeyRotationPolicyAttributes struct { Updated *time.Time `json:"updated,omitempty" azure:"ro"` } -// KeyVaultKey - A KeyBundle consisting of a WebKey plus its attributes. -type KeyVaultKey struct { - // The key management attributes. - Attributes *KeyAttributes `json:"attributes,omitempty"` - - // The Json web key. - Key *JSONWebKey `json:"key,omitempty"` - - // The policy rules under which the key can be exported. - ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` - - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags,omitempty"` - - // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will - // be true. - Managed *bool `json:"managed,omitempty" azure:"ro"` -} - // KeyVerifyResult - The key verify result. type KeyVerifyResult struct { // READ-ONLY; True if the signature is verified, otherwise false. @@ -502,7 +502,7 @@ type ReleaseParameters struct { TargetAttestationToken *string `json:"target,omitempty"` // The encryption algorithm to use to protected the exported key material - Algorithm *KeyExportEncryptionAlgorithm `json:"enc,omitempty"` + Algorithm *KeyEncryptionAlgorithm `json:"enc,omitempty"` // A client provided nonce for freshness. Nonce *string `json:"nonce,omitempty"` diff --git a/sdk/security/keyvault/azkeys/models_serde.go b/sdk/security/keyvault/azkeys/models_serde.go index aef453d77457..086bed5fbbde 100644 --- a/sdk/security/keyvault/azkeys/models_serde.go +++ b/sdk/security/keyvault/azkeys/models_serde.go @@ -393,6 +393,49 @@ func (j *JSONWebKey) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type Key. +func (k Key) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "attributes", k.Attributes) + populate(objectMap, "key", k.Key) + populate(objectMap, "managed", k.Managed) + populate(objectMap, "release_policy", k.ReleasePolicy) + populate(objectMap, "tags", k.Tags) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Key. +func (k *Key) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "attributes": + err = unpopulate(val, "Attributes", &k.Attributes) + delete(rawMsg, key) + case "key": + err = unpopulate(val, "Key", &k.Key) + delete(rawMsg, key) + case "managed": + err = unpopulate(val, "Managed", &k.Managed) + delete(rawMsg, key) + case "release_policy": + err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &k.Tags) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type KeyAttributes. func (k KeyAttributes) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -825,49 +868,6 @@ func (k *KeyRotationPolicyAttributes) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyVaultKey. -func (k KeyVaultKey) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "attributes", k.Attributes) - populate(objectMap, "key", k.Key) - populate(objectMap, "managed", k.Managed) - populate(objectMap, "release_policy", k.ReleasePolicy) - populate(objectMap, "tags", k.Tags) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVaultKey. -func (k *KeyVaultKey) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "attributes": - err = unpopulate(val, "Attributes", &k.Attributes) - delete(rawMsg, key) - case "key": - err = unpopulate(val, "Key", &k.Key) - delete(rawMsg, key) - case "managed": - err = unpopulate(val, "Managed", &k.Managed) - delete(rawMsg, key) - case "release_policy": - err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) - delete(rawMsg, key) - case "tags": - err = unpopulate(val, "Tags", &k.Tags) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) diff --git a/sdk/security/keyvault/azkeys/response_types.go b/sdk/security/keyvault/azkeys/response_types.go index d1adaed1cef1..6802ff0421aa 100644 --- a/sdk/security/keyvault/azkeys/response_types.go +++ b/sdk/security/keyvault/azkeys/response_types.go @@ -16,7 +16,7 @@ type BackupKeyResponse struct { // CreateKeyResponse contains the response from method Client.CreateKey. type CreateKeyResponse struct { - KeyVaultKey + Key } // DecryptResponse contains the response from method Client.Decrypt. @@ -41,7 +41,7 @@ type GetDeletedKeyResponse struct { // GetKeyResponse contains the response from method Client.GetKey. type GetKeyResponse struct { - KeyVaultKey + Key } // GetKeyRotationPolicyResponse contains the response from method Client.GetKeyRotationPolicy. @@ -56,7 +56,7 @@ type GetRandomBytesResponse struct { // ImportKeyResponse contains the response from method Client.ImportKey. type ImportKeyResponse struct { - KeyVaultKey + Key } // ListDeletedKeyPropertiesResponse contains the response from method Client.NewListDeletedKeyPropertiesPager. @@ -81,7 +81,7 @@ type PurgeDeletedKeyResponse struct { // RecoverDeletedKeyResponse contains the response from method Client.RecoverDeletedKey. type RecoverDeletedKeyResponse struct { - KeyVaultKey + Key } // ReleaseResponse contains the response from method Client.Release. @@ -91,12 +91,12 @@ type ReleaseResponse struct { // RestoreKeyResponse contains the response from method Client.RestoreKey. type RestoreKeyResponse struct { - KeyVaultKey + Key } // RotateKeyResponse contains the response from method Client.RotateKey. type RotateKeyResponse struct { - KeyVaultKey + Key } // SignResponse contains the response from method Client.Sign. @@ -111,7 +111,7 @@ type UnwrapKeyResponse struct { // UpdateKeyResponse contains the response from method Client.UpdateKey. type UpdateKeyResponse struct { - KeyVaultKey + Key } // UpdateKeyRotationPolicyResponse contains the response from method Client.UpdateKeyRotationPolicy. From 0e05cc2d063c7fc94a25a44f66627b37e816394e Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Tue, 30 May 2023 10:26:56 -0700 Subject: [PATCH 05/10] feedback --- sdk/security/keyvault/azkeys/CHANGELOG.md | 7 +- sdk/security/keyvault/azkeys/autorest.md | 20 +- sdk/security/keyvault/azkeys/client.go | 14 +- sdk/security/keyvault/azkeys/client_test.go | 114 ++++----- sdk/security/keyvault/azkeys/example_test.go | 14 +- sdk/security/keyvault/azkeys/models.go | 98 ++++---- sdk/security/keyvault/azkeys/models_serde.go | 230 +++++++++--------- .../keyvault/azkeys/response_types.go | 14 +- 8 files changed, 249 insertions(+), 262 deletions(-) diff --git a/sdk/security/keyvault/azkeys/CHANGELOG.md b/sdk/security/keyvault/azkeys/CHANGELOG.md index be9c3dcee1f8..2ec2e9977fb2 100644 --- a/sdk/security/keyvault/azkeys/CHANGELOG.md +++ b/sdk/security/keyvault/azkeys/CHANGELOG.md @@ -3,6 +3,9 @@ ## 1.0.0 (unreleased) ### Breaking Changes + +*Breaking Changes from last preview. Going forward, the module is now stable and will not have breaking api changes.* + * Renamed `GetRandomBytesRequest` to `GetRandomBytesParameters` * `ListDeletedKey` to `ListDeletedKeyProperties` * `ListKeys` to `ListKeyProperties` @@ -14,11 +17,9 @@ * `DeletedKeyListResult` to `DeletedKeyPropertiesListResult` * `KeyListResult` `KeyPropertiesListResult` * `KeyOperationsParameters` to `KeyOperationParameters` -* `KeyOps` field to `KeyOperations` * Changed `JSONWebKey.KeyOperations` from type []*string to []*KeyOperation -* `KeyEncryptionAlgorithm` to `KeyExportEncryptionAlgorithm` * `ReleaseParameters.Enc` to `ReleaseParameters.Algorithm` -* `KeyOperationParameters.AAD` to `KeyOperationParameters.AdditionalAuthenticationData` +* `KeyOperationParameters.AAD` to `KeyOperationParameters.AdditionalAuthenticatedData` * `KeyOperationParameters.Tag` to `KeyOperationParameters.AuthenticationTag` * `JSONWebKeyOperation` to `KeyOperation` * `JSONWebKeyCurveName` to `KeyCurveName` diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index e2c280ba44d7..8aedb10f1474 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -65,24 +65,13 @@ directive: from: GetKeyVersions to: ListKeyPropertiesVersions - # add in KeyRotation prefix - - rename-model: - from: LifetimeActions - to: KeyRotationLifetimeActions - - rename-model: - from: LifetimeActionsTrigger - to: KeyRotationLifetimeActionsTrigger - - rename-model: - from: LifetimeActionsType - to: KeyRotationLifetimeActionsType - # rename KeyItem and KeyBundle - rename-model: from: DeletedKeyBundle to: DeletedKey - rename-model: from: KeyBundle - to: Key + to: KeyVaultKey - rename-model: from: KeyItem to: KeyProperties @@ -99,16 +88,13 @@ directive: where: $.definitions.RestoreKeyParameters.properties.value transform: $["x-ms-client-name"] = "KeyBackup" - # Rename KeyOps to KeyOperations and update type + # KeyOps updates - rename-model: from: KeyOperationsParameters to: KeyOperationParameters - - from: swagger-document - where: $.definitions..properties.key_ops - transform: $["x-ms-client-name"] = "KeyOperations" - from: models.go where: $ - transform: return $.replace(/KeyOperations \[\]\*string/, "KeyOperations []*KeyOperation"); + transform: return $.replace(/KeyOps \[\]\*string/, "KeyOps []*KeyOperation"); # fix capitalization - from: swagger-document diff --git a/sdk/security/keyvault/azkeys/client.go b/sdk/security/keyvault/azkeys/client.go index 7a88cec61ba0..5e6f6a8fda5c 100644 --- a/sdk/security/keyvault/azkeys/client.go +++ b/sdk/security/keyvault/azkeys/client.go @@ -132,7 +132,7 @@ func (client *Client) createKeyCreateRequest(ctx context.Context, name string, p // createKeyHandleResponse handles the CreateKey response. func (client *Client) createKeyHandleResponse(resp *http.Response) (CreateKeyResponse, error) { result := CreateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return CreateKeyResponse{}, err } return result, nil @@ -399,7 +399,7 @@ func (client *Client) getKeyCreateRequest(ctx context.Context, name string, vers // getKeyHandleResponse handles the GetKey response. func (client *Client) getKeyHandleResponse(resp *http.Response) (GetKeyResponse, error) { result := GetKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return GetKeyResponse{}, err } return result, nil @@ -544,7 +544,7 @@ func (client *Client) importKeyCreateRequest(ctx context.Context, name string, p // importKeyHandleResponse handles the ImportKey response. func (client *Client) importKeyHandleResponse(resp *http.Response) (ImportKeyResponse, error) { result := ImportKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return ImportKeyResponse{}, err } return result, nil @@ -825,7 +825,7 @@ func (client *Client) recoverDeletedKeyCreateRequest(ctx context.Context, name s // recoverDeletedKeyHandleResponse handles the RecoverDeletedKey response. func (client *Client) recoverDeletedKeyHandleResponse(resp *http.Response) (RecoverDeletedKeyResponse, error) { result := RecoverDeletedKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RecoverDeletedKeyResponse{}, err } return result, nil @@ -929,7 +929,7 @@ func (client *Client) restoreKeyCreateRequest(ctx context.Context, parameters Re // restoreKeyHandleResponse handles the RestoreKey response. func (client *Client) restoreKeyHandleResponse(resp *http.Response) (RestoreKeyResponse, error) { result := RestoreKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RestoreKeyResponse{}, err } return result, nil @@ -977,7 +977,7 @@ func (client *Client) rotateKeyCreateRequest(ctx context.Context, name string, o // rotateKeyHandleResponse handles the RotateKey response. func (client *Client) rotateKeyHandleResponse(resp *http.Response) (RotateKeyResponse, error) { result := RotateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return RotateKeyResponse{}, err } return result, nil @@ -1135,7 +1135,7 @@ func (client *Client) updateKeyCreateRequest(ctx context.Context, name string, v // updateKeyHandleResponse handles the UpdateKey response. func (client *Client) updateKeyHandleResponse(resp *http.Response) (UpdateKeyResponse, error) { result := UpdateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.Key); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { return UpdateKeyResponse{}, err } return result, nil diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index d5da3bb87feb..c756bd818c34 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -82,8 +82,8 @@ func TestBackupRestore(t *testing.T) { keyName := createRandomName(t, "testbackuprestore") createResp, err := client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) - require.Equal(t, keyName, createResp.Key.Key.KID.Name()) - require.NotEmpty(t, createResp.Key.Key.KID.Version()) + require.Equal(t, keyName, createResp.Key.KID.Name()) + require.NotEmpty(t, createResp.Key.KID.Version()) require.NotNil(t, createResp.Attributes) require.NotNil(t, createResp.Key) @@ -93,8 +93,8 @@ func TestBackupRestore(t *testing.T) { deleteResp, err := client.DeleteKey(context.Background(), keyName, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.Key.KID.Name(), deleteResp.Key.KID.Name()) - require.Equal(t, createResp.Key.Key.KID.Version(), deleteResp.Key.KID.Version()) + require.Equal(t, createResp.Key.KID.Name(), deleteResp.Key.KID.Name()) + require.Equal(t, createResp.Key.KID.Version(), deleteResp.Key.KID.Version()) requireEqualAttributes(t, createResp.Attributes, deleteResp.Attributes) require.NotNil(t, deleteResp.Key) require.NotEmpty(t, deleteResp.RecoveryID) @@ -114,15 +114,15 @@ func TestBackupRestore(t *testing.T) { return err }) require.NoError(t, err) - defer cleanUpKey(t, client, restoreResp.Key.Key.KID) + defer cleanUpKey(t, client, restoreResp.Key.KID) require.NotNil(t, restoreResp.Key) testSerde(t, &restoreParams) getResp, err := client.GetKey(context.Background(), keyName, "", nil) require.NoError(t, err) require.Equal(t, restoreResp.Attributes, getResp.Attributes) - require.Equal(t, createResp.Key.Key.KID.Name(), getResp.Key.Key.KID.Name()) - require.Equal(t, createResp.Key.Key.KID.Version(), getResp.Key.Key.KID.Version()) + require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) + require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) }) } } @@ -160,8 +160,8 @@ func TestCRUD(t *testing.T) { keyName := createRandomName(t, "testcrud") createResp, err := client.CreateKey(context.Background(), keyName, params, nil) require.NoError(t, err) - require.Equal(t, keyName, createResp.Key.Key.KID.Name()) - require.NotEmpty(t, createResp.Key.Key.KID.Version()) + require.Equal(t, keyName, createResp.Key.KID.Name()) + require.NotEmpty(t, createResp.Key.KID.Version()) require.NotNil(t, createResp.Attributes) require.NotNil(t, createResp.Key) require.True(t, *createResp.Attributes.Enabled) @@ -169,9 +169,9 @@ func TestCRUD(t *testing.T) { getResp, err := client.GetKey(context.Background(), keyName, "", nil) require.NoError(t, err) requireEqualAttributes(t, createResp.Attributes, getResp.Attributes) - require.Equal(t, createResp.Key.Key.KID.Name(), getResp.Key.Key.KID.Name()) - require.Equal(t, createResp.Key.Key.KID.Version(), getResp.Key.Key.KID.Version()) - testSerde(t, &getResp.Key) + require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) + require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) + testSerde(t, &getResp.KeyVaultKey) updateParams := azkeys.UpdateKeyParameters{ KeyAttributes: &azkeys.KeyAttributes{ @@ -179,16 +179,16 @@ func TestCRUD(t *testing.T) { }, } testSerde(t, &updateParams) - updateResp, err := client.UpdateKey(context.Background(), keyName, createResp.Key.Key.KID.Version(), updateParams, nil) + updateResp, err := client.UpdateKey(context.Background(), keyName, createResp.Key.KID.Version(), updateParams, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.Key.KID.Name(), updateResp.Key.Key.KID.Name()) - require.Equal(t, createResp.Key.Key.KID.Version(), updateResp.Key.Key.KID.Version()) + require.Equal(t, createResp.Key.KID.Name(), updateResp.Key.KID.Name()) + require.Equal(t, createResp.Key.KID.Version(), updateResp.Key.KID.Version()) require.False(t, *updateResp.Attributes.Enabled) deleteResp, err := client.DeleteKey(context.Background(), keyName, nil) require.NoError(t, err) - require.Equal(t, createResp.Key.Key.KID.Name(), deleteResp.Key.KID.Name()) - require.Equal(t, createResp.Key.Key.KID.Version(), deleteResp.Key.KID.Version()) + require.Equal(t, createResp.Key.KID.Name(), deleteResp.Key.KID.Name()) + require.Equal(t, createResp.Key.KID.Version(), deleteResp.Key.KID.Version()) requireEqualAttributes(t, updateResp.Attributes, deleteResp.Attributes) testSerde(t, &deleteResp.DeletedKey) pollStatus(t, 404, func() error { @@ -265,8 +265,8 @@ func TestEncryptDecrypt(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Kty: to.Ptr(azkeys.KeyTypeRSAHSM), - KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), + Kty: to.Ptr(azkeys.KeyTypeRSAHSM), + KeyOps: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), } createResp, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) @@ -276,7 +276,7 @@ func TestEncryptDecrypt(t *testing.T) { Value: []byte("plaintext"), } testSerde(t, &encryptParams) - encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.Key.KID.Version(), encryptParams, nil) + encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.KID.Version(), encryptParams, nil) require.NoError(t, err) require.NotEmpty(t, encryptResponse.Result) testSerde(t, &encryptResponse.KeyOperationResult) @@ -299,9 +299,9 @@ func TestEncryptDecryptSymmetric(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Kty: to.Ptr(azkeys.KeyTypeOct), - KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), - KeySize: to.Ptr(int32(256)), + Kty: to.Ptr(azkeys.KeyTypeOct), + KeyOps: to.SliceOfPtrs(azkeys.KeyOperationEncrypt, azkeys.KeyOperationDecrypt), + KeySize: to.Ptr(int32(256)), } createResp, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) @@ -313,7 +313,7 @@ func TestEncryptDecryptSymmetric(t *testing.T) { Value: []byte("plaintext"), } testSerde(t, &encryptParams) - encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.Key.KID.Version(), encryptParams, nil) + encryptResponse, err := client.Encrypt(context.Background(), keyName, createResp.Key.KID.Version(), encryptParams, nil) require.NoError(t, err) require.NotEmpty(t, encryptResponse.Result) @@ -360,25 +360,25 @@ func TestImportKey(t *testing.T) { t.Run(name, func(t *testing.T) { client := startTest(t, mhsm) jwk := &azkeys.JSONWebKey{ - KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationEncrypt), - Kty: to.Ptr(azkeys.KeyTypeRSA), - N: toBytes("a0914d00234ac683b21b4c15d5bed887bdc959c2e57af54ae734e8f00720d775d275e455207e3784ceeb60a50a4655dd72a7a94d271e8ee8f7959a669ca6e775bf0e23badae991b4529d978528b4bd90521d32dd2656796ba82b6bbfc7668c8f5eeb5053747fd199319d29a8440d08f4412d527ff9311eda71825920b47b1c46b11ab3e91d7316407e89c7f340f7b85a34042ce51743b27d4718403d34c7b438af6181be05e4d11eb985d38253d7fe9bf53fc2f1b002d22d2d793fa79a504b6ab42d0492804d7071d727a06cf3a8893aa542b1503f832b296371b6707d4dc6e372f8fe67d8ded1c908fde45ce03bc086a71487fa75e43aa0e0679aa0d20efe35", t), - E: toBytes("10001", t), - D: toBytes("627c7d24668148fe2252c7fa649ea8a5a9ed44d75c766cda42b29b660e99404f0e862d4561a6c95af6a83d213e0a2244b03cd28576473215073785fb067f015da19084ade9f475e08b040a9a2c7ba00253bb8125508c9df140b75161d266be347a5e0f6900fe1d8bbf78ccc25eeb37e0c9d188d6e1fc15169ba4fe12276193d77790d2326928bd60d0d01d6ead8d6ac4861abadceec95358fd6689c50a1671a4a936d2376440a41445501da4e74bfb98f823bd19c45b94eb01d98fc0d2f284507f018ebd929b8180dbe6381fdd434bffb7800aaabdd973d55f9eaf9bb88a6ea7b28c2a80231e72de1ad244826d665582c2362761019de2e9f10cb8bcc2625649", t), - P: toBytes("00d1deac8d68ddd2c1fd52d5999655b2cf1565260de5269e43fd2a85f39280e1708ffff0682166cb6106ee5ea5e9ffd9f98d0becc9ff2cda2febc97259215ad84b9051e563e14a051dce438bc6541a24ac4f014cf9732d36ebfc1e61a00d82cbe412090f7793cfbd4b7605be133dfc3991f7e1bed5786f337de5036fc1e2df4cf3", t), - Q: toBytes("00c3dc66b641a9b73cd833bc439cd34fc6574465ab5b7e8a92d32595a224d56d911e74624225b48c15a670282a51c40d1dad4bc2e9a3c8dab0c76f10052dfb053bc6ed42c65288a8e8bace7a8881184323f94d7db17ea6dfba651218f931a93b8f738f3d8fd3f6ba218d35b96861a0f584b0ab88ddcf446b9815f4d287d83a3237", t), - DP: toBytes("00c9a159be7265cbbabc9afcc4967eb74fe58a4c4945431902d1142da599b760e03838f8cbd26b64324fea6bdc9338503f459793636e59b5361d1e6951e08ddb089e1b507be952a81fbeaf7e76890ea4f536e25505c3f648b1e88377dfc19b4c304e738dfca07211b792286a392a704d0f444c0a802539110b7f1f121c00cff0a9", t), - DQ: toBytes("00a0bd4c0a3d9f64436a082374b5caf2488bac1568696153a6a5e4cd85d186db31e2f58f024c617d29f37b4e6b54c97a1e25efec59c4d1fd3061ac33509ce8cae5c11f4cd2e83f41a8264f785e78dc0996076ee23dfdfc43d67c463afaa0180c4a718357f9a6f270d542479a0f213870e661fb950abca4a14ca290570ba7983347", t), - QI: toBytes("009fe7ae42e92bc04fcd5780464bd21d0c8ac0c599f9af020fde6ab0a7e7d1d39902f5d8fb6c614184c4c1b103fb46e94cd10a6c8a40f9991a1f28269f326435b6c50276fda6493353c650a833f724d80c7d522ba16c79f0eb61f672736b68fb8be3243d10943c4ab7028d09e76cfb5892222e38bc4d35585bf35a88cd68c73b07", t), + KeyOps: to.SliceOfPtrs(azkeys.KeyOperationEncrypt), + Kty: to.Ptr(azkeys.KeyTypeRSA), + N: toBytes("a0914d00234ac683b21b4c15d5bed887bdc959c2e57af54ae734e8f00720d775d275e455207e3784ceeb60a50a4655dd72a7a94d271e8ee8f7959a669ca6e775bf0e23badae991b4529d978528b4bd90521d32dd2656796ba82b6bbfc7668c8f5eeb5053747fd199319d29a8440d08f4412d527ff9311eda71825920b47b1c46b11ab3e91d7316407e89c7f340f7b85a34042ce51743b27d4718403d34c7b438af6181be05e4d11eb985d38253d7fe9bf53fc2f1b002d22d2d793fa79a504b6ab42d0492804d7071d727a06cf3a8893aa542b1503f832b296371b6707d4dc6e372f8fe67d8ded1c908fde45ce03bc086a71487fa75e43aa0e0679aa0d20efe35", t), + E: toBytes("10001", t), + D: toBytes("627c7d24668148fe2252c7fa649ea8a5a9ed44d75c766cda42b29b660e99404f0e862d4561a6c95af6a83d213e0a2244b03cd28576473215073785fb067f015da19084ade9f475e08b040a9a2c7ba00253bb8125508c9df140b75161d266be347a5e0f6900fe1d8bbf78ccc25eeb37e0c9d188d6e1fc15169ba4fe12276193d77790d2326928bd60d0d01d6ead8d6ac4861abadceec95358fd6689c50a1671a4a936d2376440a41445501da4e74bfb98f823bd19c45b94eb01d98fc0d2f284507f018ebd929b8180dbe6381fdd434bffb7800aaabdd973d55f9eaf9bb88a6ea7b28c2a80231e72de1ad244826d665582c2362761019de2e9f10cb8bcc2625649", t), + P: toBytes("00d1deac8d68ddd2c1fd52d5999655b2cf1565260de5269e43fd2a85f39280e1708ffff0682166cb6106ee5ea5e9ffd9f98d0becc9ff2cda2febc97259215ad84b9051e563e14a051dce438bc6541a24ac4f014cf9732d36ebfc1e61a00d82cbe412090f7793cfbd4b7605be133dfc3991f7e1bed5786f337de5036fc1e2df4cf3", t), + Q: toBytes("00c3dc66b641a9b73cd833bc439cd34fc6574465ab5b7e8a92d32595a224d56d911e74624225b48c15a670282a51c40d1dad4bc2e9a3c8dab0c76f10052dfb053bc6ed42c65288a8e8bace7a8881184323f94d7db17ea6dfba651218f931a93b8f738f3d8fd3f6ba218d35b96861a0f584b0ab88ddcf446b9815f4d287d83a3237", t), + DP: toBytes("00c9a159be7265cbbabc9afcc4967eb74fe58a4c4945431902d1142da599b760e03838f8cbd26b64324fea6bdc9338503f459793636e59b5361d1e6951e08ddb089e1b507be952a81fbeaf7e76890ea4f536e25505c3f648b1e88377dfc19b4c304e738dfca07211b792286a392a704d0f444c0a802539110b7f1f121c00cff0a9", t), + DQ: toBytes("00a0bd4c0a3d9f64436a082374b5caf2488bac1568696153a6a5e4cd85d186db31e2f58f024c617d29f37b4e6b54c97a1e25efec59c4d1fd3061ac33509ce8cae5c11f4cd2e83f41a8264f785e78dc0996076ee23dfdfc43d67c463afaa0180c4a718357f9a6f270d542479a0f213870e661fb950abca4a14ca290570ba7983347", t), + QI: toBytes("009fe7ae42e92bc04fcd5780464bd21d0c8ac0c599f9af020fde6ab0a7e7d1d39902f5d8fb6c614184c4c1b103fb46e94cd10a6c8a40f9991a1f28269f326435b6c50276fda6493353c650a833f724d80c7d522ba16c79f0eb61f672736b68fb8be3243d10943c4ab7028d09e76cfb5892222e38bc4d35585bf35a88cd68c73b07", t), } params := azkeys.ImportKeyParameters{HSM: to.Ptr(true), Key: jwk} testSerde(t, ¶ms) resp, err := client.ImportKey(context.Background(), createRandomName(t, "testimport"), params, nil) require.NoError(t, err) - defer cleanUpKey(t, client, resp.Key.Key.KID) - require.Equal(t, jwk.KeyOperations, resp.Key.Key.KeyOperations) - require.Equal(t, jwk.N, resp.Key.Key.N) - require.Equal(t, jwk.E, resp.Key.Key.E) + defer cleanUpKey(t, client, resp.Key.KID) + require.Equal(t, jwk.KeyOps, resp.Key.KeyOps) + require.Equal(t, jwk.N, resp.Key.N) + require.Equal(t, jwk.E, resp.Key.E) }) } } @@ -402,7 +402,7 @@ func TestListDeletedKeys(t *testing.T) { keyNames[i] = n createResp, err := client.CreateKey(context.Background(), n, createParams, nil) require.NoError(t, err) - cleanUpKey(t, client, createResp.Key.Key.KID) + cleanUpKey(t, client, createResp.Key.KID) } for i := 0; i < len(keyNames); i++ { pollStatus(t, 404, func() error { @@ -449,7 +449,7 @@ func TestListKeys(t *testing.T) { n := createRandomName(t, fmt.Sprintf("%s-%d", keyNamePrefix, i)) resp, err := client.CreateKey(context.Background(), n, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) require.NoError(t, err) - defer cleanUpKey(t, client, resp.Key.Key.KID) + defer cleanUpKey(t, client, resp.Key.KID) count++ } @@ -488,10 +488,10 @@ func TestListKeyVersions(t *testing.T) { expectedVersions := make(map[string]struct{}, 4) for i := 0; i < 4; i++ { createResp, err = client.CreateKey(context.Background(), keyName, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeRSA)}, nil) - expectedVersions[createResp.Key.Key.KID.Version()] = struct{}{} + expectedVersions[createResp.Key.KID.Version()] = struct{}{} require.NoError(t, err) } - defer cleanUpKey(t, client, createResp.Key.Key.KID) + defer cleanUpKey(t, client, createResp.Key.KID) pager := client.NewListKeyPropertiesVersionsPager(keyName, &azkeys.ListKeyPropertiesVersionsOptions{MaxResults: to.Ptr(int32(1))}) for pager.More() { @@ -538,11 +538,11 @@ func TestRecoverDeletedKey(t *testing.T) { recoverResp, err := client.RecoverDeletedKey(context.Background(), key, nil) require.NoError(t, err) pollStatus(t, 404, func() error { - _, err := client.GetKey(context.Background(), key, createResp.Key.Key.KID.Version(), nil) + _, err := client.GetKey(context.Background(), key, createResp.Key.KID.Version(), nil) return err }) - cleanUpKey(t, client, createResp.Key.Key.KID) - require.Equal(t, createResp.Key.Key.KID, recoverResp.Key.Key.KID) + cleanUpKey(t, client, createResp.Key.KID) + require.Equal(t, createResp.Key.KID, recoverResp.Key.KID) require.NotNil(t, recoverResp.Attributes) }) } @@ -583,8 +583,8 @@ func TestReleaseKey(t *testing.T) { } } require.NoError(t, err) - require.NotNil(t, createResp.Key.Key.KID) - defer cleanUpKey(t, client, createResp.Key.Key.KID) + require.NotNil(t, createResp.Key.KID) + defer cleanUpKey(t, client, createResp.Key.KID) attestationClient, err := recording.NewRecordingHTTPClient(t, nil) require.NoError(t, err) @@ -625,19 +625,19 @@ func TestRotateKey(t *testing.T) { key := createRandomName(t, "testrotatekey") createResp, err := client.CreateKey(context.Background(), key, azkeys.CreateKeyParameters{Kty: to.Ptr(azkeys.KeyTypeECHSM)}, nil) require.NoError(t, err) - defer cleanUpKey(t, client, createResp.Key.Key.KID) + defer cleanUpKey(t, client, createResp.Key.KID) timeAfterCreate := to.Ptr("P30D") policy := azkeys.KeyRotationPolicy{ Attributes: &azkeys.KeyRotationPolicyAttributes{ ExpiryTime: to.Ptr("P90D"), }, - LifetimeActions: []*azkeys.KeyRotationLifetimeActions{ + LifetimeActions: []*azkeys.LifetimeActions{ { - Action: &azkeys.KeyRotationLifetimeActionsType{ + Action: &azkeys.LifetimeActionsType{ Type: to.Ptr(azkeys.KeyRotationPolicyActionRotate), }, - Trigger: &azkeys.KeyRotationLifetimeActionsTrigger{ + Trigger: &azkeys.LifetimeActionsTrigger{ TimeAfterCreate: timeAfterCreate, }, }, @@ -662,7 +662,7 @@ func TestRotateKey(t *testing.T) { rotateResp, err := client.RotateKey(context.Background(), key, nil) require.NoError(t, err) - require.NotNil(t, rotateResp.Key.Key.KID) + require.NotNil(t, rotateResp.Key.KID) invalid, err := client.RotateKey(context.Background(), "keynonexistent", nil) require.Error(t, err) @@ -683,9 +683,9 @@ func TestSignVerify(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - Curve: to.Ptr(azkeys.CurveNameP256K), - KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationSign, azkeys.KeyOperationVerify), - Kty: to.Ptr(azkeys.KeyTypeEC), + Curve: to.Ptr(azkeys.CurveNameP256K), + KeyOps: to.SliceOfPtrs(azkeys.KeyOperationSign, azkeys.KeyOperationVerify), + Kty: to.Ptr(azkeys.KeyTypeEC), } _, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) @@ -723,8 +723,8 @@ func TestWrapUnwrap(t *testing.T) { keyName := createRandomName(t, "key") createParams := azkeys.CreateKeyParameters{ - KeyOperations: to.SliceOfPtrs(azkeys.KeyOperationWrapKey, azkeys.KeyOperationUnwrapKey), - Kty: to.Ptr(azkeys.KeyTypeRSA), + KeyOps: to.SliceOfPtrs(azkeys.KeyOperationWrapKey, azkeys.KeyOperationUnwrapKey), + Kty: to.Ptr(azkeys.KeyTypeRSA), } _, err := client.CreateKey(context.Background(), keyName, createParams, nil) require.NoError(t, err) diff --git a/sdk/security/keyvault/azkeys/example_test.go b/sdk/security/keyvault/azkeys/example_test.go index 38f898ab8562..ef61055b6435 100644 --- a/sdk/security/keyvault/azkeys/example_test.go +++ b/sdk/security/keyvault/azkeys/example_test.go @@ -43,7 +43,7 @@ func ExampleClient_CreateKey_rsa() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.Key.KID) + fmt.Println(*resp.Key.KID) } func ExampleClient_CreateKey_ec() { @@ -56,7 +56,7 @@ func ExampleClient_CreateKey_ec() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.Key.KID) + fmt.Println(*resp.Key.KID) } func ExampleClient_DeleteKey() { @@ -95,7 +95,7 @@ func ExampleClient_GetKey() { if err != nil { // TODO: handle error } - fmt.Println(*resp.Key.Key.KID) + fmt.Println(*resp.Key.KID) } // UpdateKey updates the properties of a key previously stored in the key vault @@ -112,7 +112,7 @@ func ExampleClient_UpdateKey() { if err != nil { // TODO: handle error } - fmt.Printf("Enabled key %s", *updateResp.Key.Key.KID) + fmt.Printf("Enabled key %s", *updateResp.Key.KID) } // UpdateKeyRotationPolicy allows you to configure automatic key rotation for a key by specifying a rotation policy, and @@ -123,12 +123,12 @@ func ExampleClient_UpdateKey() { func ExampleClient_UpdateKeyRotationPolicy() { // this policy rotates the key every 18 months policy := azkeys.KeyRotationPolicy{ - LifetimeActions: []*azkeys.KeyRotationLifetimeActions{ + LifetimeActions: []*azkeys.LifetimeActions{ { - Action: &azkeys.KeyRotationLifetimeActionsType{ + Action: &azkeys.LifetimeActionsType{ Type: to.Ptr(azkeys.KeyRotationPolicyActionRotate), }, - Trigger: &azkeys.KeyRotationLifetimeActionsTrigger{ + Trigger: &azkeys.LifetimeActionsTrigger{ TimeAfterCreate: to.Ptr("P18M"), }, }, diff --git a/sdk/security/keyvault/azkeys/models.go b/sdk/security/keyvault/azkeys/models.go index 3fce25dcfe3d..54631de4fc17 100644 --- a/sdk/security/keyvault/azkeys/models.go +++ b/sdk/security/keyvault/azkeys/models.go @@ -152,7 +152,7 @@ type CreateKeyParameters struct { // The attributes of a key managed by the key vault service. KeyAttributes *KeyAttributes `json:"attributes,omitempty"` - KeyOperations []*KeyOperation `json:"key_ops,omitempty"` + KeyOps []*KeyOperation `json:"key_ops,omitempty"` // The key size in bits. For example: 2048, 3072, or 4096 for RSA. KeySize *int32 `json:"key_size,omitempty"` @@ -275,8 +275,8 @@ type JSONWebKey struct { K []byte `json:"k,omitempty"` // Key identifier. - KID *ID `json:"kid,omitempty"` - KeyOperations []*KeyOperation `json:"key_ops,omitempty"` + KID *ID `json:"kid,omitempty"` + KeyOps []*KeyOperation `json:"key_ops,omitempty"` // JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. Kty *KeyType `json:"kty,omitempty"` @@ -303,25 +303,6 @@ type JSONWebKey struct { Y []byte `json:"y,omitempty"` } -// Key - A KeyBundle consisting of a WebKey plus its attributes. -type Key struct { - // The key management attributes. - Attributes *KeyAttributes `json:"attributes,omitempty"` - - // The Json web key. - Key *JSONWebKey `json:"key,omitempty"` - - // The policy rules under which the key can be exported. - ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` - - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags,omitempty"` - - // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will - // be true. - Managed *bool `json:"managed,omitempty" azure:"ro"` -} - // KeyAttributes - The attributes of a key managed by the key vault service. type KeyAttributes struct { // Determines whether the object is enabled. @@ -432,31 +413,6 @@ type KeyReleaseResult struct { Value *string `json:"value,omitempty" azure:"ro"` } -// KeyRotationLifetimeActions - Action and its trigger that will be performed by Key Vault over the lifetime of a key. -type KeyRotationLifetimeActions struct { - // The action that will be executed. - Action *KeyRotationLifetimeActionsType `json:"action,omitempty"` - - // The condition that will execute the action. - Trigger *KeyRotationLifetimeActionsTrigger `json:"trigger,omitempty"` -} - -// KeyRotationLifetimeActionsTrigger - A condition to be satisfied for an action to be executed. -type KeyRotationLifetimeActionsTrigger struct { - // Time after creation to attempt to rotate. It only applies to rotate. It will be in ISO 8601 duration format. Example: 90 - // days : "P90D" - TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` - - // Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D" - TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` -} - -// KeyRotationLifetimeActionsType - The action that will be executed. -type KeyRotationLifetimeActionsType struct { - // The type of the action. - Type *KeyRotationPolicyAction `json:"type,omitempty"` -} - // KeyRotationPolicy - Management policy for a key. type KeyRotationPolicy struct { // The key rotation policy attributes. @@ -465,7 +421,7 @@ type KeyRotationPolicy struct { // Actions that will be performed by Key Vault over the lifetime of a key. For preview, lifetimeActions can only have two // items at maximum: one for rotate, one for notify. Notification time would be // default to 30 days before expiry and it is not configurable. - LifetimeActions []*KeyRotationLifetimeActions `json:"lifetimeActions,omitempty"` + LifetimeActions []*LifetimeActions `json:"lifetimeActions,omitempty"` // READ-ONLY; The key policy id. ID *string `json:"id,omitempty" azure:"ro"` @@ -484,12 +440,56 @@ type KeyRotationPolicyAttributes struct { Updated *time.Time `json:"updated,omitempty" azure:"ro"` } +// KeyVaultKey - A KeyBundle consisting of a WebKey plus its attributes. +type KeyVaultKey struct { + // The key management attributes. + Attributes *KeyAttributes `json:"attributes,omitempty"` + + // The Json web key. + Key *JSONWebKey `json:"key,omitempty"` + + // The policy rules under which the key can be exported. + ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` + + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will + // be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` +} + // KeyVerifyResult - The key verify result. type KeyVerifyResult struct { // READ-ONLY; True if the signature is verified, otherwise false. Value *bool `json:"value,omitempty" azure:"ro"` } +// LifetimeActions - Action and its trigger that will be performed by Key Vault over the lifetime of a key. +type LifetimeActions struct { + // The action that will be executed. + Action *LifetimeActionsType `json:"action,omitempty"` + + // The condition that will execute the action. + Trigger *LifetimeActionsTrigger `json:"trigger,omitempty"` +} + +// LifetimeActionsTrigger - A condition to be satisfied for an action to be executed. +type LifetimeActionsTrigger struct { + // Time after creation to attempt to rotate. It only applies to rotate. It will be in ISO 8601 duration format. Example: 90 + // days : "P90D" + TimeAfterCreate *string `json:"timeAfterCreate,omitempty"` + + // Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D" + TimeBeforeExpiry *string `json:"timeBeforeExpiry,omitempty"` +} + +// LifetimeActionsType - The action that will be executed. +type LifetimeActionsType struct { + // The type of the action. + Type *KeyRotationPolicyAction `json:"type,omitempty"` +} + // RandomBytes - The get random bytes response object containing the bytes. type RandomBytes struct { // REQUIRED; The bytes encoded as a base64url string. @@ -529,7 +529,7 @@ type UpdateKeyParameters struct { KeyAttributes *KeyAttributes `json:"attributes,omitempty"` // Json web key operations. For more information on possible key operations, see JsonWebKeyOperation. - KeyOperations []*KeyOperation `json:"key_ops,omitempty"` + KeyOps []*KeyOperation `json:"key_ops,omitempty"` // The policy rules under which the key can be exported. ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` diff --git a/sdk/security/keyvault/azkeys/models_serde.go b/sdk/security/keyvault/azkeys/models_serde.go index 086bed5fbbde..cf8b68dcc13f 100644 --- a/sdk/security/keyvault/azkeys/models_serde.go +++ b/sdk/security/keyvault/azkeys/models_serde.go @@ -49,7 +49,7 @@ func (c CreateKeyParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "crv", c.Curve) populate(objectMap, "attributes", c.KeyAttributes) - populate(objectMap, "key_ops", c.KeyOperations) + populate(objectMap, "key_ops", c.KeyOps) populate(objectMap, "key_size", c.KeySize) populate(objectMap, "kty", c.Kty) populate(objectMap, "public_exponent", c.PublicExponent) @@ -74,7 +74,7 @@ func (c *CreateKeyParameters) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KeyAttributes", &c.KeyAttributes) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOperations", &c.KeyOperations) + err = unpopulate(val, "KeyOps", &c.KeyOps) delete(rawMsg, key) case "key_size": err = unpopulate(val, "KeySize", &c.KeySize) @@ -316,7 +316,7 @@ func (j JSONWebKey) MarshalJSON() ([]byte, error) { populateByteArray(objectMap, "e", j.E, runtime.Base64URLFormat) populateByteArray(objectMap, "k", j.K, runtime.Base64URLFormat) populate(objectMap, "kid", j.KID) - populate(objectMap, "key_ops", j.KeyOperations) + populate(objectMap, "key_ops", j.KeyOps) populate(objectMap, "kty", j.Kty) populateByteArray(objectMap, "n", j.N, runtime.Base64URLFormat) populateByteArray(objectMap, "p", j.P, runtime.Base64URLFormat) @@ -359,7 +359,7 @@ func (j *JSONWebKey) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KID", &j.KID) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOperations", &j.KeyOperations) + err = unpopulate(val, "KeyOps", &j.KeyOps) delete(rawMsg, key) case "kty": err = unpopulate(val, "Kty", &j.Kty) @@ -393,49 +393,6 @@ func (j *JSONWebKey) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type Key. -func (k Key) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "attributes", k.Attributes) - populate(objectMap, "key", k.Key) - populate(objectMap, "managed", k.Managed) - populate(objectMap, "release_policy", k.ReleasePolicy) - populate(objectMap, "tags", k.Tags) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type Key. -func (k *Key) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "attributes": - err = unpopulate(val, "Attributes", &k.Attributes) - delete(rawMsg, key) - case "key": - err = unpopulate(val, "Key", &k.Key) - delete(rawMsg, key) - case "managed": - err = unpopulate(val, "Managed", &k.Managed) - delete(rawMsg, key) - case "release_policy": - err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) - delete(rawMsg, key) - case "tags": - err = unpopulate(val, "Tags", &k.Tags) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type KeyAttributes. func (k KeyAttributes) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -709,16 +666,17 @@ func (k *KeyReleaseResult) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActions. -func (k KeyRotationLifetimeActions) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyRotationPolicy. +func (k KeyRotationPolicy) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "action", k.Action) - populate(objectMap, "trigger", k.Trigger) + populate(objectMap, "attributes", k.Attributes) + populate(objectMap, "id", k.ID) + populate(objectMap, "lifetimeActions", k.LifetimeActions) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActions. -func (k *KeyRotationLifetimeActions) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationPolicy. +func (k *KeyRotationPolicy) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -726,11 +684,14 @@ func (k *KeyRotationLifetimeActions) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "action": - err = unpopulate(val, "Action", &k.Action) + case "attributes": + err = unpopulate(val, "Attributes", &k.Attributes) delete(rawMsg, key) - case "trigger": - err = unpopulate(val, "Trigger", &k.Trigger) + case "id": + err = unpopulate(val, "ID", &k.ID) + delete(rawMsg, key) + case "lifetimeActions": + err = unpopulate(val, "LifetimeActions", &k.LifetimeActions) delete(rawMsg, key) } if err != nil { @@ -740,16 +701,17 @@ func (k *KeyRotationLifetimeActions) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActionsTrigger. -func (k KeyRotationLifetimeActionsTrigger) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyRotationPolicyAttributes. +func (k KeyRotationPolicyAttributes) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "timeAfterCreate", k.TimeAfterCreate) - populate(objectMap, "timeBeforeExpiry", k.TimeBeforeExpiry) + populateTimeUnix(objectMap, "created", k.Created) + populate(objectMap, "expiryTime", k.ExpiryTime) + populateTimeUnix(objectMap, "updated", k.Updated) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActionsTrigger. -func (k *KeyRotationLifetimeActionsTrigger) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationPolicyAttributes. +func (k *KeyRotationPolicyAttributes) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -757,11 +719,14 @@ func (k *KeyRotationLifetimeActionsTrigger) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "timeAfterCreate": - err = unpopulate(val, "TimeAfterCreate", &k.TimeAfterCreate) + case "created": + err = unpopulateTimeUnix(val, "Created", &k.Created) delete(rawMsg, key) - case "timeBeforeExpiry": - err = unpopulate(val, "TimeBeforeExpiry", &k.TimeBeforeExpiry) + case "expiryTime": + err = unpopulate(val, "ExpiryTime", &k.ExpiryTime) + delete(rawMsg, key) + case "updated": + err = unpopulateTimeUnix(val, "Updated", &k.Updated) delete(rawMsg, key) } if err != nil { @@ -771,15 +736,19 @@ func (k *KeyRotationLifetimeActionsTrigger) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyRotationLifetimeActionsType. -func (k KeyRotationLifetimeActionsType) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyVaultKey. +func (k KeyVaultKey) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "type", k.Type) + populate(objectMap, "attributes", k.Attributes) + populate(objectMap, "key", k.Key) + populate(objectMap, "managed", k.Managed) + populate(objectMap, "release_policy", k.ReleasePolicy) + populate(objectMap, "tags", k.Tags) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationLifetimeActionsType. -func (k *KeyRotationLifetimeActionsType) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVaultKey. +func (k *KeyVaultKey) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -787,8 +756,20 @@ func (k *KeyRotationLifetimeActionsType) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "type": - err = unpopulate(val, "Type", &k.Type) + case "attributes": + err = unpopulate(val, "Attributes", &k.Attributes) + delete(rawMsg, key) + case "key": + err = unpopulate(val, "Key", &k.Key) + delete(rawMsg, key) + case "managed": + err = unpopulate(val, "Managed", &k.Managed) + delete(rawMsg, key) + case "release_policy": + err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &k.Tags) delete(rawMsg, key) } if err != nil { @@ -798,17 +779,15 @@ func (k *KeyRotationLifetimeActionsType) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyRotationPolicy. -func (k KeyRotationPolicy) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. +func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "attributes", k.Attributes) - populate(objectMap, "id", k.ID) - populate(objectMap, "lifetimeActions", k.LifetimeActions) + populate(objectMap, "value", k.Value) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationPolicy. -func (k *KeyRotationPolicy) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVerifyResult. +func (k *KeyVerifyResult) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { return fmt.Errorf("unmarshalling type %T: %v", k, err) @@ -816,14 +795,8 @@ func (k *KeyRotationPolicy) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { - case "attributes": - err = unpopulate(val, "Attributes", &k.Attributes) - delete(rawMsg, key) - case "id": - err = unpopulate(val, "ID", &k.ID) - delete(rawMsg, key) - case "lifetimeActions": - err = unpopulate(val, "LifetimeActions", &k.LifetimeActions) + case "value": + err = unpopulate(val, "Value", &k.Value) delete(rawMsg, key) } if err != nil { @@ -833,63 +806,90 @@ func (k *KeyRotationPolicy) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyRotationPolicyAttributes. -func (k KeyRotationPolicyAttributes) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type LifetimeActions. +func (l LifetimeActions) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populateTimeUnix(objectMap, "created", k.Created) - populate(objectMap, "expiryTime", k.ExpiryTime) - populateTimeUnix(objectMap, "updated", k.Updated) + populate(objectMap, "action", l.Action) + populate(objectMap, "trigger", l.Trigger) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyRotationPolicyAttributes. -func (k *KeyRotationPolicyAttributes) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActions. +func (l *LifetimeActions) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) + return fmt.Errorf("unmarshalling type %T: %v", l, err) } for key, val := range rawMsg { var err error switch key { - case "created": - err = unpopulateTimeUnix(val, "Created", &k.Created) + case "action": + err = unpopulate(val, "Action", &l.Action) delete(rawMsg, key) - case "expiryTime": - err = unpopulate(val, "ExpiryTime", &k.ExpiryTime) + case "trigger": + err = unpopulate(val, "Trigger", &l.Trigger) delete(rawMsg, key) - case "updated": - err = unpopulateTimeUnix(val, "Updated", &k.Updated) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", l, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type LifetimeActionsTrigger. +func (l LifetimeActionsTrigger) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "timeAfterCreate", l.TimeAfterCreate) + populate(objectMap, "timeBeforeExpiry", l.TimeBeforeExpiry) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActionsTrigger. +func (l *LifetimeActionsTrigger) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", l, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "timeAfterCreate": + err = unpopulate(val, "TimeAfterCreate", &l.TimeAfterCreate) + delete(rawMsg, key) + case "timeBeforeExpiry": + err = unpopulate(val, "TimeBeforeExpiry", &l.TimeBeforeExpiry) delete(rawMsg, key) } if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) + return fmt.Errorf("unmarshalling type %T: %v", l, err) } } return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. -func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { +// MarshalJSON implements the json.Marshaller interface for type LifetimeActionsType. +func (l LifetimeActionsType) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "value", k.Value) + populate(objectMap, "type", l.Type) return json.Marshal(objectMap) } -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVerifyResult. -func (k *KeyVerifyResult) UnmarshalJSON(data []byte) error { +// UnmarshalJSON implements the json.Unmarshaller interface for type LifetimeActionsType. +func (l *LifetimeActionsType) UnmarshalJSON(data []byte) error { var rawMsg map[string]json.RawMessage if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) + return fmt.Errorf("unmarshalling type %T: %v", l, err) } for key, val := range rawMsg { var err error switch key { - case "value": - err = unpopulate(val, "Value", &k.Value) + case "type": + err = unpopulate(val, "Type", &l.Type) delete(rawMsg, key) } if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) + return fmt.Errorf("unmarshalling type %T: %v", l, err) } } return nil @@ -1019,7 +1019,7 @@ func (s *SignParameters) UnmarshalJSON(data []byte) error { func (u UpdateKeyParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "attributes", u.KeyAttributes) - populate(objectMap, "key_ops", u.KeyOperations) + populate(objectMap, "key_ops", u.KeyOps) populate(objectMap, "release_policy", u.ReleasePolicy) populate(objectMap, "tags", u.Tags) return json.Marshal(objectMap) @@ -1038,7 +1038,7 @@ func (u *UpdateKeyParameters) UnmarshalJSON(data []byte) error { err = unpopulate(val, "KeyAttributes", &u.KeyAttributes) delete(rawMsg, key) case "key_ops": - err = unpopulate(val, "KeyOperations", &u.KeyOperations) + err = unpopulate(val, "KeyOps", &u.KeyOps) delete(rawMsg, key) case "release_policy": err = unpopulate(val, "ReleasePolicy", &u.ReleasePolicy) diff --git a/sdk/security/keyvault/azkeys/response_types.go b/sdk/security/keyvault/azkeys/response_types.go index 6802ff0421aa..d1adaed1cef1 100644 --- a/sdk/security/keyvault/azkeys/response_types.go +++ b/sdk/security/keyvault/azkeys/response_types.go @@ -16,7 +16,7 @@ type BackupKeyResponse struct { // CreateKeyResponse contains the response from method Client.CreateKey. type CreateKeyResponse struct { - Key + KeyVaultKey } // DecryptResponse contains the response from method Client.Decrypt. @@ -41,7 +41,7 @@ type GetDeletedKeyResponse struct { // GetKeyResponse contains the response from method Client.GetKey. type GetKeyResponse struct { - Key + KeyVaultKey } // GetKeyRotationPolicyResponse contains the response from method Client.GetKeyRotationPolicy. @@ -56,7 +56,7 @@ type GetRandomBytesResponse struct { // ImportKeyResponse contains the response from method Client.ImportKey. type ImportKeyResponse struct { - Key + KeyVaultKey } // ListDeletedKeyPropertiesResponse contains the response from method Client.NewListDeletedKeyPropertiesPager. @@ -81,7 +81,7 @@ type PurgeDeletedKeyResponse struct { // RecoverDeletedKeyResponse contains the response from method Client.RecoverDeletedKey. type RecoverDeletedKeyResponse struct { - Key + KeyVaultKey } // ReleaseResponse contains the response from method Client.Release. @@ -91,12 +91,12 @@ type ReleaseResponse struct { // RestoreKeyResponse contains the response from method Client.RestoreKey. type RestoreKeyResponse struct { - Key + KeyVaultKey } // RotateKeyResponse contains the response from method Client.RotateKey. type RotateKeyResponse struct { - Key + KeyVaultKey } // SignResponse contains the response from method Client.Sign. @@ -111,7 +111,7 @@ type UnwrapKeyResponse struct { // UpdateKeyResponse contains the response from method Client.UpdateKey. type UpdateKeyResponse struct { - Key + KeyVaultKey } // UpdateKeyRotationPolicyResponse contains the response from method Client.UpdateKeyRotationPolicy. From f33cead2c1920051ad6ac1be8db5ae27a9e7d610 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Wed, 31 May 2023 14:08:38 -0700 Subject: [PATCH 06/10] heath feedback --- sdk/security/keyvault/azkeys/CHANGELOG.md | 6 +++--- sdk/security/keyvault/azkeys/autorest.md | 14 +++++++++++--- sdk/security/keyvault/azkeys/client.go | 10 ---------- sdk/security/keyvault/azkeys/client_test.go | 6 +++--- sdk/security/keyvault/azkeys/constants.go | 3 --- sdk/security/keyvault/azkeys/models.go | 9 +++------ sdk/security/keyvault/azkeys/version.go | 2 +- 7 files changed, 21 insertions(+), 29 deletions(-) diff --git a/sdk/security/keyvault/azkeys/CHANGELOG.md b/sdk/security/keyvault/azkeys/CHANGELOG.md index 2ec2e9977fb2..c8f5ec481446 100644 --- a/sdk/security/keyvault/azkeys/CHANGELOG.md +++ b/sdk/security/keyvault/azkeys/CHANGELOG.md @@ -1,11 +1,9 @@ # Release History -## 1.0.0 (unreleased) +## 0.12.0 (unreleased) ### Breaking Changes -*Breaking Changes from last preview. Going forward, the module is now stable and will not have breaking api changes.* - * Renamed `GetRandomBytesRequest` to `GetRandomBytesParameters` * `ListDeletedKey` to `ListDeletedKeyProperties` * `ListKeys` to `ListKeyProperties` @@ -27,6 +25,8 @@ * `JSONWebKeySignatureAlgorithm` to `SignatureAlgorithm` * `JSONWebKeyType` to `KeyType` * Removed `DeletionRecoveryLevel` type +* Deleted `SignatureAlgorithmRSNULL` constant +* Removed `MaxResults` option ### Other Changes * Updated dependencies diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index 8aedb10f1474..89fc8fd6ee29 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -88,6 +88,12 @@ directive: where: $.definitions.RestoreKeyParameters.properties.value transform: $["x-ms-client-name"] = "KeyBackup" + # Remove MaxResults parameter + - where: "$.paths..*" + remove-parameter: + in: query + name: maxresults + # KeyOps updates - rename-model: from: KeyOperationsParameters @@ -106,9 +112,6 @@ directive: - from: swagger-document where: $.definitions..properties..kid transform: $["x-ms-client-name"] = "KID" - - from: swagger-document - where: $.paths..parameters..[?(@.name=='maxresults')] - transform: $["x-ms-client-name"] = "MaxResults" # keyName, keyVersion -> name, version - from: swagger-document @@ -172,6 +175,11 @@ directive: where: $ transform: return $.replace(/const \(\n\s\/\/ DeletionRecoveryLevel(?:.+\s)+\)/, ""); + # delete SignatureAlgorithmRSNULL + - from: constants.go + where: $ + transform: return $.replace(/.*(\bSignatureAlgorithmRSNULL\b).*/g, ""); + # delete unused error models - from: models.go where: $ diff --git a/sdk/security/keyvault/azkeys/client.go b/sdk/security/keyvault/azkeys/client.go index 5e6f6a8fda5c..998920558e81 100644 --- a/sdk/security/keyvault/azkeys/client.go +++ b/sdk/security/keyvault/azkeys/client.go @@ -17,7 +17,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" "net/url" - "strconv" "strings" ) @@ -595,9 +594,6 @@ func (client *Client) listDeletedKeyPropertiesCreateRequest(ctx context.Context, return nil, err } reqQP := req.Raw().URL.Query() - if options != nil && options.MaxResults != nil { - reqQP.Set("maxresults", strconv.FormatInt(int64(*options.MaxResults), 10)) - } reqQP.Set("api-version", "7.4") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} @@ -656,9 +652,6 @@ func (client *Client) listKeyPropertiesCreateRequest(ctx context.Context, option return nil, err } reqQP := req.Raw().URL.Query() - if options != nil && options.MaxResults != nil { - reqQP.Set("maxresults", strconv.FormatInt(int64(*options.MaxResults), 10)) - } reqQP.Set("api-version", "7.4") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} @@ -721,9 +714,6 @@ func (client *Client) listKeyPropertiesVersionsCreateRequest(ctx context.Context return nil, err } reqQP := req.Raw().URL.Query() - if options != nil && options.MaxResults != nil { - reqQP.Set("maxresults", strconv.FormatInt(int64(*options.MaxResults), 10)) - } reqQP.Set("api-version", "7.4") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index c756bd818c34..f94a3af27161 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -410,7 +410,7 @@ func TestListDeletedKeys(t *testing.T) { return err }) } - pager := client.NewListDeletedKeyPropertiesPager(&azkeys.ListDeletedKeyPropertiesOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListDeletedKeyPropertiesPager(nil) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) @@ -453,7 +453,7 @@ func TestListKeys(t *testing.T) { count++ } - pager := client.NewListKeyPropertiesPager(&azkeys.ListKeyPropertiesOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListKeyPropertiesPager(nil) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) @@ -493,7 +493,7 @@ func TestListKeyVersions(t *testing.T) { } defer cleanUpKey(t, client, createResp.Key.KID) - pager := client.NewListKeyPropertiesVersionsPager(keyName, &azkeys.ListKeyPropertiesVersionsOptions{MaxResults: to.Ptr(int32(1))}) + pager := client.NewListKeyPropertiesVersionsPager(keyName, nil) for pager.More() { resp, err := pager.NextPage(context.Background()) require.NoError(t, err) diff --git a/sdk/security/keyvault/azkeys/constants.go b/sdk/security/keyvault/azkeys/constants.go index 4bf3199df302..b8c55a97ceab 100644 --- a/sdk/security/keyvault/azkeys/constants.go +++ b/sdk/security/keyvault/azkeys/constants.go @@ -128,8 +128,6 @@ const ( SignatureAlgorithmRS384 SignatureAlgorithm = "RS384" // SignatureAlgorithmRS512 - RSASSA-PKCS1-v1_5 using SHA-512, as described in https://tools.ietf.org/html/rfc7518 SignatureAlgorithmRS512 SignatureAlgorithm = "RS512" - // SignatureAlgorithmRSNULL - Reserved - SignatureAlgorithmRSNULL SignatureAlgorithm = "RSNULL" ) // PossibleSignatureAlgorithmValues returns the possible values for the SignatureAlgorithm const type. @@ -145,7 +143,6 @@ func PossibleSignatureAlgorithmValues() []SignatureAlgorithm { SignatureAlgorithmRS256, SignatureAlgorithmRS384, SignatureAlgorithmRS512, - SignatureAlgorithmRSNULL, } } diff --git a/sdk/security/keyvault/azkeys/models.go b/sdk/security/keyvault/azkeys/models.go index 54631de4fc17..0416560fad55 100644 --- a/sdk/security/keyvault/azkeys/models.go +++ b/sdk/security/keyvault/azkeys/models.go @@ -70,21 +70,18 @@ type ImportKeyOptions struct { // ListDeletedKeyPropertiesOptions contains the optional parameters for the Client.NewListDeletedKeyPropertiesPager // method. type ListDeletedKeyPropertiesOptions struct { - // Maximum number of results to return in a page. If not specified the service will return up to 25 results. - MaxResults *int32 + // placeholder for future optional parameters } // ListKeyPropertiesOptions contains the optional parameters for the Client.NewListKeyPropertiesPager method. type ListKeyPropertiesOptions struct { - // Maximum number of results to return in a page. If not specified the service will return up to 25 results. - MaxResults *int32 + // placeholder for future optional parameters } // ListKeyPropertiesVersionsOptions contains the optional parameters for the Client.NewListKeyPropertiesVersionsPager // method. type ListKeyPropertiesVersionsOptions struct { - // Maximum number of results to return in a page. If not specified the service will return up to 25 results. - MaxResults *int32 + // placeholder for future optional parameters } // PurgeDeletedKeyOptions contains the optional parameters for the Client.PurgeDeletedKey method. diff --git a/sdk/security/keyvault/azkeys/version.go b/sdk/security/keyvault/azkeys/version.go index d38632ecc25a..0eff06644c7f 100644 --- a/sdk/security/keyvault/azkeys/version.go +++ b/sdk/security/keyvault/azkeys/version.go @@ -8,5 +8,5 @@ package azkeys const ( moduleName = "azkeys" - version = "v1.0.0" + version = "v0.12.0" ) From 69b059c7f09d537e4a609d6c0f07bf323fa5656c Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Fri, 2 Jun 2023 12:34:13 -0700 Subject: [PATCH 07/10] remove KeyOperationExport --- sdk/security/keyvault/azkeys/CHANGELOG.md | 3 ++- sdk/security/keyvault/azkeys/autorest.md | 5 ++++ sdk/security/keyvault/azkeys/client_test.go | 12 ---------- sdk/security/keyvault/azkeys/constants.go | 8 +++---- sdk/security/keyvault/azkeys/utils_test.go | 26 +++++++++++++++++++++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/sdk/security/keyvault/azkeys/CHANGELOG.md b/sdk/security/keyvault/azkeys/CHANGELOG.md index c8f5ec481446..d44aa77524db 100644 --- a/sdk/security/keyvault/azkeys/CHANGELOG.md +++ b/sdk/security/keyvault/azkeys/CHANGELOG.md @@ -25,7 +25,8 @@ * `JSONWebKeySignatureAlgorithm` to `SignatureAlgorithm` * `JSONWebKeyType` to `KeyType` * Removed `DeletionRecoveryLevel` type -* Deleted `SignatureAlgorithmRSNULL` constant +* Removed `SignatureAlgorithmRSNULL` constant +* Removed `KeyOperationExport` constant * Removed `MaxResults` option ### Other Changes diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index 89fc8fd6ee29..3d7a526801fb 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -180,6 +180,11 @@ directive: where: $ transform: return $.replace(/.*(\bSignatureAlgorithmRSNULL\b).*/g, ""); + # delete KeyOperationExport + - from: constants.go + where: $ + transform: return $.replace(/.*(\bKeyOperationExport\b).*/g, ""); + # delete unused error models - from: models.go where: $ diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index f94a3af27161..523198397295 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -58,18 +58,6 @@ func requireEqualAttributes(t *testing.T, a, b *azkeys.KeyAttributes) { require.Equal(t, a.Updated, b.Updated) } -type serdeModel interface { - json.Marshaler - json.Unmarshaler -} - -func testSerde[T serdeModel](t *testing.T, model T) { - data, err := model.MarshalJSON() - require.NoError(t, err) - err = model.UnmarshalJSON(data) - require.NoError(t, err) -} - func TestBackupRestore(t *testing.T) { name := "KV" for _, mhsm := range []bool{false, true} { diff --git a/sdk/security/keyvault/azkeys/constants.go b/sdk/security/keyvault/azkeys/constants.go index b8c55a97ceab..64960a4090c6 100644 --- a/sdk/security/keyvault/azkeys/constants.go +++ b/sdk/security/keyvault/azkeys/constants.go @@ -79,9 +79,9 @@ func PossibleEncryptionAlgorithmValues() []EncryptionAlgorithm { type KeyOperation string const ( - KeyOperationDecrypt KeyOperation = "decrypt" - KeyOperationEncrypt KeyOperation = "encrypt" - KeyOperationExport KeyOperation = "export" + KeyOperationDecrypt KeyOperation = "decrypt" + KeyOperationEncrypt KeyOperation = "encrypt" + KeyOperationImport KeyOperation = "import" KeyOperationSign KeyOperation = "sign" KeyOperationUnwrapKey KeyOperation = "unwrapKey" @@ -94,7 +94,7 @@ func PossibleKeyOperationValues() []KeyOperation { return []KeyOperation{ KeyOperationDecrypt, KeyOperationEncrypt, - KeyOperationExport, + KeyOperationImport, KeyOperationSign, KeyOperationUnwrapKey, diff --git a/sdk/security/keyvault/azkeys/utils_test.go b/sdk/security/keyvault/azkeys/utils_test.go index d0de9910ff33..4d52fa56925e 100644 --- a/sdk/security/keyvault/azkeys/utils_test.go +++ b/sdk/security/keyvault/azkeys/utils_test.go @@ -14,6 +14,7 @@ import ( "fmt" "hash/fnv" "os" + "regexp" "strings" "sync" "testing" @@ -245,3 +246,28 @@ func getMarshalledReleasePolicy(attestationURL string) []byte { }) return data } + +type serdeModel interface { + json.Marshaler + json.Unmarshaler +} + +func testSerde[T serdeModel](t *testing.T, model T) { + data, err := model.MarshalJSON() + require.NoError(t, err) + err = model.UnmarshalJSON(data) + require.NoError(t, err) + + // testing unmarshal error scenarios + var data2 []byte + err = model.UnmarshalJSON(data2) + require.Error(t, err) + + m := regexp.MustCompile(":.*$") + modifiedData := m.ReplaceAllString(string(data), ":false}") + if modifiedData != "{}" { + data3 := []byte(modifiedData) + err = model.UnmarshalJSON(data3) + require.Error(t, err) + } +} From cf895a7d8c99a62ca9e9a1f3adf52e07edb076f2 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Mon, 5 Jun 2023 09:13:55 -0700 Subject: [PATCH 08/10] test updates --- sdk/security/keyvault/azkeys/assets.json | 2 +- sdk/security/keyvault/azkeys/utils_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/security/keyvault/azkeys/assets.json b/sdk/security/keyvault/azkeys/assets.json index 296d9f1404b4..1da72428681a 100644 --- a/sdk/security/keyvault/azkeys/assets.json +++ b/sdk/security/keyvault/azkeys/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/security/keyvault/azkeys", - "Tag": "go/security/keyvault/azkeys_d9ce3682be" + "Tag": "go/security/keyvault/azkeys_afbe036428" } diff --git a/sdk/security/keyvault/azkeys/utils_test.go b/sdk/security/keyvault/azkeys/utils_test.go index 4d52fa56925e..5a88f3fef6df 100644 --- a/sdk/security/keyvault/azkeys/utils_test.go +++ b/sdk/security/keyvault/azkeys/utils_test.go @@ -264,7 +264,7 @@ func testSerde[T serdeModel](t *testing.T, model T) { require.Error(t, err) m := regexp.MustCompile(":.*$") - modifiedData := m.ReplaceAllString(string(data), ":false}") + modifiedData := m.ReplaceAllString(string(data), ":[\"test\", \"test1\", \"test2\"]}") if modifiedData != "{}" { data3 := []byte(modifiedData) err = model.UnmarshalJSON(data3) From dc700d53a02e04514e5eabc29d36942245f00cce Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Tue, 6 Jun 2023 09:33:29 -0700 Subject: [PATCH 09/10] change back to keybundle --- sdk/security/keyvault/azkeys/autorest.md | 3 - sdk/security/keyvault/azkeys/client.go | 14 +-- sdk/security/keyvault/azkeys/client_test.go | 2 +- sdk/security/keyvault/azkeys/models.go | 38 ++++---- sdk/security/keyvault/azkeys/models_serde.go | 86 +++++++++---------- .../keyvault/azkeys/response_types.go | 14 +-- 6 files changed, 77 insertions(+), 80 deletions(-) diff --git a/sdk/security/keyvault/azkeys/autorest.md b/sdk/security/keyvault/azkeys/autorest.md index 3d7a526801fb..7744bd7c5e5d 100644 --- a/sdk/security/keyvault/azkeys/autorest.md +++ b/sdk/security/keyvault/azkeys/autorest.md @@ -69,9 +69,6 @@ directive: - rename-model: from: DeletedKeyBundle to: DeletedKey - - rename-model: - from: KeyBundle - to: KeyVaultKey - rename-model: from: KeyItem to: KeyProperties diff --git a/sdk/security/keyvault/azkeys/client.go b/sdk/security/keyvault/azkeys/client.go index 998920558e81..02ec6c7fd008 100644 --- a/sdk/security/keyvault/azkeys/client.go +++ b/sdk/security/keyvault/azkeys/client.go @@ -131,7 +131,7 @@ func (client *Client) createKeyCreateRequest(ctx context.Context, name string, p // createKeyHandleResponse handles the CreateKey response. func (client *Client) createKeyHandleResponse(resp *http.Response) (CreateKeyResponse, error) { result := CreateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return CreateKeyResponse{}, err } return result, nil @@ -398,7 +398,7 @@ func (client *Client) getKeyCreateRequest(ctx context.Context, name string, vers // getKeyHandleResponse handles the GetKey response. func (client *Client) getKeyHandleResponse(resp *http.Response) (GetKeyResponse, error) { result := GetKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return GetKeyResponse{}, err } return result, nil @@ -543,7 +543,7 @@ func (client *Client) importKeyCreateRequest(ctx context.Context, name string, p // importKeyHandleResponse handles the ImportKey response. func (client *Client) importKeyHandleResponse(resp *http.Response) (ImportKeyResponse, error) { result := ImportKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return ImportKeyResponse{}, err } return result, nil @@ -815,7 +815,7 @@ func (client *Client) recoverDeletedKeyCreateRequest(ctx context.Context, name s // recoverDeletedKeyHandleResponse handles the RecoverDeletedKey response. func (client *Client) recoverDeletedKeyHandleResponse(resp *http.Response) (RecoverDeletedKeyResponse, error) { result := RecoverDeletedKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return RecoverDeletedKeyResponse{}, err } return result, nil @@ -919,7 +919,7 @@ func (client *Client) restoreKeyCreateRequest(ctx context.Context, parameters Re // restoreKeyHandleResponse handles the RestoreKey response. func (client *Client) restoreKeyHandleResponse(resp *http.Response) (RestoreKeyResponse, error) { result := RestoreKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return RestoreKeyResponse{}, err } return result, nil @@ -967,7 +967,7 @@ func (client *Client) rotateKeyCreateRequest(ctx context.Context, name string, o // rotateKeyHandleResponse handles the RotateKey response. func (client *Client) rotateKeyHandleResponse(resp *http.Response) (RotateKeyResponse, error) { result := RotateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return RotateKeyResponse{}, err } return result, nil @@ -1125,7 +1125,7 @@ func (client *Client) updateKeyCreateRequest(ctx context.Context, name string, v // updateKeyHandleResponse handles the UpdateKey response. func (client *Client) updateKeyHandleResponse(resp *http.Response) (UpdateKeyResponse, error) { result := UpdateKeyResponse{} - if err := runtime.UnmarshalAsJSON(resp, &result.KeyVaultKey); err != nil { + if err := runtime.UnmarshalAsJSON(resp, &result.KeyBundle); err != nil { return UpdateKeyResponse{}, err } return result, nil diff --git a/sdk/security/keyvault/azkeys/client_test.go b/sdk/security/keyvault/azkeys/client_test.go index 523198397295..aaaf94f21011 100644 --- a/sdk/security/keyvault/azkeys/client_test.go +++ b/sdk/security/keyvault/azkeys/client_test.go @@ -159,7 +159,7 @@ func TestCRUD(t *testing.T) { requireEqualAttributes(t, createResp.Attributes, getResp.Attributes) require.Equal(t, createResp.Key.KID.Name(), getResp.Key.KID.Name()) require.Equal(t, createResp.Key.KID.Version(), getResp.Key.KID.Version()) - testSerde(t, &getResp.KeyVaultKey) + testSerde(t, &getResp.KeyBundle) updateParams := azkeys.UpdateKeyParameters{ KeyAttributes: &azkeys.KeyAttributes{ diff --git a/sdk/security/keyvault/azkeys/models.go b/sdk/security/keyvault/azkeys/models.go index 0416560fad55..070332c93fae 100644 --- a/sdk/security/keyvault/azkeys/models.go +++ b/sdk/security/keyvault/azkeys/models.go @@ -330,6 +330,25 @@ type KeyAttributes struct { Updated *time.Time `json:"updated,omitempty" azure:"ro"` } +// KeyBundle - A KeyBundle consisting of a WebKey plus its attributes. +type KeyBundle struct { + // The key management attributes. + Attributes *KeyAttributes `json:"attributes,omitempty"` + + // The Json web key. + Key *JSONWebKey `json:"key,omitempty"` + + // The policy rules under which the key can be exported. + ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` + + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will + // be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` +} + // KeyOperationParameters - The key operations parameters. type KeyOperationParameters struct { // REQUIRED; algorithm identifier @@ -437,25 +456,6 @@ type KeyRotationPolicyAttributes struct { Updated *time.Time `json:"updated,omitempty" azure:"ro"` } -// KeyVaultKey - A KeyBundle consisting of a WebKey plus its attributes. -type KeyVaultKey struct { - // The key management attributes. - Attributes *KeyAttributes `json:"attributes,omitempty"` - - // The Json web key. - Key *JSONWebKey `json:"key,omitempty"` - - // The policy rules under which the key can be exported. - ReleasePolicy *KeyReleasePolicy `json:"release_policy,omitempty"` - - // Application specific metadata in the form of key-value pairs. - Tags map[string]*string `json:"tags,omitempty"` - - // READ-ONLY; True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will - // be true. - Managed *bool `json:"managed,omitempty" azure:"ro"` -} - // KeyVerifyResult - The key verify result. type KeyVerifyResult struct { // READ-ONLY; True if the signature is verified, otherwise false. diff --git a/sdk/security/keyvault/azkeys/models_serde.go b/sdk/security/keyvault/azkeys/models_serde.go index cf8b68dcc13f..e62b9b7c2efd 100644 --- a/sdk/security/keyvault/azkeys/models_serde.go +++ b/sdk/security/keyvault/azkeys/models_serde.go @@ -448,6 +448,49 @@ func (k *KeyAttributes) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type KeyBundle. +func (k KeyBundle) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "attributes", k.Attributes) + populate(objectMap, "key", k.Key) + populate(objectMap, "managed", k.Managed) + populate(objectMap, "release_policy", k.ReleasePolicy) + populate(objectMap, "tags", k.Tags) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type KeyBundle. +func (k *KeyBundle) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "attributes": + err = unpopulate(val, "Attributes", &k.Attributes) + delete(rawMsg, key) + case "key": + err = unpopulate(val, "Key", &k.Key) + delete(rawMsg, key) + case "managed": + err = unpopulate(val, "Managed", &k.Managed) + delete(rawMsg, key) + case "release_policy": + err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &k.Tags) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", k, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type KeyOperationParameters. func (k KeyOperationParameters) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -736,49 +779,6 @@ func (k *KeyRotationPolicyAttributes) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type KeyVaultKey. -func (k KeyVaultKey) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "attributes", k.Attributes) - populate(objectMap, "key", k.Key) - populate(objectMap, "managed", k.Managed) - populate(objectMap, "release_policy", k.ReleasePolicy) - populate(objectMap, "tags", k.Tags) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type KeyVaultKey. -func (k *KeyVaultKey) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "attributes": - err = unpopulate(val, "Attributes", &k.Attributes) - delete(rawMsg, key) - case "key": - err = unpopulate(val, "Key", &k.Key) - delete(rawMsg, key) - case "managed": - err = unpopulate(val, "Managed", &k.Managed) - delete(rawMsg, key) - case "release_policy": - err = unpopulate(val, "ReleasePolicy", &k.ReleasePolicy) - delete(rawMsg, key) - case "tags": - err = unpopulate(val, "Tags", &k.Tags) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", k, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type KeyVerifyResult. func (k KeyVerifyResult) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) diff --git a/sdk/security/keyvault/azkeys/response_types.go b/sdk/security/keyvault/azkeys/response_types.go index d1adaed1cef1..e9fe38e6b702 100644 --- a/sdk/security/keyvault/azkeys/response_types.go +++ b/sdk/security/keyvault/azkeys/response_types.go @@ -16,7 +16,7 @@ type BackupKeyResponse struct { // CreateKeyResponse contains the response from method Client.CreateKey. type CreateKeyResponse struct { - KeyVaultKey + KeyBundle } // DecryptResponse contains the response from method Client.Decrypt. @@ -41,7 +41,7 @@ type GetDeletedKeyResponse struct { // GetKeyResponse contains the response from method Client.GetKey. type GetKeyResponse struct { - KeyVaultKey + KeyBundle } // GetKeyRotationPolicyResponse contains the response from method Client.GetKeyRotationPolicy. @@ -56,7 +56,7 @@ type GetRandomBytesResponse struct { // ImportKeyResponse contains the response from method Client.ImportKey. type ImportKeyResponse struct { - KeyVaultKey + KeyBundle } // ListDeletedKeyPropertiesResponse contains the response from method Client.NewListDeletedKeyPropertiesPager. @@ -81,7 +81,7 @@ type PurgeDeletedKeyResponse struct { // RecoverDeletedKeyResponse contains the response from method Client.RecoverDeletedKey. type RecoverDeletedKeyResponse struct { - KeyVaultKey + KeyBundle } // ReleaseResponse contains the response from method Client.Release. @@ -91,12 +91,12 @@ type ReleaseResponse struct { // RestoreKeyResponse contains the response from method Client.RestoreKey. type RestoreKeyResponse struct { - KeyVaultKey + KeyBundle } // RotateKeyResponse contains the response from method Client.RotateKey. type RotateKeyResponse struct { - KeyVaultKey + KeyBundle } // SignResponse contains the response from method Client.Sign. @@ -111,7 +111,7 @@ type UnwrapKeyResponse struct { // UpdateKeyResponse contains the response from method Client.UpdateKey. type UpdateKeyResponse struct { - KeyVaultKey + KeyBundle } // UpdateKeyRotationPolicyResponse contains the response from method Client.UpdateKeyRotationPolicy. From 517ecd72ed62fa4fa6c5384fb482635240ab2ee4 Mon Sep 17 00:00:00 2001 From: gracewilcox Date: Tue, 6 Jun 2023 09:58:17 -0700 Subject: [PATCH 10/10] improve testserde --- sdk/security/keyvault/azkeys/utils_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/security/keyvault/azkeys/utils_test.go b/sdk/security/keyvault/azkeys/utils_test.go index 5a88f3fef6df..1423365a88ba 100644 --- a/sdk/security/keyvault/azkeys/utils_test.go +++ b/sdk/security/keyvault/azkeys/utils_test.go @@ -259,12 +259,11 @@ func testSerde[T serdeModel](t *testing.T, model T) { require.NoError(t, err) // testing unmarshal error scenarios - var data2 []byte - err = model.UnmarshalJSON(data2) + err = model.UnmarshalJSON(nil) require.Error(t, err) m := regexp.MustCompile(":.*$") - modifiedData := m.ReplaceAllString(string(data), ":[\"test\", \"test1\", \"test2\"]}") + modifiedData := m.ReplaceAllString(string(data), `:["test", "test1", "test2"]}`) if modifiedData != "{}" { data3 := []byte(modifiedData) err = model.UnmarshalJSON(data3)