From 272b958a0882e007d76d186e60eed0272d99b708 Mon Sep 17 00:00:00 2001 From: Fan Shang Xiang Date: Mon, 2 Dec 2024 08:29:00 +0800 Subject: [PATCH] add update function for account client (#7705) --- pkg/azclient/accountclient/custom.go | 11 ++ pkg/azclient/accountclient/custom_test.go | 17 ++ pkg/azclient/accountclient/interface.go | 1 + .../accountclient/testdata/Account.yaml | 158 ++++++++++++++++-- 4 files changed, 171 insertions(+), 16 deletions(-) diff --git a/pkg/azclient/accountclient/custom.go b/pkg/azclient/accountclient/custom.go index c94acad9aa..2b73ed9b32 100644 --- a/pkg/azclient/accountclient/custom.go +++ b/pkg/azclient/accountclient/custom.go @@ -38,6 +38,17 @@ func (client *Client) Create(ctx context.Context, resourceGroupName string, reso return nil, nil } +func (client *Client) Update(ctx context.Context, resourceGroupName string, resourceName string, parameters *armstorage.AccountUpdateParameters) (*armstorage.Account, error) { + if parameters == nil { + parameters = &armstorage.AccountUpdateParameters{} + } + resp, err := client.AccountsClient.Update(ctx, resourceGroupName, resourceName, *parameters, nil) + if err != nil { + return nil, err + } + return &resp.Account, nil +} + func (client *Client) GetProperties(ctx context.Context, resourceGroupName string, accountName string, options *armstorage.AccountsClientGetPropertiesOptions) (*armstorage.Account, error) { resp, err := client.AccountsClient.GetProperties(ctx, resourceGroupName, accountName, options) if err != nil { diff --git a/pkg/azclient/accountclient/custom_test.go b/pkg/azclient/accountclient/custom_test.go index 0d93f150e0..339c6e8763 100644 --- a/pkg/azclient/accountclient/custom_test.go +++ b/pkg/azclient/accountclient/custom_test.go @@ -85,6 +85,23 @@ func init() { Expect(newResource).To(BeNil()) }) }) + When("update requests are raised", func() { + It("should not return error", func(ctx context.Context) { + newResource, err := realClient.Update(ctx, resourceGroupName, resourceName, &armstorage.AccountUpdateParameters{ + Properties: &armstorage.AccountPropertiesUpdateParameters{ + AllowBlobPublicAccess: to.Ptr(false), + AllowSharedKeyAccess: to.Ptr(false), + }, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(*newResource.Properties.AllowBlobPublicAccess).To(BeFalse()) + }) + It("should not return error when body is nil", func(ctx context.Context) { + newResource, err := realClient.Update(ctx, resourceGroupName, resourceName, nil) + Expect(err).NotTo(HaveOccurred()) + Expect(newResource).NotTo(BeNil()) + }) + }) When("listkeys requests are raised", func() { It("should not return error", func(ctx context.Context) { diff --git a/pkg/azclient/accountclient/interface.go b/pkg/azclient/accountclient/interface.go index 94a40439eb..1d646c1ff8 100644 --- a/pkg/azclient/accountclient/interface.go +++ b/pkg/azclient/accountclient/interface.go @@ -29,6 +29,7 @@ import ( type Interface interface { utils.ListFunc[armstorage.Account] Create(ctx context.Context, resourceGroupName string, accountName string, resource *armstorage.AccountCreateParameters) (*armstorage.Account, error) + Update(ctx context.Context, resourceGroupName string, accountName string, parameters *armstorage.AccountUpdateParameters) (*armstorage.Account, error) GetProperties(ctx context.Context, resourceGroupName string, accountName string, options *armstorage.AccountsClientGetPropertiesOptions) (*armstorage.Account, error) Delete(ctx context.Context, resourceGroupName string, accountName string) error ListKeys(ctx context.Context, resourceGroupName string, accountName string) ([]*armstorage.AccountKey, error) diff --git a/pkg/azclient/accountclient/testdata/Account.yaml b/pkg/azclient/accountclient/testdata/Account.yaml index 8eee8bae05..e46f754742 100644 --- a/pkg/azclient/accountclient/testdata/Account.yaml +++ b/pkg/azclient/accountclient/testdata/Account.yaml @@ -22,7 +22,7 @@ interactions: Content-Type: - application/json User-Agent: - - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.1; linux) + - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aks-cit-Account?api-version=2021-04-01 method: PUT response: @@ -51,6 +51,8 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Writes: + - "11999" status: 201 Created code: 201 duration: 200ms @@ -75,7 +77,7 @@ interactions: Content-Type: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest?api-version=2023-05-01 method: PUT response: @@ -106,6 +108,8 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Writes: + - "12000" status: 202 Accepted code: 202 duration: 200ms @@ -124,7 +128,7 @@ interactions: form: {} headers: User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Storage/locations/eastus/asyncoperations/00000000-0000-0000-0000-000000000000?api-version=2023-05-01&c=c&h=h&monitor=true&s=s&t=t method: GET response: @@ -153,6 +157,8 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Reads: + - "16499" status: 200 OK code: 200 duration: 200ms @@ -173,7 +179,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest?api-version=2023-05-01 method: GET response: @@ -202,6 +208,8 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Reads: + - "16499" status: 200 OK code: 200 duration: 200ms @@ -222,7 +230,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktestnotfound?api-version=2023-05-01 method: GET response: @@ -257,6 +265,116 @@ interactions: code: 404 duration: 200ms - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 75 + transfer_encoding: [] + trailer: {} + host: management.azure.com + remote_addr: "" + request_uri: "" + body: '{"properties":{"allowBlobPublicAccess":false,"allowSharedKeyAccess":false}}' + form: {} + headers: + Accept: + - application/json + Content-Length: + - "75" + Content-Type: + - application/json + User-Agent: + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) + url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest?api-version=2023-05-01 + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1617 + uncompressed: false + body: '{"sku":{"name":"Standard_GRS","tier":"Standard"},"kind":"Storage","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest","name":"akscitaccountsdktest","type":"Microsoft.Storage/storageAccounts","location":"eastus","tags":{},"properties":{"defaultToOAuthAuthentication":false,"keyPolicy":{"keyExpirationPeriodInDays":20},"keyCreationTime":{"key1":"2001-02-03T04:05:06Z","key2":"2001-02-03T04:05:06Z"},"allowCrossTenantReplication":false,"privateEndpointConnections":[],"isSftpEnabled":false,"minimumTlsVersion":"TLS1_2","allowBlobPublicAccess":false,"allowSharedKeyAccess":false,"isHnsEnabled":false,"networkAcls":{"ipv6Rules":[],"bypass":"AzureServices","virtualNetworkRules":[],"ipRules":[],"defaultAction":"Allow"},"supportsHttpsTrafficOnly":true,"encryption":{"requireInfrastructureEncryption":false,"services":{"file":{"keyType":"Account","enabled":true,"lastEnabledTime":"2001-02-03T04:05:06Z"},"blob":{"keyType":"Account","enabled":true,"lastEnabledTime":"2001-02-03T04:05:06Z"}},"keySource":"Microsoft.Storage"},"provisioningState":"Succeeded","creationTime":"2001-02-03T04:05:06Z","primaryEndpoints":{"blob":"https://akscitaccountsdktest.blob.core.windows.net/","queue":"https://akscitaccountsdktest.queue.core.windows.net/","table":"https://akscitaccountsdktest.table.core.windows.net/","file":"https://akscitaccountsdktest.file.core.windows.net/"},"primaryLocation":"eastus","statusOfPrimary":"available","secondaryLocation":"westus","statusOfSecondary":"available"}}' + headers: + Cache-Control: + - no-cache + Content-Length: + - "1617" + Content-Type: + - application/json + Expires: + - "-1" + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + X-Cache: + - CONFIG_NOCACHE + X-Content-Type-Options: + - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Writes: + - "11999" + status: 200 OK + code: 200 + duration: 200ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 2 + transfer_encoding: [] + trailer: {} + host: management.azure.com + remote_addr: "" + request_uri: "" + body: '{}' + form: {} + headers: + Accept: + - application/json + Content-Length: + - "2" + Content-Type: + - application/json + User-Agent: + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) + url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest?api-version=2023-05-01 + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1617 + uncompressed: false + body: '{"sku":{"name":"Standard_GRS","tier":"Standard"},"kind":"Storage","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest","name":"akscitaccountsdktest","type":"Microsoft.Storage/storageAccounts","location":"eastus","tags":{},"properties":{"defaultToOAuthAuthentication":false,"keyPolicy":{"keyExpirationPeriodInDays":20},"keyCreationTime":{"key1":"2001-02-03T04:05:06Z","key2":"2001-02-03T04:05:06Z"},"allowCrossTenantReplication":false,"privateEndpointConnections":[],"isSftpEnabled":false,"minimumTlsVersion":"TLS1_2","allowBlobPublicAccess":false,"allowSharedKeyAccess":false,"isHnsEnabled":false,"networkAcls":{"ipv6Rules":[],"bypass":"AzureServices","virtualNetworkRules":[],"ipRules":[],"defaultAction":"Allow"},"supportsHttpsTrafficOnly":true,"encryption":{"requireInfrastructureEncryption":false,"services":{"file":{"keyType":"Account","enabled":true,"lastEnabledTime":"2001-02-03T04:05:06Z"},"blob":{"keyType":"Account","enabled":true,"lastEnabledTime":"2001-02-03T04:05:06Z"}},"keySource":"Microsoft.Storage"},"provisioningState":"Succeeded","creationTime":"2001-02-03T04:05:06Z","primaryEndpoints":{"blob":"https://akscitaccountsdktest.blob.core.windows.net/","queue":"https://akscitaccountsdktest.queue.core.windows.net/","table":"https://akscitaccountsdktest.table.core.windows.net/","file":"https://akscitaccountsdktest.file.core.windows.net/"},"primaryLocation":"eastus","statusOfPrimary":"available","secondaryLocation":"westus","statusOfSecondary":"available"}}' + headers: + Cache-Control: + - no-cache + Content-Length: + - "1617" + Content-Type: + - application/json + Expires: + - "-1" + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + X-Cache: + - CONFIG_NOCACHE + X-Content-Type-Options: + - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Writes: + - "11999" + status: 200 OK + code: 200 + duration: 200ms + - id: 7 request: proto: HTTP/1.1 proto_major: 1 @@ -273,7 +391,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest/listKeys?api-version=2023-05-01 method: POST response: @@ -305,7 +423,7 @@ interactions: status: 200 OK code: 200 duration: 200ms - - id: 6 + - id: 8 request: proto: HTTP/1.1 proto_major: 1 @@ -322,7 +440,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts?api-version=2023-05-01 method: GET response: @@ -351,10 +469,12 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Reads: + - "16499" status: 200 OK code: 200 duration: 200ms - - id: 7 + - id: 9 request: proto: HTTP/1.1 proto_major: 1 @@ -371,7 +491,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Accountnotfound/providers/Microsoft.Storage/storageAccounts?api-version=2023-05-01 method: GET response: @@ -405,7 +525,7 @@ interactions: status: 404 Not Found code: 404 duration: 200ms - - id: 8 + - id: 10 request: proto: HTTP/1.1 proto_major: 1 @@ -420,7 +540,7 @@ interactions: form: {} headers: User-Agent: - - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.1; linux) + - ccm-Account-client azsdk-go-armstorage/v1.6.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/aks-cit-Account/providers/Microsoft.Storage/storageAccounts/akscitaccountsdktest?api-version=2023-05-01 method: DELETE response: @@ -449,10 +569,12 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Deletes: + - "12000" status: 200 OK code: 200 duration: 200ms - - id: 9 + - id: 11 request: proto: HTTP/1.1 proto_major: 1 @@ -469,7 +591,7 @@ interactions: Accept: - application/json User-Agent: - - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.1; linux) + - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aks-cit-Account?api-version=2021-04-01 method: DELETE response: @@ -498,10 +620,12 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Deletes: + - "12000" status: 202 Accepted code: 202 duration: 200ms - - id: 10 + - id: 12 request: proto: HTTP/1.1 proto_major: 1 @@ -516,7 +640,7 @@ interactions: form: {} headers: User-Agent: - - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.1; linux) + - ccm-resource-group-clien azsdk-go-armresources/v1.2.0 (go1.23.2; linux) url: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1BS1M6MkRDSVQ6MkRBQ0NPVU5ULUVBU1RVUyIsImpvYkxvY2F0aW9uIjoiZWFzdHVzIn0?api-version=2021-04-01&c=c&h=h&s=s&t=t method: GET response: @@ -543,6 +667,8 @@ interactions: - CONFIG_NOCACHE X-Content-Type-Options: - nosniff + X-Ms-Ratelimit-Remaining-Subscription-Global-Reads: + - "16499" status: 200 OK code: 200 duration: 200ms