diff --git a/sdk/keyvault/azsecrets/CHANGELOG.md b/sdk/keyvault/azsecrets/CHANGELOG.md index 1a9fd2bbad31..4d653cc11b9c 100644 --- a/sdk/keyvault/azsecrets/CHANGELOG.md +++ b/sdk/keyvault/azsecrets/CHANGELOG.md @@ -1,14 +1,9 @@ # Release History -## 0.3.1 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed +## 0.4.0 (2022-01-11) ### Other Changes +* Bumps `azcore` dependency from `v0.20.0` to `v0.21.0` ## 0.3.0 (2021-11-09) diff --git a/sdk/keyvault/azsecrets/autorest.md b/sdk/keyvault/azsecrets/autorest.md index e0665fadc0f6..e18822baa7ab 100644 --- a/sdk/keyvault/azsecrets/autorest.md +++ b/sdk/keyvault/azsecrets/autorest.md @@ -18,7 +18,7 @@ clear-output-folder: false output-folder: internal tag: package-7.2 credential-scope: none -use: "@autorest/go@4.0.0-preview.30" +use: "@autorest/go@4.0.0-preview.35" module-version: 0.2.0 export-clients: true ``` diff --git a/sdk/keyvault/azsecrets/client.go b/sdk/keyvault/azsecrets/client.go index 911e91d4f0a9..fbf9eac71296 100644 --- a/sdk/keyvault/azsecrets/client.go +++ b/sdk/keyvault/azsecrets/client.go @@ -57,10 +57,8 @@ func NewClient(vaultUrl string, credential azcore.TokenCredential, options *Clie shared.NewKeyVaultChallengePolicy(credential), ) - conn := internal.NewConnection(conOptions) - return &Client{ - kvClient: internal.NewKeyVaultClient(conn), + kvClient: internal.NewKeyVaultClient(conOptions), vaultUrl: vaultUrl, }, nil } @@ -272,9 +270,9 @@ func (s *startDeleteSecretPoller) Poll(ctx context.Context) (*http.Response, err s.lastResponse = resp return resp.RawResponse, nil } - var httpResponseErr azcore.HTTPResponse - if errors.As(err, &httpResponseErr) { - if httpResponseErr.RawResponse().StatusCode == http.StatusNotFound { + var httpErr *azcore.ResponseError + if errors.As(err, &httpErr) { + if httpErr.StatusCode == http.StatusNotFound { // This is the expected result return s.deleteResponse.RawResponse, nil } @@ -329,9 +327,9 @@ func (c *Client) BeginDeleteSecret(ctx context.Context, secretName string, optio } getResp, err := c.kvClient.GetDeletedSecret(ctx, c.vaultUrl, secretName, nil) - var httpErr azcore.HTTPResponse + var httpErr *azcore.ResponseError if errors.As(err, &httpErr) { - if httpErr.RawResponse().StatusCode != http.StatusNotFound { + if httpErr.StatusCode != http.StatusNotFound { return DeleteSecretPollerResponse{}, err } } @@ -381,7 +379,7 @@ func getDeletedSecretResponseFromGenerated(i internal.KeyVaultClientGetDeletedSe RecoveryID: i.RecoveryID, DeletedDate: i.DeletedDate, ScheduledPurgeDate: i.ScheduledPurgeDate, - Secret: secretFromGenerated(i.SecretBundle), + Secret: secretFromGenerated(i.DeletedSecretBundle), } } @@ -626,9 +624,9 @@ func (b *beginRecoverPoller) Done() bool { func (b *beginRecoverPoller) Poll(ctx context.Context) (*http.Response, error) { resp, err := b.client.GetSecret(ctx, b.vaultUrl, b.secretName, "", nil) b.lastResponse = resp - var httpErr azcore.HTTPResponse + var httpErr *azcore.ResponseError if errors.As(err, &httpErr) { - return httpErr.RawResponse(), err + return httpErr.RawResponse, err } return resp.RawResponse, nil } @@ -720,9 +718,9 @@ func (c *Client) BeginRecoverDeletedSecret(ctx context.Context, secretName strin } getResp, err := c.kvClient.GetSecret(ctx, c.vaultUrl, secretName, "", nil) - var httpErr azcore.HTTPResponse + var httpErr *azcore.ResponseError if errors.As(err, &httpErr) { - if httpErr.RawResponse().StatusCode != http.StatusNotFound { + if httpErr.StatusCode != http.StatusNotFound { return RecoverDeletedSecretPollerResponse{}, err } } diff --git a/sdk/keyvault/azsecrets/client_test.go b/sdk/keyvault/azsecrets/client_test.go index 462cbcf33f67..d4284d43c543 100644 --- a/sdk/keyvault/azsecrets/client_test.go +++ b/sdk/keyvault/azsecrets/client_test.go @@ -383,13 +383,13 @@ func TestBackupSecret(t *testing.T) { require.NoError(t, err) _, err = client.GetSecret(context.Background(), secret, nil) - var httpErr azcore.HTTPResponse + var httpErr *azcore.ResponseError require.True(t, errors.As(err, &httpErr)) - require.Equal(t, httpErr.RawResponse().StatusCode, http.StatusNotFound) + require.Equal(t, httpErr.RawResponse.StatusCode, http.StatusNotFound) _, err = client.GetDeletedSecret(context.Background(), secret, nil) require.True(t, errors.As(err, &httpErr)) - require.Equal(t, httpErr.RawResponse().StatusCode, http.StatusNotFound) + require.Equal(t, httpErr.RawResponse.StatusCode, http.StatusNotFound) time.Sleep(20 * delay()) diff --git a/sdk/keyvault/azsecrets/go.mod b/sdk/keyvault/azsecrets/go.mod index 2d965f5b3e28..64fbc3f8bcfd 100644 --- a/sdk/keyvault/azsecrets/go.mod +++ b/sdk/keyvault/azsecrets/go.mod @@ -3,8 +3,8 @@ module github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets go 1.16 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0 github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.1.0 github.com/stretchr/testify v1.7.0 diff --git a/sdk/keyvault/azsecrets/go.sum b/sdk/keyvault/azsecrets/go.sum index caa59560af2c..aaadcb37af81 100644 --- a/sdk/keyvault/azsecrets/go.sum +++ b/sdk/keyvault/azsecrets/go.sum @@ -1,20 +1,30 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0 h1:VBvHGLJbaY0+c66NZHdS9cgjHVYSH6DDa0XJMyrblsI= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0/go.mod h1:GJzjM4SR9T0KyX5gKCVyz1ytD8FeWeUPCwtFCt1AyfE= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0 h1:8wVJL0HUP5yDFXvotdewORTw7Yu88JbreWN/mobSvsQ= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0 h1:bLRntPH25SkY1uZ/YZW+dmxNky9r1fAHvDFrzluo+4Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0/go.mod h1:TmXReXZ9yPp5D5TBRMTAtyz+UyOl15Py4hL5E5p6igQ= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm2CYY3CK4spn5OmUIiQtk= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.1.0 h1:Xc2XhOPo5WsyBAX+EsMdg1HZQ0oDJ8Lt4jivIjv4Cak= github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.1.0/go.mod h1:qKJHexVLI0iqKFeV/2WnqbRBQtJTPOMeBdmHOxs+E88= +github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c= +github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= +github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= -github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= +github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= +github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -26,18 +36,23 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNm golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/sdk/keyvault/azsecrets/internal/connection.go b/sdk/keyvault/azsecrets/internal/connection.go deleted file mode 100644 index c7fa89a3946d..000000000000 --- a/sdk/keyvault/azsecrets/internal/connection.go +++ /dev/null @@ -1,37 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package internal - -import ( - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" -) - -// Connection - The key vault client performs cryptographic key operations and vault operations against the Key Vault service. -type Connection struct { - p runtime.Pipeline -} - -// NewConnection creates an instance of the Connection type with the specified endpoint. -// Pass nil to accept the default options; this is the same as passing a zero-value options. -func NewConnection(options *azcore.ClientOptions) *Connection { - cp := azcore.ClientOptions{} - if options != nil { - cp = *options - } - client := &Connection{ - p: runtime.NewPipeline(module, version, nil, nil, &cp), - } - return client -} - -// Pipeline returns the connection's pipeline. -func (c *Connection) Pipeline() runtime.Pipeline { - return c.p -} diff --git a/sdk/keyvault/azsecrets/internal/constants.go b/sdk/keyvault/azsecrets/internal/constants.go index fb7d1a1974d5..e42b8bd37abe 100644 --- a/sdk/keyvault/azsecrets/internal/constants.go +++ b/sdk/keyvault/azsecrets/internal/constants.go @@ -9,8 +9,8 @@ package internal const ( - module = "internal" - version = "v0.3.1" + moduleName = "internal" + moduleVersion = "v0.4.0" ) // DataAction - Supported permissions for data actions. @@ -123,40 +123,43 @@ func (c DataAction) ToPtr() *DataAction { return &c } -// DeletionRecoveryLevel - Reflects the deletion recovery level currently in effect for secrets in the current vault. If it contains 'Purgeable', the secret -// can be permanently deleted by a privileged user; otherwise, only the +// DeletionRecoveryLevel - Reflects the deletion recovery level currently in effect for secrets in the current vault. If it +// contains 'Purgeable', the secret can be permanently deleted by a privileged user; otherwise, only the // system can purge the secret, at the end of the retention interval. type DeletionRecoveryLevel 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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" ) diff --git a/sdk/keyvault/azsecrets/internal/hsmsecuritydomain_client.go b/sdk/keyvault/azsecrets/internal/hsmsecuritydomain_client.go index fd5a309b514e..a65cfa6aef54 100644 --- a/sdk/keyvault/azsecrets/internal/hsmsecuritydomain_client.go +++ b/sdk/keyvault/azsecrets/internal/hsmsecuritydomain_client.go @@ -10,7 +10,7 @@ package internal import ( "context" - "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" @@ -21,53 +21,68 @@ import ( // HSMSecurityDomainClient contains the methods for the HSMSecurityDomain group. // Don't use this type directly, use NewHSMSecurityDomainClient() instead. type HSMSecurityDomainClient struct { - con *Connection + pl runtime.Pipeline } // NewHSMSecurityDomainClient creates a new instance of HSMSecurityDomainClient with the specified values. -func NewHSMSecurityDomainClient(con *Connection) *HSMSecurityDomainClient { - return &HSMSecurityDomainClient{con: con} +// options - pass nil to accept the default values. +func NewHSMSecurityDomainClient(options *azcore.ClientOptions) *HSMSecurityDomainClient { + cp := azcore.ClientOptions{} + if options != nil { + cp = *options + } + client := &HSMSecurityDomainClient{ + pl: runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &cp), + } + return client } -// BeginDownload - Retrieves the Security Domain from the managed HSM. Calling this endpoint can be used to activate a provisioned managed HSM resource. -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) BeginDownload(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainBeginDownloadOptions) (HSMSecurityDomainDownloadPollerResponse, error) { +// BeginDownload - Retrieves the Security Domain from the managed HSM. Calling this endpoint can be used to activate a provisioned +// managed HSM resource. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// certificateInfoObject - The Security Domain download operation requires customer to provide N certificates (minimum 3 and +// maximum 10) containing a public key in JWK format. +// options - HSMSecurityDomainClientBeginDownloadOptions contains the optional parameters for the HSMSecurityDomainClient.BeginDownload +// method. +func (client *HSMSecurityDomainClient) BeginDownload(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainClientBeginDownloadOptions) (HSMSecurityDomainClientDownloadPollerResponse, error) { resp, err := client.download(ctx, vaultBaseURL, certificateInfoObject, options) if err != nil { - return HSMSecurityDomainDownloadPollerResponse{}, err + return HSMSecurityDomainClientDownloadPollerResponse{}, err } - result := HSMSecurityDomainDownloadPollerResponse{ + result := HSMSecurityDomainClientDownloadPollerResponse{ RawResponse: resp, } - pt, err := armruntime.NewPoller("HSMSecurityDomainClient.Download", "azure-async-operation", resp, client.con.Pipeline(), client.downloadHandleError) + pt, err := armruntime.NewPoller("HSMSecurityDomainClient.Download", "azure-async-operation", resp, client.pl) if err != nil { - return HSMSecurityDomainDownloadPollerResponse{}, err + return HSMSecurityDomainClientDownloadPollerResponse{}, err } - result.Poller = &HSMSecurityDomainDownloadPoller{ + result.Poller = &HSMSecurityDomainClientDownloadPoller{ pt: pt, } return result, nil } -// Download - Retrieves the Security Domain from the managed HSM. Calling this endpoint can be used to activate a provisioned managed HSM resource. -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) download(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainBeginDownloadOptions) (*http.Response, error) { +// Download - Retrieves the Security Domain from the managed HSM. Calling this endpoint can be used to activate a provisioned +// managed HSM resource. +// If the operation fails it returns an *azcore.ResponseError type. +func (client *HSMSecurityDomainClient) download(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainClientBeginDownloadOptions) (*http.Response, error) { req, err := client.downloadCreateRequest(ctx, vaultBaseURL, certificateInfoObject, options) if err != nil { return nil, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return nil, err } if !runtime.HasStatusCode(resp, http.StatusAccepted) { - return nil, client.downloadHandleError(resp) + return nil, runtime.NewResponseError(resp) } return resp, nil } // downloadCreateRequest creates the Download request. -func (client *HSMSecurityDomainClient) downloadCreateRequest(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainBeginDownloadOptions) (*policy.Request, error) { +func (client *HSMSecurityDomainClient) downloadCreateRequest(ctx context.Context, vaultBaseURL string, certificateInfoObject CertificateInfoObject, options *HSMSecurityDomainClientBeginDownloadOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/securitydomain/download" @@ -82,38 +97,28 @@ func (client *HSMSecurityDomainClient) downloadCreateRequest(ctx context.Context return req, runtime.MarshalAsJSON(req, certificateInfoObject) } -// downloadHandleError handles the Download error response. -func (client *HSMSecurityDomainClient) downloadHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // DownloadPending - Retrieves the Security Domain download operation status -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) DownloadPending(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainDownloadPendingOptions) (HSMSecurityDomainDownloadPendingResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// options - HSMSecurityDomainClientDownloadPendingOptions contains the optional parameters for the HSMSecurityDomainClient.DownloadPending +// method. +func (client *HSMSecurityDomainClient) DownloadPending(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientDownloadPendingOptions) (HSMSecurityDomainClientDownloadPendingResponse, error) { req, err := client.downloadPendingCreateRequest(ctx, vaultBaseURL, options) if err != nil { - return HSMSecurityDomainDownloadPendingResponse{}, err + return HSMSecurityDomainClientDownloadPendingResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return HSMSecurityDomainDownloadPendingResponse{}, err + return HSMSecurityDomainClientDownloadPendingResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return HSMSecurityDomainDownloadPendingResponse{}, client.downloadPendingHandleError(resp) + return HSMSecurityDomainClientDownloadPendingResponse{}, runtime.NewResponseError(resp) } return client.downloadPendingHandleResponse(resp) } // downloadPendingCreateRequest creates the DownloadPending request. -func (client *HSMSecurityDomainClient) downloadPendingCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainDownloadPendingOptions) (*policy.Request, error) { +func (client *HSMSecurityDomainClient) downloadPendingCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientDownloadPendingOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/securitydomain/download/pending" @@ -126,46 +131,36 @@ func (client *HSMSecurityDomainClient) downloadPendingCreateRequest(ctx context. } // downloadPendingHandleResponse handles the DownloadPending response. -func (client *HSMSecurityDomainClient) downloadPendingHandleResponse(resp *http.Response) (HSMSecurityDomainDownloadPendingResponse, error) { - result := HSMSecurityDomainDownloadPendingResponse{RawResponse: resp} +func (client *HSMSecurityDomainClient) downloadPendingHandleResponse(resp *http.Response) (HSMSecurityDomainClientDownloadPendingResponse, error) { + result := HSMSecurityDomainClientDownloadPendingResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.SecurityDomainOperationStatus); err != nil { - return HSMSecurityDomainDownloadPendingResponse{}, err + return HSMSecurityDomainClientDownloadPendingResponse{}, err } return result, nil } -// downloadPendingHandleError handles the DownloadPending error response. -func (client *HSMSecurityDomainClient) downloadPendingHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // TransferKey - Retrieve Security Domain transfer key -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) TransferKey(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainTransferKeyOptions) (HSMSecurityDomainTransferKeyResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// options - HSMSecurityDomainClientTransferKeyOptions contains the optional parameters for the HSMSecurityDomainClient.TransferKey +// method. +func (client *HSMSecurityDomainClient) TransferKey(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientTransferKeyOptions) (HSMSecurityDomainClientTransferKeyResponse, error) { req, err := client.transferKeyCreateRequest(ctx, vaultBaseURL, options) if err != nil { - return HSMSecurityDomainTransferKeyResponse{}, err + return HSMSecurityDomainClientTransferKeyResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return HSMSecurityDomainTransferKeyResponse{}, err + return HSMSecurityDomainClientTransferKeyResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return HSMSecurityDomainTransferKeyResponse{}, client.transferKeyHandleError(resp) + return HSMSecurityDomainClientTransferKeyResponse{}, runtime.NewResponseError(resp) } return client.transferKeyHandleResponse(resp) } // transferKeyCreateRequest creates the TransferKey request. -func (client *HSMSecurityDomainClient) transferKeyCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainTransferKeyOptions) (*policy.Request, error) { +func (client *HSMSecurityDomainClient) transferKeyCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientTransferKeyOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/securitydomain/upload" @@ -181,66 +176,57 @@ func (client *HSMSecurityDomainClient) transferKeyCreateRequest(ctx context.Cont } // transferKeyHandleResponse handles the TransferKey response. -func (client *HSMSecurityDomainClient) transferKeyHandleResponse(resp *http.Response) (HSMSecurityDomainTransferKeyResponse, error) { - result := HSMSecurityDomainTransferKeyResponse{RawResponse: resp} +func (client *HSMSecurityDomainClient) transferKeyHandleResponse(resp *http.Response) (HSMSecurityDomainClientTransferKeyResponse, error) { + result := HSMSecurityDomainClientTransferKeyResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.TransferKey); err != nil { - return HSMSecurityDomainTransferKeyResponse{}, err + return HSMSecurityDomainClientTransferKeyResponse{}, err } return result, nil } -// transferKeyHandleError handles the TransferKey error response. -func (client *HSMSecurityDomainClient) transferKeyHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // BeginUpload - Restore the provided Security Domain. -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) BeginUpload(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainBeginUploadOptions) (HSMSecurityDomainUploadPollerResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// securityDomain - The Security Domain to be restored. +// options - HSMSecurityDomainClientBeginUploadOptions contains the optional parameters for the HSMSecurityDomainClient.BeginUpload +// method. +func (client *HSMSecurityDomainClient) BeginUpload(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainClientBeginUploadOptions) (HSMSecurityDomainClientUploadPollerResponse, error) { resp, err := client.upload(ctx, vaultBaseURL, securityDomain, options) if err != nil { - return HSMSecurityDomainUploadPollerResponse{}, err + return HSMSecurityDomainClientUploadPollerResponse{}, err } - result := HSMSecurityDomainUploadPollerResponse{ + result := HSMSecurityDomainClientUploadPollerResponse{ RawResponse: resp, } - pt, err := armruntime.NewPoller("HSMSecurityDomainClient.Upload", "azure-async-operation", resp, client.con.Pipeline(), client.uploadHandleError) + pt, err := armruntime.NewPoller("HSMSecurityDomainClient.Upload", "azure-async-operation", resp, client.pl) if err != nil { - return HSMSecurityDomainUploadPollerResponse{}, err + return HSMSecurityDomainClientUploadPollerResponse{}, err } - result.Poller = &HSMSecurityDomainUploadPoller{ + result.Poller = &HSMSecurityDomainClientUploadPoller{ pt: pt, } return result, nil } // Upload - Restore the provided Security Domain. -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) upload(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainBeginUploadOptions) (*http.Response, error) { +// If the operation fails it returns an *azcore.ResponseError type. +func (client *HSMSecurityDomainClient) upload(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainClientBeginUploadOptions) (*http.Response, error) { req, err := client.uploadCreateRequest(ctx, vaultBaseURL, securityDomain, options) if err != nil { return nil, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return nil, err } if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { - return nil, client.uploadHandleError(resp) + return nil, runtime.NewResponseError(resp) } return resp, nil } // uploadCreateRequest creates the Upload request. -func (client *HSMSecurityDomainClient) uploadCreateRequest(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainBeginUploadOptions) (*policy.Request, error) { +func (client *HSMSecurityDomainClient) uploadCreateRequest(ctx context.Context, vaultBaseURL string, securityDomain SecurityDomainObject, options *HSMSecurityDomainClientBeginUploadOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/securitydomain/upload" @@ -252,38 +238,28 @@ func (client *HSMSecurityDomainClient) uploadCreateRequest(ctx context.Context, return req, runtime.MarshalAsJSON(req, securityDomain) } -// uploadHandleError handles the Upload error response. -func (client *HSMSecurityDomainClient) uploadHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // UploadPending - Get Security Domain upload operation status -// If the operation fails it returns the *KeyVaultError error type. -func (client *HSMSecurityDomainClient) UploadPending(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainUploadPendingOptions) (HSMSecurityDomainUploadPendingResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// options - HSMSecurityDomainClientUploadPendingOptions contains the optional parameters for the HSMSecurityDomainClient.UploadPending +// method. +func (client *HSMSecurityDomainClient) UploadPending(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientUploadPendingOptions) (HSMSecurityDomainClientUploadPendingResponse, error) { req, err := client.uploadPendingCreateRequest(ctx, vaultBaseURL, options) if err != nil { - return HSMSecurityDomainUploadPendingResponse{}, err + return HSMSecurityDomainClientUploadPendingResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return HSMSecurityDomainUploadPendingResponse{}, err + return HSMSecurityDomainClientUploadPendingResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return HSMSecurityDomainUploadPendingResponse{}, client.uploadPendingHandleError(resp) + return HSMSecurityDomainClientUploadPendingResponse{}, runtime.NewResponseError(resp) } return client.uploadPendingHandleResponse(resp) } // uploadPendingCreateRequest creates the UploadPending request. -func (client *HSMSecurityDomainClient) uploadPendingCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainUploadPendingOptions) (*policy.Request, error) { +func (client *HSMSecurityDomainClient) uploadPendingCreateRequest(ctx context.Context, vaultBaseURL string, options *HSMSecurityDomainClientUploadPendingOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/securitydomain/upload/pending" @@ -296,23 +272,10 @@ func (client *HSMSecurityDomainClient) uploadPendingCreateRequest(ctx context.Co } // uploadPendingHandleResponse handles the UploadPending response. -func (client *HSMSecurityDomainClient) uploadPendingHandleResponse(resp *http.Response) (HSMSecurityDomainUploadPendingResponse, error) { - result := HSMSecurityDomainUploadPendingResponse{RawResponse: resp} +func (client *HSMSecurityDomainClient) uploadPendingHandleResponse(resp *http.Response) (HSMSecurityDomainClientUploadPendingResponse, error) { + result := HSMSecurityDomainClientUploadPendingResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.SecurityDomainOperationStatus); err != nil { - return HSMSecurityDomainUploadPendingResponse{}, err + return HSMSecurityDomainClientUploadPendingResponse{}, err } return result, nil } - -// uploadPendingHandleError handles the UploadPending error response. -func (client *HSMSecurityDomainClient) uploadPendingHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} diff --git a/sdk/keyvault/azsecrets/internal/keyvaultclient_client.go b/sdk/keyvault/azsecrets/internal/keyvault_client.go similarity index 71% rename from sdk/keyvault/azsecrets/internal/keyvaultclient_client.go rename to sdk/keyvault/azsecrets/internal/keyvault_client.go index 9ca6a48c7f68..e02b387243ed 100644 --- a/sdk/keyvault/azsecrets/internal/keyvaultclient_client.go +++ b/sdk/keyvault/azsecrets/internal/keyvault_client.go @@ -11,7 +11,7 @@ package internal import ( "context" "errors" - "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -23,28 +23,39 @@ import ( // KeyVaultClient contains the methods for the KeyVaultClient group. // Don't use this type directly, use NewKeyVaultClient() instead. type KeyVaultClient struct { - con *Connection + pl runtime.Pipeline } // NewKeyVaultClient creates a new instance of KeyVaultClient with the specified values. -func NewKeyVaultClient(con *Connection) *KeyVaultClient { - return &KeyVaultClient{con: con} +// options - pass nil to accept the default values. +func NewKeyVaultClient(options *azcore.ClientOptions) *KeyVaultClient { + cp := azcore.ClientOptions{} + if options != nil { + cp = *options + } + client := &KeyVaultClient{ + pl: runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &cp), + } + return client } -// BackupSecret - Requests that a backup of the specified secret be downloaded to the client. All versions of the secret will be downloaded. This operation -// requires the secrets/backup permission. -// If the operation fails it returns the *KeyVaultError error type. +// BackupSecret - Requests that a backup of the specified secret be downloaded to the client. All versions of the secret will +// be downloaded. This operation requires the secrets/backup permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// options - KeyVaultClientBackupSecretOptions contains the optional parameters for the KeyVaultClient.BackupSecret method. func (client *KeyVaultClient) BackupSecret(ctx context.Context, vaultBaseURL string, secretName string, options *KeyVaultClientBackupSecretOptions) (KeyVaultClientBackupSecretResponse, error) { req, err := client.backupSecretCreateRequest(ctx, vaultBaseURL, secretName, options) if err != nil { return KeyVaultClientBackupSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientBackupSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientBackupSecretResponse{}, client.backupSecretHandleError(resp) + return KeyVaultClientBackupSecretResponse{}, runtime.NewResponseError(resp) } return client.backupSecretHandleResponse(resp) } @@ -78,33 +89,23 @@ func (client *KeyVaultClient) backupSecretHandleResponse(resp *http.Response) (K return result, nil } -// backupSecretHandleError handles the BackupSecret error response. -func (client *KeyVaultClient) backupSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// DeleteSecret - The DELETE operation applies to any secret stored in Azure Key Vault. DELETE cannot be applied to an individual version of a secret. This -// operation requires the secrets/delete permission. -// If the operation fails it returns the *KeyVaultError error type. +// DeleteSecret - The DELETE operation applies to any secret stored in Azure Key Vault. DELETE cannot be applied to an individual +// version of a secret. This operation requires the secrets/delete permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// options - KeyVaultClientDeleteSecretOptions contains the optional parameters for the KeyVaultClient.DeleteSecret method. func (client *KeyVaultClient) DeleteSecret(ctx context.Context, vaultBaseURL string, secretName string, options *KeyVaultClientDeleteSecretOptions) (KeyVaultClientDeleteSecretResponse, error) { req, err := client.deleteSecretCreateRequest(ctx, vaultBaseURL, secretName, options) if err != nil { return KeyVaultClientDeleteSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientDeleteSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientDeleteSecretResponse{}, client.deleteSecretHandleError(resp) + return KeyVaultClientDeleteSecretResponse{}, runtime.NewResponseError(resp) } return client.deleteSecretHandleResponse(resp) } @@ -138,33 +139,24 @@ func (client *KeyVaultClient) deleteSecretHandleResponse(resp *http.Response) (K return result, nil } -// deleteSecretHandleError handles the DeleteSecret error response. -func (client *KeyVaultClient) deleteSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// GetDeletedSecret - The Get Deleted Secret operation returns the specified deleted secret along with its attributes. This operation requires the secrets/get -// permission. -// If the operation fails it returns the *KeyVaultError error type. +// GetDeletedSecret - The Get Deleted Secret operation returns the specified deleted secret along with its attributes. This +// operation requires the secrets/get permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// options - KeyVaultClientGetDeletedSecretOptions contains the optional parameters for the KeyVaultClient.GetDeletedSecret +// method. func (client *KeyVaultClient) GetDeletedSecret(ctx context.Context, vaultBaseURL string, secretName string, options *KeyVaultClientGetDeletedSecretOptions) (KeyVaultClientGetDeletedSecretResponse, error) { req, err := client.getDeletedSecretCreateRequest(ctx, vaultBaseURL, secretName, options) if err != nil { return KeyVaultClientGetDeletedSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientGetDeletedSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientGetDeletedSecretResponse{}, client.getDeletedSecretHandleError(resp) + return KeyVaultClientGetDeletedSecretResponse{}, runtime.NewResponseError(resp) } return client.getDeletedSecretHandleResponse(resp) } @@ -198,22 +190,12 @@ func (client *KeyVaultClient) getDeletedSecretHandleResponse(resp *http.Response return result, nil } -// getDeletedSecretHandleError handles the GetDeletedSecret error response. -func (client *KeyVaultClient) getDeletedSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// GetDeletedSecrets - The Get Deleted Secrets operation returns the secrets that have been deleted for a vault enabled for soft-delete. This operation -// requires the secrets/list permission. -// If the operation fails it returns the *KeyVaultError error type. +// GetDeletedSecrets - The Get Deleted Secrets operation returns the secrets that have been deleted for a vault enabled for +// soft-delete. This operation requires the secrets/list permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// options - KeyVaultClientGetDeletedSecretsOptions contains the optional parameters for the KeyVaultClient.GetDeletedSecrets +// method. func (client *KeyVaultClient) GetDeletedSecrets(vaultBaseURL string, options *KeyVaultClientGetDeletedSecretsOptions) *KeyVaultClientGetDeletedSecretsPager { return &KeyVaultClientGetDeletedSecretsPager{ client: client, @@ -254,32 +236,25 @@ func (client *KeyVaultClient) getDeletedSecretsHandleResponse(resp *http.Respons return result, nil } -// getDeletedSecretsHandleError handles the GetDeletedSecrets error response. -func (client *KeyVaultClient) getDeletedSecretsHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// GetSecret - The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission. -// If the operation fails it returns the *KeyVaultError error type. +// GetSecret - The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get +// permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// secretVersion - The version of the secret. This URI fragment is optional. If not specified, the latest version of the secret +// is returned. +// options - KeyVaultClientGetSecretOptions contains the optional parameters for the KeyVaultClient.GetSecret method. func (client *KeyVaultClient) GetSecret(ctx context.Context, vaultBaseURL string, secretName string, secretVersion string, options *KeyVaultClientGetSecretOptions) (KeyVaultClientGetSecretResponse, error) { req, err := client.getSecretCreateRequest(ctx, vaultBaseURL, secretName, secretVersion, options) if err != nil { return KeyVaultClientGetSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientGetSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientGetSecretResponse{}, client.getSecretHandleError(resp) + return KeyVaultClientGetSecretResponse{}, runtime.NewResponseError(resp) } return client.getSecretHandleResponse(resp) } @@ -317,22 +292,13 @@ func (client *KeyVaultClient) getSecretHandleResponse(resp *http.Response) (KeyV return result, nil } -// getSecretHandleError handles the GetSecret error response. -func (client *KeyVaultClient) getSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// GetSecretVersions - The full secret identifier and attributes are provided in the response. No values are returned for the secrets. This operations requires -// the secrets/list permission. -// If the operation fails it returns the *KeyVaultError error type. +// GetSecretVersions - The full secret identifier and attributes are provided in the response. No values are returned for +// the secrets. This operations requires the secrets/list permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// options - KeyVaultClientGetSecretVersionsOptions contains the optional parameters for the KeyVaultClient.GetSecretVersions +// method. func (client *KeyVaultClient) GetSecretVersions(vaultBaseURL string, secretName string, options *KeyVaultClientGetSecretVersionsOptions) *KeyVaultClientGetSecretVersionsPager { return &KeyVaultClientGetSecretVersionsPager{ client: client, @@ -377,23 +343,12 @@ func (client *KeyVaultClient) getSecretVersionsHandleResponse(resp *http.Respons return result, nil } -// getSecretVersionsHandleError handles the GetSecretVersions error response. -func (client *KeyVaultClient) getSecretVersionsHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// GetSecrets - The Get Secrets operation is applicable to the entire vault. However, only the base secret identifier and its attributes are provided in -// the response. Individual secret versions are not listed in the +// GetSecrets - The Get Secrets operation is applicable to the entire vault. However, only the base secret identifier and +// its attributes are provided in the response. Individual secret versions are not listed in the // response. This operation requires the secrets/list permission. -// If the operation fails it returns the *KeyVaultError error type. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// options - KeyVaultClientGetSecretsOptions contains the optional parameters for the KeyVaultClient.GetSecrets method. func (client *KeyVaultClient) GetSecrets(vaultBaseURL string, options *KeyVaultClientGetSecretsOptions) *KeyVaultClientGetSecretsPager { return &KeyVaultClientGetSecretsPager{ client: client, @@ -434,34 +389,25 @@ func (client *KeyVaultClient) getSecretsHandleResponse(resp *http.Response) (Key return result, nil } -// getSecretsHandleError handles the GetSecrets error response. -func (client *KeyVaultClient) getSecretsHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// PurgeDeletedSecret - The purge deleted secret operation removes the secret permanently, without the possibility of recovery. This operation can only -// be enabled on a soft-delete enabled vault. This operation requires the +// PurgeDeletedSecret - The purge deleted secret operation removes the secret permanently, without the possibility of recovery. +// This operation can only be enabled on a soft-delete enabled vault. This operation requires the // secrets/purge permission. -// If the operation fails it returns the *KeyVaultError error type. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// options - KeyVaultClientPurgeDeletedSecretOptions contains the optional parameters for the KeyVaultClient.PurgeDeletedSecret +// method. func (client *KeyVaultClient) PurgeDeletedSecret(ctx context.Context, vaultBaseURL string, secretName string, options *KeyVaultClientPurgeDeletedSecretOptions) (KeyVaultClientPurgeDeletedSecretResponse, error) { req, err := client.purgeDeletedSecretCreateRequest(ctx, vaultBaseURL, secretName, options) if err != nil { return KeyVaultClientPurgeDeletedSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientPurgeDeletedSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusNoContent) { - return KeyVaultClientPurgeDeletedSecretResponse{}, client.purgeDeletedSecretHandleError(resp) + return KeyVaultClientPurgeDeletedSecretResponse{}, runtime.NewResponseError(resp) } return KeyVaultClientPurgeDeletedSecretResponse{RawResponse: resp}, nil } @@ -486,33 +432,24 @@ func (client *KeyVaultClient) purgeDeletedSecretCreateRequest(ctx context.Contex return req, nil } -// purgeDeletedSecretHandleError handles the PurgeDeletedSecret error response. -func (client *KeyVaultClient) purgeDeletedSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// RecoverDeletedSecret - Recovers the deleted secret in the specified vault. This operation can only be performed on a soft-delete enabled vault. This -// operation requires the secrets/recover permission. -// If the operation fails it returns the *KeyVaultError error type. +// RecoverDeletedSecret - Recovers the deleted secret in the specified vault. This operation can only be performed on a soft-delete +// enabled vault. This operation requires the secrets/recover permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the deleted secret. +// options - KeyVaultClientRecoverDeletedSecretOptions contains the optional parameters for the KeyVaultClient.RecoverDeletedSecret +// method. func (client *KeyVaultClient) RecoverDeletedSecret(ctx context.Context, vaultBaseURL string, secretName string, options *KeyVaultClientRecoverDeletedSecretOptions) (KeyVaultClientRecoverDeletedSecretResponse, error) { req, err := client.recoverDeletedSecretCreateRequest(ctx, vaultBaseURL, secretName, options) if err != nil { return KeyVaultClientRecoverDeletedSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientRecoverDeletedSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientRecoverDeletedSecretResponse{}, client.recoverDeletedSecretHandleError(resp) + return KeyVaultClientRecoverDeletedSecretResponse{}, runtime.NewResponseError(resp) } return client.recoverDeletedSecretHandleResponse(resp) } @@ -546,32 +483,23 @@ func (client *KeyVaultClient) recoverDeletedSecretHandleResponse(resp *http.Resp return result, nil } -// recoverDeletedSecretHandleError handles the RecoverDeletedSecret error response. -func (client *KeyVaultClient) recoverDeletedSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// RestoreSecret - Restores a backed up secret, and all its versions, to a vault. This operation requires the secrets/restore permission. -// If the operation fails it returns the *KeyVaultError error type. +// RestoreSecret - Restores a backed up secret, and all its versions, to a vault. This operation requires the secrets/restore +// permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// parameters - The parameters to restore the secret. +// options - KeyVaultClientRestoreSecretOptions contains the optional parameters for the KeyVaultClient.RestoreSecret method. func (client *KeyVaultClient) RestoreSecret(ctx context.Context, vaultBaseURL string, parameters SecretRestoreParameters, options *KeyVaultClientRestoreSecretOptions) (KeyVaultClientRestoreSecretResponse, error) { req, err := client.restoreSecretCreateRequest(ctx, vaultBaseURL, parameters, options) if err != nil { return KeyVaultClientRestoreSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientRestoreSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientRestoreSecretResponse{}, client.restoreSecretHandleError(resp) + return KeyVaultClientRestoreSecretResponse{}, runtime.NewResponseError(resp) } return client.restoreSecretHandleResponse(resp) } @@ -601,33 +529,24 @@ func (client *KeyVaultClient) restoreSecretHandleResponse(resp *http.Response) ( return result, nil } -// restoreSecretHandleError handles the RestoreSecret error response. -func (client *KeyVaultClient) restoreSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// SetSecret - The SET operation adds a secret to the Azure Key Vault. If the named secret already exists, Azure Key Vault creates a new version of that -// secret. This operation requires the secrets/set permission. -// If the operation fails it returns the *KeyVaultError error type. +// SetSecret - The SET operation adds a secret to the Azure Key Vault. If the named secret already exists, Azure Key Vault +// creates a new version of that secret. This operation requires the secrets/set permission. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// parameters - The parameters for setting the secret. +// options - KeyVaultClientSetSecretOptions contains the optional parameters for the KeyVaultClient.SetSecret method. func (client *KeyVaultClient) SetSecret(ctx context.Context, vaultBaseURL string, secretName string, parameters SecretSetParameters, options *KeyVaultClientSetSecretOptions) (KeyVaultClientSetSecretResponse, error) { req, err := client.setSecretCreateRequest(ctx, vaultBaseURL, secretName, parameters, options) if err != nil { return KeyVaultClientSetSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientSetSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientSetSecretResponse{}, client.setSecretHandleError(resp) + return KeyVaultClientSetSecretResponse{}, runtime.NewResponseError(resp) } return client.setSecretHandleResponse(resp) } @@ -661,34 +580,26 @@ func (client *KeyVaultClient) setSecretHandleResponse(resp *http.Response) (KeyV return result, nil } -// setSecretHandleError handles the SetSecret error response. -func (client *KeyVaultClient) setSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - -// UpdateSecret - The UPDATE operation changes specified attributes of an existing stored secret. Attributes that are not specified in the request are left -// unchanged. The value of a secret itself cannot be changed. +// UpdateSecret - The UPDATE operation changes specified attributes of an existing stored secret. Attributes that are not +// specified in the request are left unchanged. The value of a secret itself cannot be changed. // This operation requires the secrets/set permission. -// If the operation fails it returns the *KeyVaultError error type. +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// secretName - The name of the secret. +// secretVersion - The version of the secret. +// parameters - The parameters for update secret operation. +// options - KeyVaultClientUpdateSecretOptions contains the optional parameters for the KeyVaultClient.UpdateSecret method. func (client *KeyVaultClient) UpdateSecret(ctx context.Context, vaultBaseURL string, secretName string, secretVersion string, parameters SecretUpdateParameters, options *KeyVaultClientUpdateSecretOptions) (KeyVaultClientUpdateSecretResponse, error) { req, err := client.updateSecretCreateRequest(ctx, vaultBaseURL, secretName, secretVersion, parameters, options) if err != nil { return KeyVaultClientUpdateSecretResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { return KeyVaultClientUpdateSecretResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return KeyVaultClientUpdateSecretResponse{}, client.updateSecretHandleError(resp) + return KeyVaultClientUpdateSecretResponse{}, runtime.NewResponseError(resp) } return client.updateSecretHandleResponse(resp) } @@ -725,16 +636,3 @@ func (client *KeyVaultClient) updateSecretHandleResponse(resp *http.Response) (K } return result, nil } - -// updateSecretHandleError handles the UpdateSecret error response. -func (client *KeyVaultClient) updateSecretHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} diff --git a/sdk/keyvault/azsecrets/internal/models.go b/sdk/keyvault/azsecrets/internal/models.go index 054e2eb95fa7..327c379db41a 100644 --- a/sdk/keyvault/azsecrets/internal/models.go +++ b/sdk/keyvault/azsecrets/internal/models.go @@ -37,7 +37,11 @@ type Attributes struct { // MarshalJSON implements the json.Marshaller interface for type Attributes. func (a Attributes) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - a.marshalInternal(objectMap) + populateTimeUnix(objectMap, "created", a.Created) + populate(objectMap, "enabled", a.Enabled) + populateTimeUnix(objectMap, "exp", a.Expires) + populateTimeUnix(objectMap, "nbf", a.NotBefore) + populateTimeUnix(objectMap, "updated", a.Updated) return json.Marshal(objectMap) } @@ -47,18 +51,6 @@ func (a *Attributes) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(data, &rawMsg); err != nil { return err } - return a.unmarshalInternal(rawMsg) -} - -func (a Attributes) marshalInternal(objectMap map[string]interface{}) { - populateTimeUnix(objectMap, "created", a.Created) - populate(objectMap, "enabled", a.Enabled) - populateTimeUnix(objectMap, "exp", a.Expires) - populateTimeUnix(objectMap, "nbf", a.NotBefore) - populateTimeUnix(objectMap, "updated", a.Updated) -} - -func (a *Attributes) unmarshalInternal(rawMsg map[string]json.RawMessage) error { for key, val := range rawMsg { var err error switch key { @@ -134,15 +126,38 @@ func (c CertificateInfoObject) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } -// DeletedSecretBundle - A Deleted Secret consisting of its previous id, attributes and its tags, as well as information on when it will be purged. +// DeletedSecretBundle - A Deleted Secret consisting of its previous id, attributes and its tags, as well as information on +// when it will be purged. type DeletedSecretBundle struct { - SecretBundle + // The secret management attributes. + Attributes *SecretAttributes `json:"attributes,omitempty"` + + // The content type of the secret. + ContentType *string `json:"contentType,omitempty"` + + // The secret id. + ID *string `json:"id,omitempty"` + // The url of the recovery object, used to identify and recover the deleted secret. RecoveryID *string `json:"recoveryId,omitempty"` + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` + + // The secret value. + Value *string `json:"value,omitempty"` + // READ-ONLY; The time when the secret was deleted, in UTC DeletedDate *time.Time `json:"deletedDate,omitempty" azure:"ro"` + // READ-ONLY; If this is a secret backing a KV certificate, then this field specifies the corresponding key backing the KV + // certificate. + Kid *string `json:"kid,omitempty" azure:"ro"` + + // READ-ONLY; True if the secret's lifetime is managed by key vault. If this is a secret backing a certificate, then managed + // will be true. + Managed *bool `json:"managed,omitempty" azure:"ro"` + // READ-ONLY; The time when the secret is scheduled to be purged, in UTC ScheduledPurgeDate *time.Time `json:"scheduledPurgeDate,omitempty" azure:"ro"` } @@ -150,10 +165,16 @@ type DeletedSecretBundle struct { // MarshalJSON implements the json.Marshaller interface for type DeletedSecretBundle. func (d DeletedSecretBundle) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - d.SecretBundle.marshalInternal(objectMap) + populate(objectMap, "attributes", d.Attributes) + populate(objectMap, "contentType", d.ContentType) populateTimeUnix(objectMap, "deletedDate", d.DeletedDate) + populate(objectMap, "id", d.ID) + populate(objectMap, "kid", d.Kid) + populate(objectMap, "managed", d.Managed) populate(objectMap, "recoveryId", d.RecoveryID) populateTimeUnix(objectMap, "scheduledPurgeDate", d.ScheduledPurgeDate) + populate(objectMap, "tags", d.Tags) + populate(objectMap, "value", d.Value) return json.Marshal(objectMap) } @@ -166,35 +187,68 @@ func (d *DeletedSecretBundle) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { + case "attributes": + err = unpopulate(val, &d.Attributes) + delete(rawMsg, key) + case "contentType": + err = unpopulate(val, &d.ContentType) + delete(rawMsg, key) case "deletedDate": err = unpopulateTimeUnix(val, &d.DeletedDate) delete(rawMsg, key) + case "id": + err = unpopulate(val, &d.ID) + delete(rawMsg, key) + case "kid": + err = unpopulate(val, &d.Kid) + delete(rawMsg, key) + case "managed": + err = unpopulate(val, &d.Managed) + delete(rawMsg, key) case "recoveryId": err = unpopulate(val, &d.RecoveryID) delete(rawMsg, key) case "scheduledPurgeDate": err = unpopulateTimeUnix(val, &d.ScheduledPurgeDate) delete(rawMsg, key) + case "tags": + err = unpopulate(val, &d.Tags) + delete(rawMsg, key) + case "value": + err = unpopulate(val, &d.Value) + delete(rawMsg, key) } if err != nil { return err } } - if err := d.SecretBundle.unmarshalInternal(rawMsg); err != nil { - return err - } return nil } // DeletedSecretItem - The deleted secret item containing metadata about the deleted secret. type DeletedSecretItem struct { - SecretItem + // The secret management attributes. + Attributes *SecretAttributes `json:"attributes,omitempty"` + + // Type of the secret value such as a password. + ContentType *string `json:"contentType,omitempty"` + + // Secret identifier. + ID *string `json:"id,omitempty"` + // The url of the recovery object, used to identify and recover the deleted secret. RecoveryID *string `json:"recoveryId,omitempty"` + // Application specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` + // READ-ONLY; The time when the secret was deleted, in UTC DeletedDate *time.Time `json:"deletedDate,omitempty" azure:"ro"` + // READ-ONLY; True if the secret'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"` + // READ-ONLY; The time when the secret is scheduled to be purged, in UTC ScheduledPurgeDate *time.Time `json:"scheduledPurgeDate,omitempty" azure:"ro"` } @@ -202,10 +256,14 @@ type DeletedSecretItem struct { // MarshalJSON implements the json.Marshaller interface for type DeletedSecretItem. func (d DeletedSecretItem) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - d.SecretItem.marshalInternal(objectMap) + populate(objectMap, "attributes", d.Attributes) + populate(objectMap, "contentType", d.ContentType) populateTimeUnix(objectMap, "deletedDate", d.DeletedDate) + populate(objectMap, "id", d.ID) + populate(objectMap, "managed", d.Managed) populate(objectMap, "recoveryId", d.RecoveryID) populateTimeUnix(objectMap, "scheduledPurgeDate", d.ScheduledPurgeDate) + populate(objectMap, "tags", d.Tags) return json.Marshal(objectMap) } @@ -218,23 +276,35 @@ func (d *DeletedSecretItem) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { + case "attributes": + err = unpopulate(val, &d.Attributes) + delete(rawMsg, key) + case "contentType": + err = unpopulate(val, &d.ContentType) + delete(rawMsg, key) case "deletedDate": err = unpopulateTimeUnix(val, &d.DeletedDate) delete(rawMsg, key) + case "id": + err = unpopulate(val, &d.ID) + delete(rawMsg, key) + case "managed": + err = unpopulate(val, &d.Managed) + delete(rawMsg, key) case "recoveryId": err = unpopulate(val, &d.RecoveryID) delete(rawMsg, key) case "scheduledPurgeDate": err = unpopulateTimeUnix(val, &d.ScheduledPurgeDate) delete(rawMsg, key) + case "tags": + err = unpopulate(val, &d.Tags) + delete(rawMsg, key) } if err != nil { return err } } - if err := d.SecretItem.unmarshalInternal(rawMsg); err != nil { - return err - } return nil } @@ -243,7 +313,8 @@ type DeletedSecretListResult struct { // READ-ONLY; The URL to get the next set of deleted secrets. NextLink *string `json:"nextLink,omitempty" azure:"ro"` - // READ-ONLY; A response message containing a list of the deleted secrets in the vault along with a link to the next page of deleted secrets + // READ-ONLY; A response message containing a list of the deleted secrets in the vault along with a link to the next page + // of deleted secrets Value []*DeletedSecretItem `json:"value,omitempty" azure:"ro"` } @@ -267,28 +338,33 @@ type Error struct { Message *string `json:"message,omitempty" azure:"ro"` } -// HSMSecurityDomainBeginDownloadOptions contains the optional parameters for the HSMSecurityDomain.BeginDownload method. -type HSMSecurityDomainBeginDownloadOptions struct { +// HSMSecurityDomainClientBeginDownloadOptions contains the optional parameters for the HSMSecurityDomainClient.BeginDownload +// method. +type HSMSecurityDomainClientBeginDownloadOptions struct { // placeholder for future optional parameters } -// HSMSecurityDomainBeginUploadOptions contains the optional parameters for the HSMSecurityDomain.BeginUpload method. -type HSMSecurityDomainBeginUploadOptions struct { +// HSMSecurityDomainClientBeginUploadOptions contains the optional parameters for the HSMSecurityDomainClient.BeginUpload +// method. +type HSMSecurityDomainClientBeginUploadOptions struct { // placeholder for future optional parameters } -// HSMSecurityDomainDownloadPendingOptions contains the optional parameters for the HSMSecurityDomain.DownloadPending method. -type HSMSecurityDomainDownloadPendingOptions struct { +// HSMSecurityDomainClientDownloadPendingOptions contains the optional parameters for the HSMSecurityDomainClient.DownloadPending +// method. +type HSMSecurityDomainClientDownloadPendingOptions struct { // placeholder for future optional parameters } -// HSMSecurityDomainTransferKeyOptions contains the optional parameters for the HSMSecurityDomain.TransferKey method. -type HSMSecurityDomainTransferKeyOptions struct { +// HSMSecurityDomainClientTransferKeyOptions contains the optional parameters for the HSMSecurityDomainClient.TransferKey +// method. +type HSMSecurityDomainClientTransferKeyOptions struct { // placeholder for future optional parameters } -// HSMSecurityDomainUploadPendingOptions contains the optional parameters for the HSMSecurityDomain.UploadPending method. -type HSMSecurityDomainUploadPendingOptions struct { +// HSMSecurityDomainClientUploadPendingOptions contains the optional parameters for the HSMSecurityDomainClient.UploadPending +// method. +type HSMSecurityDomainClientUploadPendingOptions struct { // placeholder for future optional parameters } @@ -335,7 +411,8 @@ type KeyVaultClientPurgeDeletedSecretOptions struct { // placeholder for future optional parameters } -// KeyVaultClientRecoverDeletedSecretOptions contains the optional parameters for the KeyVaultClient.RecoverDeletedSecret method. +// KeyVaultClientRecoverDeletedSecretOptions contains the optional parameters for the KeyVaultClient.RecoverDeletedSecret +// method. type KeyVaultClientRecoverDeletedSecretOptions struct { // placeholder for future optional parameters } @@ -356,17 +433,9 @@ type KeyVaultClientUpdateSecretOptions struct { } // KeyVaultError - The key vault error exception. -// Implements the error and azcore.HTTPResponse interfaces. type KeyVaultError struct { - raw string // READ-ONLY; The key vault server error. - InnerError *Error `json:"error,omitempty" azure:"ro"` -} - -// Error implements the error interface for type KeyVaultError. -// The contents of the error text are not contractual and subject to change. -func (e KeyVaultError) Error() string { - return e.raw + Error *Error `json:"error,omitempty" azure:"ro"` } // Permission - Role definition permissions. @@ -440,8 +509,8 @@ func (r RoleAssignmentListResult) MarshalJSON() ([]byte, error) { // RoleAssignmentProperties - Role assignment properties. type RoleAssignmentProperties struct { - // REQUIRED; The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, service principal, or security - // group. + // REQUIRED; The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, + // service principal, or security group. PrincipalID *string `json:"principalId,omitempty"` // REQUIRED; The role definition ID used in the role assignment. @@ -460,25 +529,26 @@ type RoleAssignmentPropertiesWithScope struct { Scope *RoleScope `json:"scope,omitempty"` } -// RoleAssignmentsCreateOptions contains the optional parameters for the RoleAssignments.Create method. -type RoleAssignmentsCreateOptions struct { +// RoleAssignmentsClientCreateOptions contains the optional parameters for the RoleAssignmentsClient.Create method. +type RoleAssignmentsClientCreateOptions struct { // placeholder for future optional parameters } -// RoleAssignmentsDeleteOptions contains the optional parameters for the RoleAssignments.Delete method. -type RoleAssignmentsDeleteOptions struct { +// RoleAssignmentsClientDeleteOptions contains the optional parameters for the RoleAssignmentsClient.Delete method. +type RoleAssignmentsClientDeleteOptions struct { // placeholder for future optional parameters } -// RoleAssignmentsGetOptions contains the optional parameters for the RoleAssignments.Get method. -type RoleAssignmentsGetOptions struct { +// RoleAssignmentsClientGetOptions contains the optional parameters for the RoleAssignmentsClient.Get method. +type RoleAssignmentsClientGetOptions struct { // placeholder for future optional parameters } -// RoleAssignmentsListForScopeOptions contains the optional parameters for the RoleAssignments.ListForScope method. -type RoleAssignmentsListForScopeOptions struct { - // The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or above the scope. Use $filter=principalId eq {id} to - // return all role assignments at, above or below the scope for the specified principal. +// RoleAssignmentsClientListForScopeOptions contains the optional parameters for the RoleAssignmentsClient.ListForScope method. +type RoleAssignmentsClientListForScopeOptions struct { + // The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or above the scope. Use $filter=principalId + // eq {id} to return all role assignments at, above or below the + // scope for the specified principal. Filter *string } @@ -555,45 +625,64 @@ func (r RoleDefinitionProperties) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } -// RoleDefinitionsCreateOrUpdateOptions contains the optional parameters for the RoleDefinitions.CreateOrUpdate method. -type RoleDefinitionsCreateOrUpdateOptions struct { +// RoleDefinitionsClientCreateOrUpdateOptions contains the optional parameters for the RoleDefinitionsClient.CreateOrUpdate +// method. +type RoleDefinitionsClientCreateOrUpdateOptions struct { // placeholder for future optional parameters } -// RoleDefinitionsDeleteOptions contains the optional parameters for the RoleDefinitions.Delete method. -type RoleDefinitionsDeleteOptions struct { +// RoleDefinitionsClientDeleteOptions contains the optional parameters for the RoleDefinitionsClient.Delete method. +type RoleDefinitionsClientDeleteOptions struct { // placeholder for future optional parameters } -// RoleDefinitionsGetOptions contains the optional parameters for the RoleDefinitions.Get method. -type RoleDefinitionsGetOptions struct { +// RoleDefinitionsClientGetOptions contains the optional parameters for the RoleDefinitionsClient.Get method. +type RoleDefinitionsClientGetOptions struct { // placeholder for future optional parameters } -// RoleDefinitionsListOptions contains the optional parameters for the RoleDefinitions.List method. -type RoleDefinitionsListOptions struct { +// RoleDefinitionsClientListOptions contains the optional parameters for the RoleDefinitionsClient.List method. +type RoleDefinitionsClientListOptions struct { // The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as well. Filter *string } // SecretAttributes - The secret management attributes. type SecretAttributes struct { - Attributes + // Determines whether the object is enabled. + Enabled *bool `json:"enabled,omitempty"` + + // Expiry date in UTC. + Expires *time.Time `json:"exp,omitempty"` + + // Not before date in UTC. + NotBefore *time.Time `json:"nbf,omitempty"` + + // READ-ONLY; Creation time in UTC. + Created *time.Time `json:"created,omitempty" azure:"ro"` + // READ-ONLY; softDelete data retention days. Value should be >=7 and <=90 when softDelete enabled, otherwise 0. RecoverableDays *int32 `json:"recoverableDays,omitempty" azure:"ro"` - // READ-ONLY; Reflects the deletion recovery level currently in effect for secrets in the current vault. If it contains 'Purgeable', the secret can be permanently - // deleted by a privileged user; otherwise, only the + // READ-ONLY; Reflects the deletion recovery level currently in effect for secrets in the current vault. If it contains 'Purgeable', + // the secret can be permanently deleted by a privileged user; otherwise, only the // system can purge the secret, at the end of the retention interval. RecoveryLevel *DeletionRecoveryLevel `json:"recoveryLevel,omitempty" azure:"ro"` + + // READ-ONLY; Last updated time in UTC. + Updated *time.Time `json:"updated,omitempty" azure:"ro"` } // MarshalJSON implements the json.Marshaller interface for type SecretAttributes. func (s SecretAttributes) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - s.Attributes.marshalInternal(objectMap) + populateTimeUnix(objectMap, "created", s.Created) + populate(objectMap, "enabled", s.Enabled) + populateTimeUnix(objectMap, "exp", s.Expires) + populateTimeUnix(objectMap, "nbf", s.NotBefore) populate(objectMap, "recoverableDays", s.RecoverableDays) populate(objectMap, "recoveryLevel", s.RecoveryLevel) + populateTimeUnix(objectMap, "updated", s.Updated) return json.Marshal(objectMap) } @@ -606,20 +695,32 @@ func (s *SecretAttributes) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { + case "created": + err = unpopulateTimeUnix(val, &s.Created) + delete(rawMsg, key) + case "enabled": + err = unpopulate(val, &s.Enabled) + delete(rawMsg, key) + case "exp": + err = unpopulateTimeUnix(val, &s.Expires) + delete(rawMsg, key) + case "nbf": + err = unpopulateTimeUnix(val, &s.NotBefore) + delete(rawMsg, key) case "recoverableDays": err = unpopulate(val, &s.RecoverableDays) delete(rawMsg, key) case "recoveryLevel": err = unpopulate(val, &s.RecoveryLevel) delete(rawMsg, key) + case "updated": + err = unpopulateTimeUnix(val, &s.Updated) + delete(rawMsg, key) } if err != nil { return err } } - if err := s.Attributes.unmarshalInternal(rawMsg); err != nil { - return err - } return nil } @@ -640,30 +741,18 @@ type SecretBundle struct { // The secret value. Value *string `json:"value,omitempty"` - // READ-ONLY; If this is a secret backing a KV certificate, then this field specifies the corresponding key backing the KV certificate. + // READ-ONLY; If this is a secret backing a KV certificate, then this field specifies the corresponding key backing the KV + // certificate. Kid *string `json:"kid,omitempty" azure:"ro"` - // READ-ONLY; True if the secret's lifetime is managed by key vault. If this is a secret backing a certificate, then managed will be true. + // READ-ONLY; True if the secret's lifetime is managed by key vault. If this is a secret backing a certificate, then managed + // will be true. Managed *bool `json:"managed,omitempty" azure:"ro"` } // MarshalJSON implements the json.Marshaller interface for type SecretBundle. func (s SecretBundle) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - s.marshalInternal(objectMap) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type SecretBundle. -func (s *SecretBundle) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return err - } - return s.unmarshalInternal(rawMsg) -} - -func (s SecretBundle) marshalInternal(objectMap map[string]interface{}) { populate(objectMap, "attributes", s.Attributes) populate(objectMap, "contentType", s.ContentType) populate(objectMap, "id", s.ID) @@ -671,39 +760,7 @@ func (s SecretBundle) marshalInternal(objectMap map[string]interface{}) { populate(objectMap, "managed", s.Managed) populate(objectMap, "tags", s.Tags) populate(objectMap, "value", s.Value) -} - -func (s *SecretBundle) unmarshalInternal(rawMsg map[string]json.RawMessage) error { - for key, val := range rawMsg { - var err error - switch key { - case "attributes": - err = unpopulate(val, &s.Attributes) - delete(rawMsg, key) - case "contentType": - err = unpopulate(val, &s.ContentType) - delete(rawMsg, key) - case "id": - err = unpopulate(val, &s.ID) - delete(rawMsg, key) - case "kid": - err = unpopulate(val, &s.Kid) - delete(rawMsg, key) - case "managed": - err = unpopulate(val, &s.Managed) - delete(rawMsg, key) - case "tags": - err = unpopulate(val, &s.Tags) - delete(rawMsg, key) - case "value": - err = unpopulate(val, &s.Value) - delete(rawMsg, key) - } - if err != nil { - return err - } - } - return nil + return json.Marshal(objectMap) } // SecretItem - The secret item containing secret metadata. @@ -720,59 +777,20 @@ type SecretItem struct { // Application specific metadata in the form of key-value pairs. Tags map[string]*string `json:"tags,omitempty"` - // READ-ONLY; True if the secret's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be true. + // READ-ONLY; True if the secret'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"` } // MarshalJSON implements the json.Marshaller interface for type SecretItem. func (s SecretItem) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - s.marshalInternal(objectMap) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type SecretItem. -func (s *SecretItem) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return err - } - return s.unmarshalInternal(rawMsg) -} - -func (s SecretItem) marshalInternal(objectMap map[string]interface{}) { populate(objectMap, "attributes", s.Attributes) populate(objectMap, "contentType", s.ContentType) populate(objectMap, "id", s.ID) populate(objectMap, "managed", s.Managed) populate(objectMap, "tags", s.Tags) -} - -func (s *SecretItem) unmarshalInternal(rawMsg map[string]json.RawMessage) error { - for key, val := range rawMsg { - var err error - switch key { - case "attributes": - err = unpopulate(val, &s.Attributes) - delete(rawMsg, key) - case "contentType": - err = unpopulate(val, &s.ContentType) - delete(rawMsg, key) - case "id": - err = unpopulate(val, &s.ID) - delete(rawMsg, key) - case "managed": - err = unpopulate(val, &s.Managed) - delete(rawMsg, key) - case "tags": - err = unpopulate(val, &s.Tags) - delete(rawMsg, key) - } - if err != nil { - return err - } - } - return nil + return json.Marshal(objectMap) } // SecretListResult - The secret list result. @@ -890,8 +908,8 @@ type SecurityDomainJSONWebKey struct { // REQUIRED; Key identifier. Kid *string `json:"kid,omitempty"` - // REQUIRED; JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. For Security Domain this value - // must be RSA. + // REQUIRED; JsonWebKey Key Type (kty), as defined in https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40. + // For Security Domain this value must be RSA. Kty *string `json:"kty,omitempty"` // REQUIRED; RSA modulus. diff --git a/sdk/keyvault/azsecrets/internal/pagers.go b/sdk/keyvault/azsecrets/internal/pagers.go index dea8488ce558..c72254457cbc 100644 --- a/sdk/keyvault/azsecrets/internal/pagers.go +++ b/sdk/keyvault/azsecrets/internal/pagers.go @@ -47,13 +47,13 @@ func (p *KeyVaultClientGetDeletedSecretsPager) NextPage(ctx context.Context) boo p.err = err return false } - resp, err := p.client.con.Pipeline().Do(req) + resp, err := p.client.pl.Do(req) if err != nil { p.err = err return false } if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = p.client.getDeletedSecretsHandleError(resp) + p.err = runtime.NewResponseError(resp) return false } result, err := p.client.getDeletedSecretsHandleResponse(resp) @@ -101,13 +101,13 @@ func (p *KeyVaultClientGetSecretVersionsPager) NextPage(ctx context.Context) boo p.err = err return false } - resp, err := p.client.con.Pipeline().Do(req) + resp, err := p.client.pl.Do(req) if err != nil { p.err = err return false } if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = p.client.getSecretVersionsHandleError(resp) + p.err = runtime.NewResponseError(resp) return false } result, err := p.client.getSecretVersionsHandleResponse(resp) @@ -155,13 +155,13 @@ func (p *KeyVaultClientGetSecretsPager) NextPage(ctx context.Context) bool { p.err = err return false } - resp, err := p.client.con.Pipeline().Do(req) + resp, err := p.client.pl.Do(req) if err != nil { p.err = err return false } if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = p.client.getSecretsHandleError(resp) + p.err = runtime.NewResponseError(resp) return false } result, err := p.client.getSecretsHandleResponse(resp) @@ -178,23 +178,23 @@ func (p *KeyVaultClientGetSecretsPager) PageResponse() KeyVaultClientGetSecretsR return p.current } -// RoleAssignmentsListForScopePager provides operations for iterating over paged responses. -type RoleAssignmentsListForScopePager struct { +// RoleAssignmentsClientListForScopePager provides operations for iterating over paged responses. +type RoleAssignmentsClientListForScopePager struct { client *RoleAssignmentsClient - current RoleAssignmentsListForScopeResponse + current RoleAssignmentsClientListForScopeResponse err error requester func(context.Context) (*policy.Request, error) - advancer func(context.Context, RoleAssignmentsListForScopeResponse) (*policy.Request, error) + advancer func(context.Context, RoleAssignmentsClientListForScopeResponse) (*policy.Request, error) } // Err returns the last error encountered while paging. -func (p *RoleAssignmentsListForScopePager) Err() error { +func (p *RoleAssignmentsClientListForScopePager) Err() error { return p.err } // NextPage returns true if the pager advanced to the next page. // Returns false if there are no more pages or an error occurred. -func (p *RoleAssignmentsListForScopePager) NextPage(ctx context.Context) bool { +func (p *RoleAssignmentsClientListForScopePager) NextPage(ctx context.Context) bool { var req *policy.Request var err error if !reflect.ValueOf(p.current).IsZero() { @@ -209,13 +209,13 @@ func (p *RoleAssignmentsListForScopePager) NextPage(ctx context.Context) bool { p.err = err return false } - resp, err := p.client.con.Pipeline().Do(req) + resp, err := p.client.pl.Do(req) if err != nil { p.err = err return false } if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = p.client.listForScopeHandleError(resp) + p.err = runtime.NewResponseError(resp) return false } result, err := p.client.listForScopeHandleResponse(resp) @@ -227,28 +227,28 @@ func (p *RoleAssignmentsListForScopePager) NextPage(ctx context.Context) bool { return true } -// PageResponse returns the current RoleAssignmentsListForScopeResponse page. -func (p *RoleAssignmentsListForScopePager) PageResponse() RoleAssignmentsListForScopeResponse { +// PageResponse returns the current RoleAssignmentsClientListForScopeResponse page. +func (p *RoleAssignmentsClientListForScopePager) PageResponse() RoleAssignmentsClientListForScopeResponse { return p.current } -// RoleDefinitionsListPager provides operations for iterating over paged responses. -type RoleDefinitionsListPager struct { +// RoleDefinitionsClientListPager provides operations for iterating over paged responses. +type RoleDefinitionsClientListPager struct { client *RoleDefinitionsClient - current RoleDefinitionsListResponse + current RoleDefinitionsClientListResponse err error requester func(context.Context) (*policy.Request, error) - advancer func(context.Context, RoleDefinitionsListResponse) (*policy.Request, error) + advancer func(context.Context, RoleDefinitionsClientListResponse) (*policy.Request, error) } // Err returns the last error encountered while paging. -func (p *RoleDefinitionsListPager) Err() error { +func (p *RoleDefinitionsClientListPager) Err() error { return p.err } // NextPage returns true if the pager advanced to the next page. // Returns false if there are no more pages or an error occurred. -func (p *RoleDefinitionsListPager) NextPage(ctx context.Context) bool { +func (p *RoleDefinitionsClientListPager) NextPage(ctx context.Context) bool { var req *policy.Request var err error if !reflect.ValueOf(p.current).IsZero() { @@ -263,13 +263,13 @@ func (p *RoleDefinitionsListPager) NextPage(ctx context.Context) bool { p.err = err return false } - resp, err := p.client.con.Pipeline().Do(req) + resp, err := p.client.pl.Do(req) if err != nil { p.err = err return false } if !runtime.HasStatusCode(resp, http.StatusOK) { - p.err = p.client.listHandleError(resp) + p.err = runtime.NewResponseError(resp) return false } result, err := p.client.listHandleResponse(resp) @@ -281,7 +281,7 @@ func (p *RoleDefinitionsListPager) NextPage(ctx context.Context) bool { return true } -// PageResponse returns the current RoleDefinitionsListResponse page. -func (p *RoleDefinitionsListPager) PageResponse() RoleDefinitionsListResponse { +// PageResponse returns the current RoleDefinitionsClientListResponse page. +func (p *RoleDefinitionsClientListPager) PageResponse() RoleDefinitionsClientListResponse { return p.current } diff --git a/sdk/keyvault/azsecrets/internal/pollers.go b/sdk/keyvault/azsecrets/internal/pollers.go index 2b5e07174fe8..c29eb753fca6 100644 --- a/sdk/keyvault/azsecrets/internal/pollers.go +++ b/sdk/keyvault/azsecrets/internal/pollers.go @@ -14,13 +14,13 @@ import ( "net/http" ) -// HSMSecurityDomainDownloadPoller provides polling facilities until the operation reaches a terminal state. -type HSMSecurityDomainDownloadPoller struct { +// HSMSecurityDomainClientDownloadPoller provides polling facilities until the operation reaches a terminal state. +type HSMSecurityDomainClientDownloadPoller struct { pt *azcore.Poller } // Done returns true if the LRO has reached a terminal state. -func (p *HSMSecurityDomainDownloadPoller) Done() bool { +func (p *HSMSecurityDomainClientDownloadPoller) Done() bool { return p.pt.Done() } @@ -34,18 +34,18 @@ func (p *HSMSecurityDomainDownloadPoller) Done() bool { // If Poll fails, the poller's state is unmodified and the error is returned. // Calling Poll on an LRO that has reached a terminal state will return the final // HTTP response or error. -func (p *HSMSecurityDomainDownloadPoller) Poll(ctx context.Context) (*http.Response, error) { +func (p *HSMSecurityDomainClientDownloadPoller) Poll(ctx context.Context) (*http.Response, error) { return p.pt.Poll(ctx) } // FinalResponse performs a final GET to the service and returns the final response // for the polling operation. If there is an error performing the final GET then an error is returned. -// If the final GET succeeded then the final HSMSecurityDomainDownloadResponse will be returned. -func (p *HSMSecurityDomainDownloadPoller) FinalResponse(ctx context.Context) (HSMSecurityDomainDownloadResponse, error) { - respType := HSMSecurityDomainDownloadResponse{} +// If the final GET succeeded then the final HSMSecurityDomainClientDownloadResponse will be returned. +func (p *HSMSecurityDomainClientDownloadPoller) FinalResponse(ctx context.Context) (HSMSecurityDomainClientDownloadResponse, error) { + respType := HSMSecurityDomainClientDownloadResponse{} resp, err := p.pt.FinalResponse(ctx, &respType.SecurityDomainObject) if err != nil { - return HSMSecurityDomainDownloadResponse{}, err + return HSMSecurityDomainClientDownloadResponse{}, err } respType.RawResponse = resp return respType, nil @@ -53,17 +53,17 @@ func (p *HSMSecurityDomainDownloadPoller) FinalResponse(ctx context.Context) (HS // ResumeToken returns a value representing the poller that can be used to resume // the LRO at a later time. ResumeTokens are unique per service operation. -func (p *HSMSecurityDomainDownloadPoller) ResumeToken() (string, error) { +func (p *HSMSecurityDomainClientDownloadPoller) ResumeToken() (string, error) { return p.pt.ResumeToken() } -// HSMSecurityDomainUploadPoller provides polling facilities until the operation reaches a terminal state. -type HSMSecurityDomainUploadPoller struct { +// HSMSecurityDomainClientUploadPoller provides polling facilities until the operation reaches a terminal state. +type HSMSecurityDomainClientUploadPoller struct { pt *azcore.Poller } // Done returns true if the LRO has reached a terminal state. -func (p *HSMSecurityDomainUploadPoller) Done() bool { +func (p *HSMSecurityDomainClientUploadPoller) Done() bool { return p.pt.Done() } @@ -77,18 +77,18 @@ func (p *HSMSecurityDomainUploadPoller) Done() bool { // If Poll fails, the poller's state is unmodified and the error is returned. // Calling Poll on an LRO that has reached a terminal state will return the final // HTTP response or error. -func (p *HSMSecurityDomainUploadPoller) Poll(ctx context.Context) (*http.Response, error) { +func (p *HSMSecurityDomainClientUploadPoller) Poll(ctx context.Context) (*http.Response, error) { return p.pt.Poll(ctx) } // FinalResponse performs a final GET to the service and returns the final response // for the polling operation. If there is an error performing the final GET then an error is returned. -// If the final GET succeeded then the final HSMSecurityDomainUploadResponse will be returned. -func (p *HSMSecurityDomainUploadPoller) FinalResponse(ctx context.Context) (HSMSecurityDomainUploadResponse, error) { - respType := HSMSecurityDomainUploadResponse{} +// If the final GET succeeded then the final HSMSecurityDomainClientUploadResponse will be returned. +func (p *HSMSecurityDomainClientUploadPoller) FinalResponse(ctx context.Context) (HSMSecurityDomainClientUploadResponse, error) { + respType := HSMSecurityDomainClientUploadResponse{} resp, err := p.pt.FinalResponse(ctx, &respType.SecurityDomainOperationStatus) if err != nil { - return HSMSecurityDomainUploadResponse{}, err + return HSMSecurityDomainClientUploadResponse{}, err } respType.RawResponse = resp return respType, nil @@ -96,6 +96,6 @@ func (p *HSMSecurityDomainUploadPoller) FinalResponse(ctx context.Context) (HSMS // ResumeToken returns a value representing the poller that can be used to resume // the LRO at a later time. ResumeTokens are unique per service operation. -func (p *HSMSecurityDomainUploadPoller) ResumeToken() (string, error) { +func (p *HSMSecurityDomainClientUploadPoller) ResumeToken() (string, error) { return p.pt.ResumeToken() } diff --git a/sdk/keyvault/azsecrets/internal/response_types.go b/sdk/keyvault/azsecrets/internal/response_types.go index 065fbbfbfa12..edd5a025c2f9 100644 --- a/sdk/keyvault/azsecrets/internal/response_types.go +++ b/sdk/keyvault/azsecrets/internal/response_types.go @@ -15,22 +15,22 @@ import ( "time" ) -// HSMSecurityDomainDownloadPendingResponse contains the response from method HSMSecurityDomain.DownloadPending. -type HSMSecurityDomainDownloadPendingResponse struct { - HSMSecurityDomainDownloadPendingResult +// HSMSecurityDomainClientDownloadPendingResponse contains the response from method HSMSecurityDomainClient.DownloadPending. +type HSMSecurityDomainClientDownloadPendingResponse struct { + HSMSecurityDomainClientDownloadPendingResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// HSMSecurityDomainDownloadPendingResult contains the result from method HSMSecurityDomain.DownloadPending. -type HSMSecurityDomainDownloadPendingResult struct { +// HSMSecurityDomainClientDownloadPendingResult contains the result from method HSMSecurityDomainClient.DownloadPending. +type HSMSecurityDomainClientDownloadPendingResult struct { SecurityDomainOperationStatus } -// HSMSecurityDomainDownloadPollerResponse contains the response from method HSMSecurityDomain.Download. -type HSMSecurityDomainDownloadPollerResponse struct { +// HSMSecurityDomainClientDownloadPollerResponse contains the response from method HSMSecurityDomainClient.Download. +type HSMSecurityDomainClientDownloadPollerResponse struct { // Poller contains an initialized poller. - Poller *HSMSecurityDomainDownloadPoller + Poller *HSMSecurityDomainClientDownloadPoller // RawResponse contains the underlying HTTP response. RawResponse *http.Response @@ -38,8 +38,8 @@ type HSMSecurityDomainDownloadPollerResponse struct { // PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. // freq: the time to wait between intervals in absence of a Retry-After header. Allowed minimum is one second. -func (l HSMSecurityDomainDownloadPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (HSMSecurityDomainDownloadResponse, error) { - respType := HSMSecurityDomainDownloadResponse{} +func (l HSMSecurityDomainClientDownloadPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (HSMSecurityDomainClientDownloadResponse, error) { + respType := HSMSecurityDomainClientDownloadResponse{} resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.SecurityDomainObject) if err != nil { return respType, err @@ -48,13 +48,13 @@ func (l HSMSecurityDomainDownloadPollerResponse) PollUntilDone(ctx context.Conte return respType, nil } -// Resume rehydrates a HSMSecurityDomainDownloadPollerResponse from the provided client and resume token. -func (l *HSMSecurityDomainDownloadPollerResponse) Resume(ctx context.Context, client *HSMSecurityDomainClient, token string) error { - pt, err := armruntime.NewPollerFromResumeToken("HSMSecurityDomainClient.Download", token, client.con.Pipeline(), client.downloadHandleError) +// Resume rehydrates a HSMSecurityDomainClientDownloadPollerResponse from the provided client and resume token. +func (l *HSMSecurityDomainClientDownloadPollerResponse) Resume(ctx context.Context, client *HSMSecurityDomainClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("HSMSecurityDomainClient.Download", token, client.pl) if err != nil { return err } - poller := &HSMSecurityDomainDownloadPoller{ + poller := &HSMSecurityDomainClientDownloadPoller{ pt: pt, } resp, err := poller.Poll(ctx) @@ -66,46 +66,46 @@ func (l *HSMSecurityDomainDownloadPollerResponse) Resume(ctx context.Context, cl return nil } -// HSMSecurityDomainDownloadResponse contains the response from method HSMSecurityDomain.Download. -type HSMSecurityDomainDownloadResponse struct { - HSMSecurityDomainDownloadResult +// HSMSecurityDomainClientDownloadResponse contains the response from method HSMSecurityDomainClient.Download. +type HSMSecurityDomainClientDownloadResponse struct { + HSMSecurityDomainClientDownloadResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// HSMSecurityDomainDownloadResult contains the result from method HSMSecurityDomain.Download. -type HSMSecurityDomainDownloadResult struct { +// HSMSecurityDomainClientDownloadResult contains the result from method HSMSecurityDomainClient.Download. +type HSMSecurityDomainClientDownloadResult struct { SecurityDomainObject } -// HSMSecurityDomainTransferKeyResponse contains the response from method HSMSecurityDomain.TransferKey. -type HSMSecurityDomainTransferKeyResponse struct { - HSMSecurityDomainTransferKeyResult +// HSMSecurityDomainClientTransferKeyResponse contains the response from method HSMSecurityDomainClient.TransferKey. +type HSMSecurityDomainClientTransferKeyResponse struct { + HSMSecurityDomainClientTransferKeyResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// HSMSecurityDomainTransferKeyResult contains the result from method HSMSecurityDomain.TransferKey. -type HSMSecurityDomainTransferKeyResult struct { +// HSMSecurityDomainClientTransferKeyResult contains the result from method HSMSecurityDomainClient.TransferKey. +type HSMSecurityDomainClientTransferKeyResult struct { TransferKey } -// HSMSecurityDomainUploadPendingResponse contains the response from method HSMSecurityDomain.UploadPending. -type HSMSecurityDomainUploadPendingResponse struct { - HSMSecurityDomainUploadPendingResult +// HSMSecurityDomainClientUploadPendingResponse contains the response from method HSMSecurityDomainClient.UploadPending. +type HSMSecurityDomainClientUploadPendingResponse struct { + HSMSecurityDomainClientUploadPendingResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// HSMSecurityDomainUploadPendingResult contains the result from method HSMSecurityDomain.UploadPending. -type HSMSecurityDomainUploadPendingResult struct { +// HSMSecurityDomainClientUploadPendingResult contains the result from method HSMSecurityDomainClient.UploadPending. +type HSMSecurityDomainClientUploadPendingResult struct { SecurityDomainOperationStatus } -// HSMSecurityDomainUploadPollerResponse contains the response from method HSMSecurityDomain.Upload. -type HSMSecurityDomainUploadPollerResponse struct { +// HSMSecurityDomainClientUploadPollerResponse contains the response from method HSMSecurityDomainClient.Upload. +type HSMSecurityDomainClientUploadPollerResponse struct { // Poller contains an initialized poller. - Poller *HSMSecurityDomainUploadPoller + Poller *HSMSecurityDomainClientUploadPoller // RawResponse contains the underlying HTTP response. RawResponse *http.Response @@ -113,8 +113,8 @@ type HSMSecurityDomainUploadPollerResponse struct { // PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. // freq: the time to wait between intervals in absence of a Retry-After header. Allowed minimum is one second. -func (l HSMSecurityDomainUploadPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (HSMSecurityDomainUploadResponse, error) { - respType := HSMSecurityDomainUploadResponse{} +func (l HSMSecurityDomainClientUploadPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (HSMSecurityDomainClientUploadResponse, error) { + respType := HSMSecurityDomainClientUploadResponse{} resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.SecurityDomainOperationStatus) if err != nil { return respType, err @@ -123,13 +123,13 @@ func (l HSMSecurityDomainUploadPollerResponse) PollUntilDone(ctx context.Context return respType, nil } -// Resume rehydrates a HSMSecurityDomainUploadPollerResponse from the provided client and resume token. -func (l *HSMSecurityDomainUploadPollerResponse) Resume(ctx context.Context, client *HSMSecurityDomainClient, token string) error { - pt, err := armruntime.NewPollerFromResumeToken("HSMSecurityDomainClient.Upload", token, client.con.Pipeline(), client.uploadHandleError) +// Resume rehydrates a HSMSecurityDomainClientUploadPollerResponse from the provided client and resume token. +func (l *HSMSecurityDomainClientUploadPollerResponse) Resume(ctx context.Context, client *HSMSecurityDomainClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("HSMSecurityDomainClient.Upload", token, client.pl) if err != nil { return err } - poller := &HSMSecurityDomainUploadPoller{ + poller := &HSMSecurityDomainClientUploadPoller{ pt: pt, } resp, err := poller.Poll(ctx) @@ -141,15 +141,15 @@ func (l *HSMSecurityDomainUploadPollerResponse) Resume(ctx context.Context, clie return nil } -// HSMSecurityDomainUploadResponse contains the response from method HSMSecurityDomain.Upload. -type HSMSecurityDomainUploadResponse struct { - HSMSecurityDomainUploadResult +// HSMSecurityDomainClientUploadResponse contains the response from method HSMSecurityDomainClient.Upload. +type HSMSecurityDomainClientUploadResponse struct { + HSMSecurityDomainClientUploadResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// HSMSecurityDomainUploadResult contains the result from method HSMSecurityDomain.Upload. -type HSMSecurityDomainUploadResult struct { +// HSMSecurityDomainClientUploadResult contains the result from method HSMSecurityDomainClient.Upload. +type HSMSecurityDomainClientUploadResult struct { SecurityDomainOperationStatus } @@ -291,98 +291,98 @@ type KeyVaultClientUpdateSecretResult struct { SecretBundle } -// RoleAssignmentsCreateResponse contains the response from method RoleAssignments.Create. -type RoleAssignmentsCreateResponse struct { - RoleAssignmentsCreateResult +// RoleAssignmentsClientCreateResponse contains the response from method RoleAssignmentsClient.Create. +type RoleAssignmentsClientCreateResponse struct { + RoleAssignmentsClientCreateResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleAssignmentsCreateResult contains the result from method RoleAssignments.Create. -type RoleAssignmentsCreateResult struct { +// RoleAssignmentsClientCreateResult contains the result from method RoleAssignmentsClient.Create. +type RoleAssignmentsClientCreateResult struct { RoleAssignment } -// RoleAssignmentsDeleteResponse contains the response from method RoleAssignments.Delete. -type RoleAssignmentsDeleteResponse struct { - RoleAssignmentsDeleteResult +// RoleAssignmentsClientDeleteResponse contains the response from method RoleAssignmentsClient.Delete. +type RoleAssignmentsClientDeleteResponse struct { + RoleAssignmentsClientDeleteResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleAssignmentsDeleteResult contains the result from method RoleAssignments.Delete. -type RoleAssignmentsDeleteResult struct { +// RoleAssignmentsClientDeleteResult contains the result from method RoleAssignmentsClient.Delete. +type RoleAssignmentsClientDeleteResult struct { RoleAssignment } -// RoleAssignmentsGetResponse contains the response from method RoleAssignments.Get. -type RoleAssignmentsGetResponse struct { - RoleAssignmentsGetResult +// RoleAssignmentsClientGetResponse contains the response from method RoleAssignmentsClient.Get. +type RoleAssignmentsClientGetResponse struct { + RoleAssignmentsClientGetResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleAssignmentsGetResult contains the result from method RoleAssignments.Get. -type RoleAssignmentsGetResult struct { +// RoleAssignmentsClientGetResult contains the result from method RoleAssignmentsClient.Get. +type RoleAssignmentsClientGetResult struct { RoleAssignment } -// RoleAssignmentsListForScopeResponse contains the response from method RoleAssignments.ListForScope. -type RoleAssignmentsListForScopeResponse struct { - RoleAssignmentsListForScopeResult +// RoleAssignmentsClientListForScopeResponse contains the response from method RoleAssignmentsClient.ListForScope. +type RoleAssignmentsClientListForScopeResponse struct { + RoleAssignmentsClientListForScopeResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleAssignmentsListForScopeResult contains the result from method RoleAssignments.ListForScope. -type RoleAssignmentsListForScopeResult struct { +// RoleAssignmentsClientListForScopeResult contains the result from method RoleAssignmentsClient.ListForScope. +type RoleAssignmentsClientListForScopeResult struct { RoleAssignmentListResult } -// RoleDefinitionsCreateOrUpdateResponse contains the response from method RoleDefinitions.CreateOrUpdate. -type RoleDefinitionsCreateOrUpdateResponse struct { - RoleDefinitionsCreateOrUpdateResult +// RoleDefinitionsClientCreateOrUpdateResponse contains the response from method RoleDefinitionsClient.CreateOrUpdate. +type RoleDefinitionsClientCreateOrUpdateResponse struct { + RoleDefinitionsClientCreateOrUpdateResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleDefinitionsCreateOrUpdateResult contains the result from method RoleDefinitions.CreateOrUpdate. -type RoleDefinitionsCreateOrUpdateResult struct { +// RoleDefinitionsClientCreateOrUpdateResult contains the result from method RoleDefinitionsClient.CreateOrUpdate. +type RoleDefinitionsClientCreateOrUpdateResult struct { RoleDefinition } -// RoleDefinitionsDeleteResponse contains the response from method RoleDefinitions.Delete. -type RoleDefinitionsDeleteResponse struct { - RoleDefinitionsDeleteResult +// RoleDefinitionsClientDeleteResponse contains the response from method RoleDefinitionsClient.Delete. +type RoleDefinitionsClientDeleteResponse struct { + RoleDefinitionsClientDeleteResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleDefinitionsDeleteResult contains the result from method RoleDefinitions.Delete. -type RoleDefinitionsDeleteResult struct { +// RoleDefinitionsClientDeleteResult contains the result from method RoleDefinitionsClient.Delete. +type RoleDefinitionsClientDeleteResult struct { RoleDefinition } -// RoleDefinitionsGetResponse contains the response from method RoleDefinitions.Get. -type RoleDefinitionsGetResponse struct { - RoleDefinitionsGetResult +// RoleDefinitionsClientGetResponse contains the response from method RoleDefinitionsClient.Get. +type RoleDefinitionsClientGetResponse struct { + RoleDefinitionsClientGetResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleDefinitionsGetResult contains the result from method RoleDefinitions.Get. -type RoleDefinitionsGetResult struct { +// RoleDefinitionsClientGetResult contains the result from method RoleDefinitionsClient.Get. +type RoleDefinitionsClientGetResult struct { RoleDefinition } -// RoleDefinitionsListResponse contains the response from method RoleDefinitions.List. -type RoleDefinitionsListResponse struct { - RoleDefinitionsListResult +// RoleDefinitionsClientListResponse contains the response from method RoleDefinitionsClient.List. +type RoleDefinitionsClientListResponse struct { + RoleDefinitionsClientListResult // RawResponse contains the underlying HTTP response. RawResponse *http.Response } -// RoleDefinitionsListResult contains the result from method RoleDefinitions.List. -type RoleDefinitionsListResult struct { +// RoleDefinitionsClientListResult contains the result from method RoleDefinitionsClient.List. +type RoleDefinitionsClientListResult struct { RoleDefinitionListResult } diff --git a/sdk/keyvault/azsecrets/internal/roleassignments_client.go b/sdk/keyvault/azsecrets/internal/roleassignments_client.go index 5f504d527b85..dc89c2e26d64 100644 --- a/sdk/keyvault/azsecrets/internal/roleassignments_client.go +++ b/sdk/keyvault/azsecrets/internal/roleassignments_client.go @@ -11,7 +11,7 @@ package internal import ( "context" "errors" - "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -22,39 +22,49 @@ import ( // RoleAssignmentsClient contains the methods for the RoleAssignments group. // Don't use this type directly, use NewRoleAssignmentsClient() instead. type RoleAssignmentsClient struct { - con *Connection + pl runtime.Pipeline } // NewRoleAssignmentsClient creates a new instance of RoleAssignmentsClient with the specified values. -func NewRoleAssignmentsClient(con *Connection) *RoleAssignmentsClient { - return &RoleAssignmentsClient{con: con} +// options - pass nil to accept the default values. +func NewRoleAssignmentsClient(options *azcore.ClientOptions) *RoleAssignmentsClient { + cp := azcore.ClientOptions{} + if options != nil { + cp = *options + } + client := &RoleAssignmentsClient{ + pl: runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &cp), + } + return client } // Create - Creates a role assignment. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleAssignmentsClient) Create(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, parameters RoleAssignmentCreateParameters, options *RoleAssignmentsCreateOptions) (RoleAssignmentsCreateResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role assignment to create. +// roleAssignmentName - The name of the role assignment to create. It can be any valid GUID. +// parameters - Parameters for the role assignment. +// options - RoleAssignmentsClientCreateOptions contains the optional parameters for the RoleAssignmentsClient.Create method. +func (client *RoleAssignmentsClient) Create(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, parameters RoleAssignmentCreateParameters, options *RoleAssignmentsClientCreateOptions) (RoleAssignmentsClientCreateResponse, error) { req, err := client.createCreateRequest(ctx, vaultBaseURL, scope, roleAssignmentName, parameters, options) if err != nil { - return RoleAssignmentsCreateResponse{}, err + return RoleAssignmentsClientCreateResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleAssignmentsCreateResponse{}, err + return RoleAssignmentsClientCreateResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusCreated) { - return RoleAssignmentsCreateResponse{}, client.createHandleError(resp) + return RoleAssignmentsClientCreateResponse{}, runtime.NewResponseError(resp) } return client.createHandleResponse(resp) } // createCreateRequest creates the Create request. -func (client *RoleAssignmentsClient) createCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, parameters RoleAssignmentCreateParameters, options *RoleAssignmentsCreateOptions) (*policy.Request, error) { +func (client *RoleAssignmentsClient) createCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, parameters RoleAssignmentCreateParameters, options *RoleAssignmentsClientCreateOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleAssignmentName == "" { return nil, errors.New("parameter roleAssignmentName cannot be empty") @@ -72,52 +82,40 @@ func (client *RoleAssignmentsClient) createCreateRequest(ctx context.Context, va } // createHandleResponse handles the Create response. -func (client *RoleAssignmentsClient) createHandleResponse(resp *http.Response) (RoleAssignmentsCreateResponse, error) { - result := RoleAssignmentsCreateResponse{RawResponse: resp} +func (client *RoleAssignmentsClient) createHandleResponse(resp *http.Response) (RoleAssignmentsClientCreateResponse, error) { + result := RoleAssignmentsClientCreateResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleAssignment); err != nil { - return RoleAssignmentsCreateResponse{}, err + return RoleAssignmentsClientCreateResponse{}, err } return result, nil } -// createHandleError handles the Create error response. -func (client *RoleAssignmentsClient) createHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // Delete - Deletes a role assignment. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleAssignmentsClient) Delete(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsDeleteOptions) (RoleAssignmentsDeleteResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role assignment to delete. +// roleAssignmentName - The name of the role assignment to delete. +// options - RoleAssignmentsClientDeleteOptions contains the optional parameters for the RoleAssignmentsClient.Delete method. +func (client *RoleAssignmentsClient) Delete(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsClientDeleteOptions) (RoleAssignmentsClientDeleteResponse, error) { req, err := client.deleteCreateRequest(ctx, vaultBaseURL, scope, roleAssignmentName, options) if err != nil { - return RoleAssignmentsDeleteResponse{}, err + return RoleAssignmentsClientDeleteResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleAssignmentsDeleteResponse{}, err + return RoleAssignmentsClientDeleteResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoleAssignmentsDeleteResponse{}, client.deleteHandleError(resp) + return RoleAssignmentsClientDeleteResponse{}, runtime.NewResponseError(resp) } return client.deleteHandleResponse(resp) } // deleteCreateRequest creates the Delete request. -func (client *RoleAssignmentsClient) deleteCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsDeleteOptions) (*policy.Request, error) { +func (client *RoleAssignmentsClient) deleteCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsClientDeleteOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleAssignmentName == "" { return nil, errors.New("parameter roleAssignmentName cannot be empty") @@ -135,52 +133,40 @@ func (client *RoleAssignmentsClient) deleteCreateRequest(ctx context.Context, va } // deleteHandleResponse handles the Delete response. -func (client *RoleAssignmentsClient) deleteHandleResponse(resp *http.Response) (RoleAssignmentsDeleteResponse, error) { - result := RoleAssignmentsDeleteResponse{RawResponse: resp} +func (client *RoleAssignmentsClient) deleteHandleResponse(resp *http.Response) (RoleAssignmentsClientDeleteResponse, error) { + result := RoleAssignmentsClientDeleteResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleAssignment); err != nil { - return RoleAssignmentsDeleteResponse{}, err + return RoleAssignmentsClientDeleteResponse{}, err } return result, nil } -// deleteHandleError handles the Delete error response. -func (client *RoleAssignmentsClient) deleteHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // Get - Get the specified role assignment. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleAssignmentsClient) Get(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsGetOptions) (RoleAssignmentsGetResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role assignment. +// roleAssignmentName - The name of the role assignment to get. +// options - RoleAssignmentsClientGetOptions contains the optional parameters for the RoleAssignmentsClient.Get method. +func (client *RoleAssignmentsClient) Get(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsClientGetOptions) (RoleAssignmentsClientGetResponse, error) { req, err := client.getCreateRequest(ctx, vaultBaseURL, scope, roleAssignmentName, options) if err != nil { - return RoleAssignmentsGetResponse{}, err + return RoleAssignmentsClientGetResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleAssignmentsGetResponse{}, err + return RoleAssignmentsClientGetResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoleAssignmentsGetResponse{}, client.getHandleError(resp) + return RoleAssignmentsClientGetResponse{}, runtime.NewResponseError(resp) } return client.getHandleResponse(resp) } // getCreateRequest creates the Get request. -func (client *RoleAssignmentsClient) getCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsGetOptions) (*policy.Request, error) { +func (client *RoleAssignmentsClient) getCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleAssignmentName string, options *RoleAssignmentsClientGetOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleAssignmentName == "" { return nil, errors.New("parameter roleAssignmentName cannot be empty") @@ -198,49 +184,37 @@ func (client *RoleAssignmentsClient) getCreateRequest(ctx context.Context, vault } // getHandleResponse handles the Get response. -func (client *RoleAssignmentsClient) getHandleResponse(resp *http.Response) (RoleAssignmentsGetResponse, error) { - result := RoleAssignmentsGetResponse{RawResponse: resp} +func (client *RoleAssignmentsClient) getHandleResponse(resp *http.Response) (RoleAssignmentsClientGetResponse, error) { + result := RoleAssignmentsClientGetResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleAssignment); err != nil { - return RoleAssignmentsGetResponse{}, err + return RoleAssignmentsClientGetResponse{}, err } return result, nil } -// getHandleError handles the Get error response. -func (client *RoleAssignmentsClient) getHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // ListForScope - Gets role assignments for a scope. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleAssignmentsClient) ListForScope(vaultBaseURL string, scope string, options *RoleAssignmentsListForScopeOptions) *RoleAssignmentsListForScopePager { - return &RoleAssignmentsListForScopePager{ +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role assignments. +// options - RoleAssignmentsClientListForScopeOptions contains the optional parameters for the RoleAssignmentsClient.ListForScope +// method. +func (client *RoleAssignmentsClient) ListForScope(vaultBaseURL string, scope string, options *RoleAssignmentsClientListForScopeOptions) *RoleAssignmentsClientListForScopePager { + return &RoleAssignmentsClientListForScopePager{ client: client, requester: func(ctx context.Context) (*policy.Request, error) { return client.listForScopeCreateRequest(ctx, vaultBaseURL, scope, options) }, - advancer: func(ctx context.Context, resp RoleAssignmentsListForScopeResponse) (*policy.Request, error) { + advancer: func(ctx context.Context, resp RoleAssignmentsClientListForScopeResponse) (*policy.Request, error) { return runtime.NewRequest(ctx, http.MethodGet, *resp.RoleAssignmentListResult.NextLink) }, } } // listForScopeCreateRequest creates the ListForScope request. -func (client *RoleAssignmentsClient) listForScopeCreateRequest(ctx context.Context, vaultBaseURL string, scope string, options *RoleAssignmentsListForScopeOptions) (*policy.Request, error) { +func (client *RoleAssignmentsClient) listForScopeCreateRequest(ctx context.Context, vaultBaseURL string, scope string, options *RoleAssignmentsClientListForScopeOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleAssignments" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(host, urlPath)) if err != nil { @@ -257,23 +231,10 @@ func (client *RoleAssignmentsClient) listForScopeCreateRequest(ctx context.Conte } // listForScopeHandleResponse handles the ListForScope response. -func (client *RoleAssignmentsClient) listForScopeHandleResponse(resp *http.Response) (RoleAssignmentsListForScopeResponse, error) { - result := RoleAssignmentsListForScopeResponse{RawResponse: resp} +func (client *RoleAssignmentsClient) listForScopeHandleResponse(resp *http.Response) (RoleAssignmentsClientListForScopeResponse, error) { + result := RoleAssignmentsClientListForScopeResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleAssignmentListResult); err != nil { - return RoleAssignmentsListForScopeResponse{}, err + return RoleAssignmentsClientListForScopeResponse{}, err } return result, nil } - -// listForScopeHandleError handles the ListForScope error response. -func (client *RoleAssignmentsClient) listForScopeHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} diff --git a/sdk/keyvault/azsecrets/internal/roledefinitions_client.go b/sdk/keyvault/azsecrets/internal/roledefinitions_client.go index 0340e32a0625..3d62ea44f89b 100644 --- a/sdk/keyvault/azsecrets/internal/roledefinitions_client.go +++ b/sdk/keyvault/azsecrets/internal/roledefinitions_client.go @@ -11,7 +11,7 @@ package internal import ( "context" "errors" - "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "net/http" @@ -22,39 +22,50 @@ import ( // RoleDefinitionsClient contains the methods for the RoleDefinitions group. // Don't use this type directly, use NewRoleDefinitionsClient() instead. type RoleDefinitionsClient struct { - con *Connection + pl runtime.Pipeline } // NewRoleDefinitionsClient creates a new instance of RoleDefinitionsClient with the specified values. -func NewRoleDefinitionsClient(con *Connection) *RoleDefinitionsClient { - return &RoleDefinitionsClient{con: con} +// options - pass nil to accept the default values. +func NewRoleDefinitionsClient(options *azcore.ClientOptions) *RoleDefinitionsClient { + cp := azcore.ClientOptions{} + if options != nil { + cp = *options + } + client := &RoleDefinitionsClient{ + pl: runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{}, &cp), + } + return client } // CreateOrUpdate - Creates or updates a custom role definition. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleDefinitionsClient) CreateOrUpdate(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, parameters RoleDefinitionCreateParameters, options *RoleDefinitionsCreateOrUpdateOptions) (RoleDefinitionsCreateOrUpdateResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role definition to create or update. Managed HSM only supports '/'. +// roleDefinitionName - The name of the role definition to create or update. It can be any valid GUID. +// parameters - Parameters for the role definition. +// options - RoleDefinitionsClientCreateOrUpdateOptions contains the optional parameters for the RoleDefinitionsClient.CreateOrUpdate +// method. +func (client *RoleDefinitionsClient) CreateOrUpdate(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, parameters RoleDefinitionCreateParameters, options *RoleDefinitionsClientCreateOrUpdateOptions) (RoleDefinitionsClientCreateOrUpdateResponse, error) { req, err := client.createOrUpdateCreateRequest(ctx, vaultBaseURL, scope, roleDefinitionName, parameters, options) if err != nil { - return RoleDefinitionsCreateOrUpdateResponse{}, err + return RoleDefinitionsClientCreateOrUpdateResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleDefinitionsCreateOrUpdateResponse{}, err + return RoleDefinitionsClientCreateOrUpdateResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusCreated) { - return RoleDefinitionsCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp) + return RoleDefinitionsClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) } return client.createOrUpdateHandleResponse(resp) } // createOrUpdateCreateRequest creates the CreateOrUpdate request. -func (client *RoleDefinitionsClient) createOrUpdateCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, parameters RoleDefinitionCreateParameters, options *RoleDefinitionsCreateOrUpdateOptions) (*policy.Request, error) { +func (client *RoleDefinitionsClient) createOrUpdateCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, parameters RoleDefinitionCreateParameters, options *RoleDefinitionsClientCreateOrUpdateOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleDefinitionName == "" { return nil, errors.New("parameter roleDefinitionName cannot be empty") @@ -72,52 +83,40 @@ func (client *RoleDefinitionsClient) createOrUpdateCreateRequest(ctx context.Con } // createOrUpdateHandleResponse handles the CreateOrUpdate response. -func (client *RoleDefinitionsClient) createOrUpdateHandleResponse(resp *http.Response) (RoleDefinitionsCreateOrUpdateResponse, error) { - result := RoleDefinitionsCreateOrUpdateResponse{RawResponse: resp} +func (client *RoleDefinitionsClient) createOrUpdateHandleResponse(resp *http.Response) (RoleDefinitionsClientCreateOrUpdateResponse, error) { + result := RoleDefinitionsClientCreateOrUpdateResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil { - return RoleDefinitionsCreateOrUpdateResponse{}, err + return RoleDefinitionsClientCreateOrUpdateResponse{}, err } return result, nil } -// createOrUpdateHandleError handles the CreateOrUpdate error response. -func (client *RoleDefinitionsClient) createOrUpdateHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // Delete - Deletes a custom role definition. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleDefinitionsClient) Delete(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsDeleteOptions) (RoleDefinitionsDeleteResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role definition to delete. Managed HSM only supports '/'. +// roleDefinitionName - The name (GUID) of the role definition to delete. +// options - RoleDefinitionsClientDeleteOptions contains the optional parameters for the RoleDefinitionsClient.Delete method. +func (client *RoleDefinitionsClient) Delete(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsClientDeleteOptions) (RoleDefinitionsClientDeleteResponse, error) { req, err := client.deleteCreateRequest(ctx, vaultBaseURL, scope, roleDefinitionName, options) if err != nil { - return RoleDefinitionsDeleteResponse{}, err + return RoleDefinitionsClientDeleteResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleDefinitionsDeleteResponse{}, err + return RoleDefinitionsClientDeleteResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoleDefinitionsDeleteResponse{}, client.deleteHandleError(resp) + return RoleDefinitionsClientDeleteResponse{}, runtime.NewResponseError(resp) } return client.deleteHandleResponse(resp) } // deleteCreateRequest creates the Delete request. -func (client *RoleDefinitionsClient) deleteCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsDeleteOptions) (*policy.Request, error) { +func (client *RoleDefinitionsClient) deleteCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsClientDeleteOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleDefinitionName == "" { return nil, errors.New("parameter roleDefinitionName cannot be empty") @@ -135,52 +134,40 @@ func (client *RoleDefinitionsClient) deleteCreateRequest(ctx context.Context, va } // deleteHandleResponse handles the Delete response. -func (client *RoleDefinitionsClient) deleteHandleResponse(resp *http.Response) (RoleDefinitionsDeleteResponse, error) { - result := RoleDefinitionsDeleteResponse{RawResponse: resp} +func (client *RoleDefinitionsClient) deleteHandleResponse(resp *http.Response) (RoleDefinitionsClientDeleteResponse, error) { + result := RoleDefinitionsClientDeleteResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil { - return RoleDefinitionsDeleteResponse{}, err + return RoleDefinitionsClientDeleteResponse{}, err } return result, nil } -// deleteHandleError handles the Delete error response. -func (client *RoleDefinitionsClient) deleteHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // Get - Get the specified role definition. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleDefinitionsClient) Get(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsGetOptions) (RoleDefinitionsGetResponse, error) { +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role definition to get. Managed HSM only supports '/'. +// roleDefinitionName - The name of the role definition to get. +// options - RoleDefinitionsClientGetOptions contains the optional parameters for the RoleDefinitionsClient.Get method. +func (client *RoleDefinitionsClient) Get(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsClientGetOptions) (RoleDefinitionsClientGetResponse, error) { req, err := client.getCreateRequest(ctx, vaultBaseURL, scope, roleDefinitionName, options) if err != nil { - return RoleDefinitionsGetResponse{}, err + return RoleDefinitionsClientGetResponse{}, err } - resp, err := client.con.Pipeline().Do(req) + resp, err := client.pl.Do(req) if err != nil { - return RoleDefinitionsGetResponse{}, err + return RoleDefinitionsClientGetResponse{}, err } if !runtime.HasStatusCode(resp, http.StatusOK) { - return RoleDefinitionsGetResponse{}, client.getHandleError(resp) + return RoleDefinitionsClientGetResponse{}, runtime.NewResponseError(resp) } return client.getHandleResponse(resp) } // getCreateRequest creates the Get request. -func (client *RoleDefinitionsClient) getCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsGetOptions) (*policy.Request, error) { +func (client *RoleDefinitionsClient) getCreateRequest(ctx context.Context, vaultBaseURL string, scope string, roleDefinitionName string, options *RoleDefinitionsClientGetOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) if roleDefinitionName == "" { return nil, errors.New("parameter roleDefinitionName cannot be empty") @@ -198,49 +185,36 @@ func (client *RoleDefinitionsClient) getCreateRequest(ctx context.Context, vault } // getHandleResponse handles the Get response. -func (client *RoleDefinitionsClient) getHandleResponse(resp *http.Response) (RoleDefinitionsGetResponse, error) { - result := RoleDefinitionsGetResponse{RawResponse: resp} +func (client *RoleDefinitionsClient) getHandleResponse(resp *http.Response) (RoleDefinitionsClientGetResponse, error) { + result := RoleDefinitionsClientGetResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinition); err != nil { - return RoleDefinitionsGetResponse{}, err + return RoleDefinitionsClientGetResponse{}, err } return result, nil } -// getHandleError handles the Get error response. -func (client *RoleDefinitionsClient) getHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} - // List - Get all role definitions that are applicable at scope and above. -// If the operation fails it returns the *KeyVaultError error type. -func (client *RoleDefinitionsClient) List(vaultBaseURL string, scope string, options *RoleDefinitionsListOptions) *RoleDefinitionsListPager { - return &RoleDefinitionsListPager{ +// If the operation fails it returns an *azcore.ResponseError type. +// vaultBaseURL - The vault name, for example https://myvault.vault.azure.net. +// scope - The scope of the role definition. +// options - RoleDefinitionsClientListOptions contains the optional parameters for the RoleDefinitionsClient.List method. +func (client *RoleDefinitionsClient) List(vaultBaseURL string, scope string, options *RoleDefinitionsClientListOptions) *RoleDefinitionsClientListPager { + return &RoleDefinitionsClientListPager{ client: client, requester: func(ctx context.Context) (*policy.Request, error) { return client.listCreateRequest(ctx, vaultBaseURL, scope, options) }, - advancer: func(ctx context.Context, resp RoleDefinitionsListResponse) (*policy.Request, error) { + advancer: func(ctx context.Context, resp RoleDefinitionsClientListResponse) (*policy.Request, error) { return runtime.NewRequest(ctx, http.MethodGet, *resp.RoleDefinitionListResult.NextLink) }, } } // listCreateRequest creates the List request. -func (client *RoleDefinitionsClient) listCreateRequest(ctx context.Context, vaultBaseURL string, scope string, options *RoleDefinitionsListOptions) (*policy.Request, error) { +func (client *RoleDefinitionsClient) listCreateRequest(ctx context.Context, vaultBaseURL string, scope string, options *RoleDefinitionsClientListOptions) (*policy.Request, error) { host := "{vaultBaseUrl}" host = strings.ReplaceAll(host, "{vaultBaseUrl}", vaultBaseURL) urlPath := "/{scope}/providers/Microsoft.Authorization/roleDefinitions" - if scope == "" { - return nil, errors.New("parameter scope cannot be empty") - } urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(host, urlPath)) if err != nil { @@ -257,23 +231,10 @@ func (client *RoleDefinitionsClient) listCreateRequest(ctx context.Context, vaul } // listHandleResponse handles the List response. -func (client *RoleDefinitionsClient) listHandleResponse(resp *http.Response) (RoleDefinitionsListResponse, error) { - result := RoleDefinitionsListResponse{RawResponse: resp} +func (client *RoleDefinitionsClient) listHandleResponse(resp *http.Response) (RoleDefinitionsClientListResponse, error) { + result := RoleDefinitionsClientListResponse{RawResponse: resp} if err := runtime.UnmarshalAsJSON(resp, &result.RoleDefinitionListResult); err != nil { - return RoleDefinitionsListResponse{}, err + return RoleDefinitionsClientListResponse{}, err } return result, nil } - -// listHandleError handles the List error response. -func (client *RoleDefinitionsClient) listHandleError(resp *http.Response) error { - body, err := runtime.Payload(resp) - if err != nil { - return runtime.NewResponseError(err, resp) - } - errType := KeyVaultError{raw: string(body)} - if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { - return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) - } - return runtime.NewResponseError(&errType, resp) -} diff --git a/sdk/keyvault/azsecrets/models.go b/sdk/keyvault/azsecrets/models.go index 9d308f75d666..5a1cf6e23de2 100644 --- a/sdk/keyvault/azsecrets/models.go +++ b/sdk/keyvault/azsecrets/models.go @@ -49,7 +49,7 @@ type Secret struct { Managed *bool `json:"managed,omitempty" azure:"ro"` } -func secretFromGenerated(i internal.SecretBundle) Secret { +func secretFromGenerated(i internal.DeletedSecretBundle) Secret { return Secret{ Attributes: secretAttributesFromGenerated(i.Attributes), ContentType: i.ContentType, @@ -91,13 +91,11 @@ func (s Attributes) toGenerated() *internal.SecretAttributes { return &internal.SecretAttributes{ RecoverableDays: s.RecoverableDays, RecoveryLevel: s.RecoveryLevel.toGenerated(), - Attributes: internal.Attributes{ - Enabled: s.Enabled, - Expires: s.Expires, - NotBefore: s.NotBefore, - Created: s.Created, - Updated: s.Updated, - }, + Enabled: s.Enabled, + Expires: s.Expires, + NotBefore: s.NotBefore, + Created: s.Created, + Updated: s.Updated, } } @@ -172,7 +170,13 @@ func deletedSecretItemFromGenerated(i *internal.DeletedSecretItem) DeletedSecret RecoveryID: i.RecoveryID, DeletedDate: i.DeletedDate, ScheduledPurgeDate: i.ScheduledPurgeDate, - Item: secretItemFromGenerated(&i.SecretItem), + Item: Item{ + Attributes: secretAttributesFromGenerated(i.Attributes), + ContentType: i.ContentType, + ID: i.ID, + Tags: convertPtrMap(i.Tags), + Managed: i.Managed, + }, } }