From 088d5b01dc390d17c755513f8c87e13c34cc9995 Mon Sep 17 00:00:00 2001 From: Sean Kane <68240067+seankane-msft@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:11:18 -0400 Subject: [PATCH] [Tables] bump deps (#15350) * Sync eng/common directory with azure-sdk-tools for PR 1912 (#15314) * Attempt to purge all vaults, managed HSMs Reverts #1910. Vaults and managed HSMs are automatically purged on their purge date. The point was to purge them daily to preserve capacity. The default purge date is +90 days. * Add timeout and more logging * Pass required -Resource * Fix log message * Ensure the $Resource is correctly captured Added comment to new code explaining why, since ScriptBlock.GetNewClosure() is not working as expected. * Add -ErrorAction to Receive-Job Worked without terminating when run locally, but failed on the first error in the AzDO agent. * Use $using:r instead of creating ScriptBlock More idiomatic for passing ScriptBlocks to jobs. * Resolve PR feedback * Change default DeleteAfterHours to 120 Resolves #1917 * Use the Az cmdlets built-in -AsJob Co-authored-by: Heath Stewart * Fix query batch processing (#15319) Co-authored-by: Wes Haggard * fix: three dots path not work in linux in build script (#15297) * Release v56.3.0 1629350585 (#15323) * Generated from specification/apimanagement/resource-manager/readme.md tag package-preview-2021-01 (commit hash: 30d1537f0c9aa49e6e04401b1d16f612b31231e7) * Generated from specification/purview/resource-manager/readme.md tag package-2021-07-01 (commit hash: 30d1537f0c9aa49e6e04401b1d16f612b31231e7) * v56.3.0 * fix * Remove old unused update changelog script (#15326) Co-authored-by: Wes Haggard * add clear output flag to build.ps1 (#15255) * add clear output flag * remove the path parameter and make sure the process-sdk function only runs in current directory * change flag name * [tools/generator] add automation and release command for track2 (#15271) * [tools/generator] add automation and release command for track2 * add copyright and do gofmt * Use semver to pump version, move git operation to repo package and fix some typo * Add specfic version to release cmd, seperate package for automation and remove test config file * add automation script and config for track2 * fix: three dots path not work in linux in build script * fix: ln pwsh.exe to pwsh to run in linux * fix: ignore dep check for go-git * chore: label name change for track2 * fix: wrong package path result in empty git commit * fix: repo addr replacement in autorest.md * chore: move script to eng folder and change name * fix: onboard generation need to replace NewClientMethod * chore: change all naming from track2 to v2 * fix: add new build constraint * fix: template compat with go 1.17 and change commit msg for release * chore: add v2 to readme begin regex to support future change of `track2` naming * chore: remove track2 naming * fix: duplicated and wrong expression * fix: add package title param to release cmd * fix: ci * Prevent ManagedIdentityCredential mutating GetToken arguments (#15331) * [Azcore] bumps version of internal (#15347) * bump internal to latest * upgrading internal * not the correct one * changelog update * [azidentity] bump azcore and internal dependencies (#15348) * updating to latest core and identity * trying to fix merge * undoing changes to identity that should not be there * more changes * more changes * removing a bunch more * one last file * formatting * linting checks * linting * formatting Co-authored-by: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Co-authored-by: Heath Stewart Co-authored-by: Wes Haggard Co-authored-by: tadelesh Co-authored-by: JiahuiPeng <46921893+804873052@users.noreply.github.com> Co-authored-by: Arcturus Co-authored-by: Charles Lowell --- sdk/internal/recording/recording.go | 268 ++++++++++++++++++ sdk/tables/aztable/consts.go | 9 + .../aztable/cosmos_patch_transform_policy.go | 3 +- sdk/tables/aztable/errors.go | 4 +- sdk/tables/aztable/go.mod | 11 +- sdk/tables/aztable/go.sum | 19 +- sdk/tables/aztable/proxy_test.go | 43 ++- sdk/tables/aztable/sas_query_params.go | 4 +- .../aztable/shared_access_signature_test.go | 24 +- .../shared_policy_shared_key_credential.go | 64 +++-- .../aztable/table_access_policy_test.go | 2 +- sdk/tables/aztable/table_batch_test.go | 45 ++- sdk/tables/aztable/table_client.go | 10 +- sdk/tables/aztable/table_client_test.go | 35 +-- sdk/tables/aztable/table_pagers.go | 14 +- sdk/tables/aztable/table_pagers_test.go | 42 --- sdk/tables/aztable/table_service_client.go | 2 +- .../aztable/table_service_client_test.go | 9 +- .../aztable/table_transactional_batch.go | 62 ++-- sdk/tables/aztable/zc_client_options.go | 2 +- sdk/tables/aztable/zc_table_constants.go | 27 +- sdk/tables/aztable/zt_table_recorded_tests.go | 49 +--- sdk/tables/aztable/zz_generated_connection.go | 3 +- sdk/tables/aztable/zz_generated_constants.go | 1 + sdk/tables/aztable/zz_generated_models.go | 1 + .../aztable/zz_generated_response_types.go | 1 + .../aztable/zz_generated_service_client.go | 62 ++-- .../aztable/zz_generated_table_client.go | 216 +++++++------- .../aztable/zz_generated_time_rfc1123.go | 1 + .../aztable/zz_generated_time_rfc3339.go | 1 + 30 files changed, 632 insertions(+), 402 deletions(-) create mode 100644 sdk/tables/aztable/consts.go delete mode 100644 sdk/tables/aztable/table_pagers_test.go diff --git a/sdk/internal/recording/recording.go b/sdk/internal/recording/recording.go index 26d34cd57a07..92f8785ebdb7 100644 --- a/sdk/internal/recording/recording.go +++ b/sdk/internal/recording/recording.go @@ -7,6 +7,10 @@ package recording import ( + "bytes" + "crypto/tls" + "crypto/x509" + "encoding/json" "errors" "fmt" "io/ioutil" @@ -16,6 +20,7 @@ import ( "path/filepath" "strconv" "strings" + "testing" "time" "github.com/Azure/azure-sdk-for-go/sdk/internal/uuid" @@ -433,3 +438,266 @@ var modeMap = map[RecordMode]recorder.Mode{ Live: recorder.ModeDisabled, Playback: recorder.ModeReplaying, } + +var recordMode, _ = os.LookupEnv("AZURE_RECORD_MODE") +var ModeRecording = "record" +var ModePlayback = "playback" + +var baseProxyURLSecure = "localhost:5001" +var baseProxyURL = "localhost:5000" + +var recordingId string +var IdHeader = "x-recording-id" +var ModeHeader = "x-recording-mode" +var UpstreamUriHeader = "x-recording-upstream-base-uri" + +var tr = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, +} +var client = http.Client{ + Transport: tr, +} + +type RecordingOptions struct { + MaxRetries int32 + UseHTTPS bool + Host string + Scheme string +} + +func defaultOptions() *RecordingOptions { + return &RecordingOptions{ + MaxRetries: 0, + UseHTTPS: true, + Host: "localhost:5001", + Scheme: "https", + } +} + +func (r RecordingOptions) HostScheme() string { + if r.UseHTTPS { + return "https://localhost:5001" + } + return "http://localhost:5000" +} + +func getTestId(pathToRecordings string, t *testing.T) string { + return pathToRecordings + "/recordings/" + t.Name() + ".json" +} + +func StartRecording(t *testing.T, pathToRecordings string, options *RecordingOptions) error { + if options == nil { + options = defaultOptions() + } + if recordMode == "" { + t.Log("AZURE_RECORD_MODE was not set, options are \"record\" or \"playback\". \nDefaulting to playback") + recordMode = "playback" + } else { + t.Log("AZURE_RECORD_MODE: ", recordMode) + } + testId := getTestId(pathToRecordings, t) + + url := fmt.Sprintf("%v/%v/start", options.HostScheme(), recordMode) + + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return err + } + + req.Header.Set("x-recording-file", testId) + + resp, err := client.Do(req) + if err != nil { + return err + } + recordingId = resp.Header.Get(IdHeader) + return nil +} + +func StopRecording(t *testing.T, options *RecordingOptions) error { + if options == nil { + options = defaultOptions() + } + + url := fmt.Sprintf("%v/%v/stop", options.HostScheme(), recordMode) + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return err + } + if recordingId == "" { + return errors.New("Recording ID was never set. Did you call StartRecording?") + } + req.Header.Set("x-recording-id", recordingId) + _, err = client.Do(req) + if err != nil { + t.Errorf(err.Error()) + } + return nil +} + +func AddUriSanitizer(replacement, regex string, options *RecordingOptions) error { + if options == nil { + options = defaultOptions() + } + url := fmt.Sprintf("%v/Admin/AddSanitizer", options.HostScheme()) + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return err + } + req.Header.Set("x-abstraction-identifier", "UriRegexSanitizer") + bodyContent := map[string]string{ + "value": replacement, + "regex": regex, + } + marshalled, err := json.Marshal(bodyContent) + if err != nil { + return err + } + req.Body = ioutil.NopCloser(bytes.NewReader(marshalled)) + req.ContentLength = int64(len(marshalled)) + _, err = client.Do(req) + return err +} + +func (o *RecordingOptions) Init() { + if o.MaxRetries != 0 { + o.MaxRetries = 0 + } + if o.UseHTTPS { + o.Host = baseProxyURLSecure + o.Scheme = "https" + } else { + o.Host = baseProxyURL + o.Scheme = "http" + } +} + +// type recordingPolicy struct { +// options RecordingOptions +// } + +// func NewRecordingPolicy(o *RecordingOptions) azcore.Policy { +// if o == nil { +// o = &RecordingOptions{} +// } +// p := &recordingPolicy{options: *o} +// p.options.init() +// return p +// } + +// func (p *recordingPolicy) Do(req *azcore.Request) (resp *azcore.Response, err error) { +// originalURLHost := req.URL.Host +// req.URL.Scheme = "https" +// req.URL.Host = p.options.host +// req.Host = p.options.host + +// req.Header.Set(UpstreamUriHeader, fmt.Sprintf("%v://%v", p.options.scheme, originalURLHost)) +// req.Header.Set(ModeHeader, recordMode) +// req.Header.Set(IdHeader, recordingId) + +// return req.Next() +// } + +// This looks up an environment variable and if it is not found, returns the recordedValue +func GetEnvVariable(t *testing.T, varName string, recordedValue string) string { + val, ok := os.LookupEnv(varName) + if !ok { + t.Logf("Could not find environment variable: %v", varName) + return recordedValue + } + return val +} + +func LiveOnly(t *testing.T) { + if GetRecordMode() != ModeRecording { + t.Skip("Live Test Only") + } +} + +// Function for sleeping during a test for `duration` seconds. This method will only execute when +// AZURE_RECORD_MODE = "record", if a test is running in playback this will be a noop. +func Sleep(duration int) { + if GetRecordMode() == ModeRecording { + time.Sleep(time.Duration(duration) * time.Second) + } +} + +func GetRecordingId() string { + return recordingId +} + +func GetRecordMode() string { + return recordMode +} + +func InPlayback() bool { + return GetRecordMode() == ModePlayback +} + +func InRecord() bool { + return GetRecordMode() == ModeRecording +} + +// type FakeCredential struct { +// accountName string +// accountKey string +// } + +// func NewFakeCredential(accountName, accountKey string) *FakeCredential { +// return &FakeCredential{ +// accountName: accountName, +// accountKey: accountKey, +// } +// } + +// func (f *FakeCredential) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { +// return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { +// authHeader := strings.Join([]string{"Authorization ", f.accountName, ":", f.accountKey}, "") +// req.Request.Header.Set(azcore.HeaderAuthorization, authHeader) +// return req.Next() +// }) +// } + +func getRootCas() (*x509.CertPool, error) { + localFile, ok := os.LookupEnv("PROXY_CERT") + + rootCAs, err := x509.SystemCertPool() + if err != nil { + rootCAs = x509.NewCertPool() + } + + if !ok { + fmt.Println("Could not find path to proxy certificate, set the environment variable 'PROXY_CERT' to the location of your certificate") + return rootCAs, nil + } + + cert, err := ioutil.ReadFile(localFile) + if err != nil { + fmt.Println("error opening cert file") + return nil, err + } + + if ok := rootCAs.AppendCertsFromPEM(cert); !ok { + fmt.Println("No certs appended, using system certs only") + } + + return rootCAs, nil +} + +func GetHTTPClient() (*http.Client, error) { + transport := http.DefaultTransport.(*http.Transport).Clone() + + rootCAs, err := getRootCas() + if err != nil { + return nil, err + } + + transport.TLSClientConfig.RootCAs = rootCAs + transport.TLSClientConfig.MinVersion = tls.VersionTLS12 + transport.TLSClientConfig.InsecureSkipVerify = true + + defaultHttpClient := &http.Client{ + Transport: transport, + } + return defaultHttpClient, nil +} diff --git a/sdk/tables/aztable/consts.go b/sdk/tables/aztable/consts.go new file mode 100644 index 000000000000..f97dfa2121c3 --- /dev/null +++ b/sdk/tables/aztable/consts.go @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package aztable + +const ( + headerXmsDate = "x-ms-date" + headerAuthorization = "Authorization" +) diff --git a/sdk/tables/aztable/cosmos_patch_transform_policy.go b/sdk/tables/aztable/cosmos_patch_transform_policy.go index 8403a0893e67..8c7447a304e8 100644 --- a/sdk/tables/aztable/cosmos_patch_transform_policy.go +++ b/sdk/tables/aztable/cosmos_patch_transform_policy.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -14,7 +15,7 @@ import ( // cosmosPatchTransformPolicy transforms PATCH requests into POST requests with the "X-HTTP-Method":"MERGE" header set. type cosmosPatchTransformPolicy struct{} -func (p cosmosPatchTransformPolicy) Do(req *azcore.Request) (*azcore.Response, error) { +func (p cosmosPatchTransformPolicy) Do(req *azcore.Request) (*http.Response, error) { transformPatchToCosmosPost(req) return req.Next() } diff --git a/sdk/tables/aztable/errors.go b/sdk/tables/aztable/errors.go index 1152898a309e..b2b883f50136 100644 --- a/sdk/tables/aztable/errors.go +++ b/sdk/tables/aztable/errors.go @@ -9,11 +9,11 @@ var errInvalidUpdateMode = errors.New("invalid EntityUpdateMode") func checkEntityForPkRk(entity *map[string]interface{}, err error) error { if _, ok := (*entity)[partitionKey]; !ok { - return partitionKeyRowKeyError + return errPartitionKeyRowKeyError } if _, ok := (*entity)[rowKey]; !ok { - return partitionKeyRowKeyError + return errPartitionKeyRowKeyError } return err diff --git a/sdk/tables/aztable/go.mod b/sdk/tables/aztable/go.mod index d221fb14275b..4c10fa962220 100644 --- a/sdk/tables/aztable/go.mod +++ b/sdk/tables/aztable/go.mod @@ -3,15 +3,12 @@ module github.com/Azure/azure-sdk-for-go/sdk/tables/aztable go 1.13 replace github.com/Azure/azure-sdk-for-go/sdk/internal => ../../internal -replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity -replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azcore require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.2 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.2 // indirect - github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 - github.com/Azure/azure-sdk-for-go/sdk/to v0.1.4 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.18.1 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.3 + github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 + github.com/Azure/azure-sdk-for-go/sdk/to v0.1.4 github.com/stretchr/testify v1.7.0 - golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/sdk/tables/aztable/go.sum b/sdk/tables/aztable/go.sum index 011ec80c81be..8aa9657f874b 100644 --- a/sdk/tables/aztable/go.sum +++ b/sdk/tables/aztable/go.sum @@ -1,10 +1,7 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.14.0/go.mod h1:pElNP+u99BvCZD+0jOlhI9OC/NB2IDTOTGZOZH0Qhq8= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.1 h1:yQw8Ah26gBP4dv66ZNjZpRBRV+gaHH/0TLn1taU4FZ4= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.1/go.mod h1:MVdrcUC4Hup35qHym3VdzoW+NBgBxrta9Vei97jRtM8= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.2 h1:UC4vfOhW2l0f2QOCQpOxJS4/K6oKFy2tQZE+uWU1MEo= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.2/go.mod h1:MVdrcUC4Hup35qHym3VdzoW+NBgBxrta9Vei97jRtM8= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.2 h1:3W8umQHRg0DXV5KvmbqU43uFi8MKvqLHQCE8L8v6Xds= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.2/go.mod h1:acANgl9stsT5xflESXKjZx4rhZJSr0TGgTDYY0xJPIE= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.18.1 h1:BxW0zeNz9VbxtaeyuwAsgZ2WgCG7wwjb17H3f5czlp4= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.18.1/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.3 h1:xxhrKdJQHnbzyquwt4GJuK0xGYIchlxtrbOCy1RcXyg= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.3/go.mod h1:uuSIs9Jj5y1WfsKhk9xGaEzyu/5SEmdKwY3Oi0UK59M= github.com/Azure/azure-sdk-for-go/sdk/to v0.1.4 h1:3w4gk+uYOwplGhID1fDP305/8bI5Aug3URoC1V493KU= github.com/Azure/azure-sdk-for-go/sdk/to v0.1.4/go.mod h1:UL/d4lvWAzSJUuX+19uKdN0ktyjoOyQhgY+HWNgtIYI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= @@ -16,7 +13,6 @@ github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7T github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= 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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -26,11 +22,8 @@ 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-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I= -golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +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/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= diff --git a/sdk/tables/aztable/proxy_test.go b/sdk/tables/aztable/proxy_test.go index d79f395a4e11..da3f785bf0ad 100644 --- a/sdk/tables/aztable/proxy_test.go +++ b/sdk/tables/aztable/proxy_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "hash/fnv" + "net/http" "strings" "testing" @@ -18,6 +19,8 @@ import ( var AADAuthenticationScope = "https://storage.azure.com/.default" +var pathToPackage = "sdk/tables/aztable" + type recordingPolicy struct { options recording.RecordingOptions } @@ -31,7 +34,7 @@ func NewRecordingPolicy(o *recording.RecordingOptions) azcore.Policy { return p } -func (p *recordingPolicy) Do(req *azcore.Request) (resp *azcore.Response, err error) { +func (p *recordingPolicy) Do(req *azcore.Request) (resp *http.Response, err error) { originalURLHost := req.URL.Host req.URL.Scheme = "https" req.URL.Host = p.options.Host @@ -56,12 +59,22 @@ func NewFakeCredential(accountName, accountKey string) *FakeCredential { } } -func (f *FakeCredential) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { - return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { - authHeader := strings.Join([]string{"Authorization ", f.accountName, ":", f.accountKey}, "") - req.Request.Header.Set(azcore.HeaderAuthorization, authHeader) - return req.Next() - }) +type fakeCredPolicy struct { + cred *FakeCredential +} + +func newFakeCredPolicy(cred *FakeCredential, opts azcore.AuthenticationOptions) *fakeCredPolicy { + return &fakeCredPolicy{cred: cred} +} + +func (f *fakeCredPolicy) Do(req *azcore.Request) (*http.Response, error) { + authHeader := strings.Join([]string{"Authorization ", f.cred.accountName, ":", f.cred.accountKey}, "") + req.Request.Header.Set(headerAuthorization, authHeader) + return req.Next() +} + +func (f *FakeCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { + return newFakeCredPolicy(f, options) } func createTableClientForRecording(t *testing.T, tableName string, serviceURL string, cred azcore.Credential) (*TableClient, error) { @@ -99,7 +112,7 @@ func initClientTest(t *testing.T, service string, createTable bool) (*TableClien require.NoError(t, err) } - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) if createTable { @@ -126,7 +139,7 @@ func initServiceTest(t *testing.T, service string) (*TableServiceClient, func()) require.NoError(t, err) } - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) return client, func() { @@ -165,6 +178,9 @@ func getSharedKeyCredential(t *testing.T) (azcore.Credential, error) { func createStorageTableClient(t *testing.T) (*TableClient, error) { var cred azcore.Credential accountName := recording.GetEnvVariable(t, "TABLES_STORAGE_ACCOUNT_NAME", "fakestorageaccount") + if recording.InPlayback() { + accountName = "fakestorageaccount" + } cred, err := getAADCredential(t) require.NoError(t, err) @@ -180,6 +196,9 @@ func createStorageTableClient(t *testing.T) (*TableClient, error) { func createCosmosTableClient(t *testing.T) (*TableClient, error) { var cred azcore.Credential accountName := recording.GetEnvVariable(t, "TABLES_COSMOS_ACCOUNT_NAME", "fakestorageaccount") + if recording.InPlayback() { + accountName = "fakestorageaccount" + } cred, err := getSharedKeyCredential(t) require.NoError(t, err) @@ -195,6 +214,9 @@ func createCosmosTableClient(t *testing.T) (*TableClient, error) { func createStorageServiceClient(t *testing.T) (*TableServiceClient, error) { var cred azcore.Credential accountName := recording.GetEnvVariable(t, "TABLES_STORAGE_ACCOUNT_NAME", "fakestorageaccount") + if recording.InPlayback() { + accountName = "fakestorageaccount" + } cred, err := getAADCredential(t) require.NoError(t, err) @@ -207,6 +229,9 @@ func createStorageServiceClient(t *testing.T) (*TableServiceClient, error) { func createCosmosServiceClient(t *testing.T) (*TableServiceClient, error) { var cred azcore.Credential accountName := recording.GetEnvVariable(t, "TABLES_COSMOS_ACCOUNT_NAME", "fakestorageaccount") + if recording.InPlayback() { + accountName = "fakestorageaccount" + } cred, err := getSharedKeyCredential(t) require.NoError(t, err) diff --git a/sdk/tables/aztable/sas_query_params.go b/sdk/tables/aztable/sas_query_params.go index f313f74adfb7..1827d1f6967c 100644 --- a/sdk/tables/aztable/sas_query_params.go +++ b/sdk/tables/aztable/sas_query_params.go @@ -56,7 +56,7 @@ func formatSASTime(t *time.Time, format string) string { } // parseSASTimeString try to parse sas time string. -func parseSASTimeString(val string) (t time.Time, timeFormat string, err error) { +func parseSASTimeString(val string) (t time.Time, timeFormat string, err error) { //nolint for _, sasTimeFormat := range SASTimeFormats { t, err = time.Parse(sasTimeFormat, val) if err == nil { @@ -184,7 +184,7 @@ func (ipr *IPRange) String() string { // query parameter map's passed-in values. If deleteSASParametersFromValues is true, // all SAS-related query parameters are removed from the passed-in map. If // deleteSASParametersFromValues is false, the map passed-in map is unaltered. -func newSASQueryParameters(values url.Values, deleteSASParametersFromValues bool) SASQueryParameters { +func newSASQueryParameters(values url.Values, deleteSASParametersFromValues bool) SASQueryParameters { //nolint p := SASQueryParameters{} for k, v := range values { val := v[0] diff --git a/sdk/tables/aztable/shared_access_signature_test.go b/sdk/tables/aztable/shared_access_signature_test.go index 124af26e2aa3..2ce8451bab57 100644 --- a/sdk/tables/aztable/shared_access_signature_test.go +++ b/sdk/tables/aztable/shared_access_signature_test.go @@ -58,11 +58,11 @@ func TestSASServiceClient(t *testing.T) { sasUrl := fmt.Sprintf("https://%s.table.core.windows.net/?%s", accountName, queryParams) - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) - client, err := createTableClientForRecording(t, tableName, sasUrl, azcore.AnonymousCredential()) + client, err := createTableClientForRecording(t, tableName, sasUrl, azcore.NewAnonymousCredential()) require.NoError(t, err) - defer recording.StopRecording(t, nil) + defer recording.StopRecording(t, nil) //nolint entity := map[string]string{ "PartitionKey": "pk001", @@ -113,11 +113,11 @@ func TestSASTableClient(t *testing.T) { sasUrl := fmt.Sprintf("https://%s.table.core.windows.net/?%s", accountName, queryParams) - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) - client, err := createTableClientForRecording(t, tableName, sasUrl, azcore.AnonymousCredential()) + client, err := createTableClientForRecording(t, tableName, sasUrl, azcore.NewAnonymousCredential()) require.NoError(t, err) - defer recording.StopRecording(t, nil) + defer recording.StopRecording(t, nil) //nolint entity := map[string]string{ "PartitionKey": "pk001", @@ -170,11 +170,11 @@ func TestSASTableClientReadOnly(t *testing.T) { sasUrl := fmt.Sprintf("https://%s.table.core.windows.net/?%s", accountName, queryParams) - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) - client, err = createTableClientForRecording(t, tableName, sasUrl, azcore.AnonymousCredential()) + client, err = createTableClientForRecording(t, tableName, sasUrl, azcore.NewAnonymousCredential()) require.NoError(t, err) - defer recording.StopRecording(t, nil) + defer recording.StopRecording(t, nil) //nolint entity := map[string]string{ "PartitionKey": "pk001", @@ -236,11 +236,11 @@ func TestSASCosmosTableClientReadOnly(t *testing.T) { sasUrl := fmt.Sprintf("https://%s.table.cosmos.azure.com/?%s", accountName, queryParams) - err = recording.StartRecording(t, nil) + err = recording.StartRecording(t, pathToPackage, nil) require.NoError(t, err) - client, err = createTableClientForRecording(t, tableName, sasUrl, azcore.AnonymousCredential()) + client, err = createTableClientForRecording(t, tableName, sasUrl, azcore.NewAnonymousCredential()) require.NoError(t, err) - defer recording.StopRecording(t, nil) + defer recording.StopRecording(t, nil) //nolint entity := map[string]string{ "PartitionKey": "pk001", diff --git a/sdk/tables/aztable/shared_policy_shared_key_credential.go b/sdk/tables/aztable/shared_policy_shared_key_credential.go index ca011f0b5240..06c29da9bf8b 100644 --- a/sdk/tables/aztable/shared_policy_shared_key_credential.go +++ b/sdk/tables/aztable/shared_policy_shared_key_credential.go @@ -17,6 +17,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/internal/log" ) // NewSharedKeyCredential creates an immutable SharedKeyCredential containing the @@ -69,7 +70,7 @@ func (c *SharedKeyCredential) buildStringToSign(req *http.Request) (string, erro } stringToSign := strings.Join([]string{ - headers.Get(azcore.HeaderXmsDate), + headers.Get(headerXmsDate), canonicalizedResource, }, "\n") return stringToSign, nil @@ -133,29 +134,42 @@ func (c *SharedKeyCredential) buildCanonicalizedResource(u *url.URL) (string, er return cr.String(), nil } -// AuthenticationPolicy implements the Credential interface on SharedKeyCredential. -func (c *SharedKeyCredential) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { - return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { - // Add a x-ms-date header if it doesn't already exist - if d := req.Request.Header.Get(azcore.HeaderXmsDate); d == "" { - req.Request.Header.Set(azcore.HeaderXmsDate, time.Now().UTC().Format(http.TimeFormat)) - } - stringToSign, err := c.buildStringToSign(req.Request) - if err != nil { - return nil, err - } - signature, err := c.ComputeHMACSHA256(stringToSign) - if err != nil { - return nil, err - } - authHeader := strings.Join([]string{"SharedKeyLite ", c.AccountName(), ":", signature}, "") - req.Request.Header.Set(azcore.HeaderAuthorization, authHeader) +type sharedKeyCredPolicy struct { + cred *SharedKeyCredential +} - response, err := req.Next() - if err != nil && response != nil && response.StatusCode == http.StatusForbidden { - // Service failed to authenticate request, log it - azcore.Log().Write(azcore.LogResponse, "===== HTTP Forbidden status, String-to-Sign:\n"+stringToSign+"\n===============================\n") - } - return response, err - }) +func newSharedKeyCredPolicy(cred *SharedKeyCredential, opts azcore.AuthenticationOptions) *sharedKeyCredPolicy { + s := &sharedKeyCredPolicy{ + cred: cred, + } + + return s +} + +func (s *sharedKeyCredPolicy) Do(req *azcore.Request) (*http.Response, error) { + if d := req.Request.Header.Get(headerXmsDate); d == "" { + req.Request.Header.Set(headerXmsDate, time.Now().UTC().Format(http.TimeFormat)) + } + stringToSign, err := s.cred.buildStringToSign(req.Request) + if err != nil { + return nil, err + } + signature, err := s.cred.ComputeHMACSHA256(stringToSign) + if err != nil { + return nil, err + } + authHeader := strings.Join([]string{"SharedKeyLite ", s.cred.AccountName(), ":", signature}, "") + req.Request.Header.Set(headerAuthorization, authHeader) + + response, err := req.Next() + if err != nil && response != nil && response.StatusCode == http.StatusForbidden { + // Service failed to authenticate request, log it + log.Write(log.Response, "===== HTTP Forbidden status, String-to-Sign:\n"+stringToSign+"\n===============================\n") + } + return response, err +} + +// NewAuthenticationPolicy implements the Credential interface on SharedKeyCredential. +func (c *SharedKeyCredential) NewAuthenticationPolicy(options azcore.AuthenticationOptions) azcore.Policy { + return newSharedKeyCredPolicy(c, options) } diff --git a/sdk/tables/aztable/table_access_policy_test.go b/sdk/tables/aztable/table_access_policy_test.go index 60015bdf6aaa..68e099a43659 100644 --- a/sdk/tables/aztable/table_access_policy_test.go +++ b/sdk/tables/aztable/table_access_policy_test.go @@ -124,7 +124,7 @@ func TestSetTooManyAccessPolicies(t *testing.T) { _, err := client.SetAccessPolicy(ctx, ¶m) require.NotNil(t, err, "Set access policy succeeded but should have failed") - require.Contains(t, err.Error(), tooManyAccessPoliciesError.Error()) + require.Contains(t, err.Error(), errTooManyAccessPoliciesError.Error()) } func TestSetNullAccessPolicy(t *testing.T) { diff --git a/sdk/tables/aztable/table_batch_test.go b/sdk/tables/aztable/table_batch_test.go index 7a7fbde8a65e..526543bb052e 100644 --- a/sdk/tables/aztable/table_batch_test.go +++ b/sdk/tables/aztable/table_batch_test.go @@ -30,7 +30,11 @@ func TestBatchAdd(t *testing.T) { batch[i] = TableTransactionAction{ActionType: Add, Entity: marshalled} } - resp, err := client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + u1, err := uuid.New() + require.NoError(t, err) + u2, err := uuid.New() + require.NoError(t, err) + resp, err := client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NoError(t, err) for i := 0; i < len(*resp.TransactionResponses); i++ { r := (*resp.TransactionResponses)[i] @@ -69,7 +73,11 @@ func TestBatchMixed(t *testing.T) { } } - resp, err := client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + u1, err := uuid.New() + require.NoError(t, err) + u2, err := uuid.New() + require.NoError(t, err) + resp, err := client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NoError(t, err) for i := 0; i < len(*resp.TransactionResponses); i++ { r := (*resp.TransactionResponses)[i] @@ -127,7 +135,11 @@ func TestBatchMixed(t *testing.T) { batch[3] = TableTransactionAction{ActionType: Add, Entity: marshalled4thEntity} batch[4] = TableTransactionAction{ActionType: Add, Entity: marshalled5thEntity} - resp, err = client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + u1, err = uuid.New() + require.NoError(t, err) + u2, err = uuid.New() + require.NoError(t, err) + resp, err = client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NoError(t, err) for i := 0; i < len(*resp.TransactionResponses); i++ { @@ -164,15 +176,20 @@ func TestBatchError(t *testing.T) { // Create the batch. batch := make([]TableTransactionAction, 0, 3) + u1, err := uuid.New() + require.NoError(t, err) + u2, err := uuid.New() + require.NoError(t, err) // Sending an empty batch throws. - _, err := client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + _, err = client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NotNil(t, err) require.Equal(t, error_empty_transaction, err.Error()) // Add the last entity to the table prior to adding it as part of the batch to cause a batch failure. marshalledFinalEntity, err := json.Marshal((*entitiesToCreate)[2]) require.NoError(t, err) - client.AddEntity(ctx, marshalledFinalEntity) + _, err = client.AddEntity(ctx, marshalledFinalEntity) + require.NoError(t, err) // Add the entities to the batch for i := 0; i < cap(batch); i++ { @@ -181,7 +198,11 @@ func TestBatchError(t *testing.T) { batch = append(batch, TableTransactionAction{ActionType: Add, Entity: marshalledEntity}) } - resp, err := client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + u1, err = uuid.New() + require.NoError(t, err) + u2, err = uuid.New() + require.NoError(t, err) + resp, err := client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NotNil(t, err) transactionError, ok := err.(*TableTransactionError) require.Truef(t, ok, "err should be of type TableTransactionError") @@ -241,7 +262,11 @@ func TestBatchComplex(t *testing.T) { Entity: marshalled5, } - resp, err := client.submitTransactionInternal(ctx, &batch, uuid.New(), uuid.New(), nil) + u1, err := uuid.New() + require.NoError(t, err) + u2, err := uuid.New() + require.NoError(t, err) + resp, err := client.submitTransactionInternal(ctx, &batch, u1, u2, nil) require.NoError(t, err) for i := 0; i < len(*resp.TransactionResponses); i++ { r := (*resp.TransactionResponses)[i] @@ -273,7 +298,11 @@ func TestBatchComplex(t *testing.T) { Entity: marshalled3, } - resp, err = client.submitTransactionInternal(ctx, &batch2, uuid.New(), uuid.New(), nil) + u1, err = uuid.New() + require.NoError(t, err) + u2, err = uuid.New() + require.NoError(t, err) + resp, err = client.submitTransactionInternal(ctx, &batch2, u1, u2, nil) require.NoError(t, err) for i := 0; i < len(*resp.TransactionResponses); i++ { r := (*resp.TransactionResponses)[i] diff --git a/sdk/tables/aztable/table_client.go b/sdk/tables/aztable/table_client.go index 144e4ab1ea5e..4d7e86c94e14 100644 --- a/sdk/tables/aztable/table_client.go +++ b/sdk/tables/aztable/table_client.go @@ -129,10 +129,10 @@ func (t *TableClient) UpdateEntity(ctx context.Context, entity []byte, etag *str return entity, err } - pk, _ := mapEntity[partitionKey] + pk := mapEntity[partitionKey] partKey := pk.(string) - rk, _ := mapEntity[rowKey] + rk := mapEntity[rowKey] rowkey := rk.(string) switch updateMode { @@ -155,10 +155,10 @@ func (t *TableClient) InsertEntity(ctx context.Context, entity []byte, updateMod return entity, err } - pk, _ := mapEntity[partitionKey] + pk := mapEntity[partitionKey] partKey := pk.(string) - rk, _ := mapEntity[rowKey] + rk := mapEntity[rowKey] rowkey := rk.(string) switch updateMode { @@ -179,7 +179,7 @@ func (t *TableClient) GetAccessPolicy(ctx context.Context) (SignedIdentifierArra func (t *TableClient) SetAccessPolicy(ctx context.Context, options *TableSetAccessPolicyOptions) (TableSetAccessPolicyResponse, error) { response, err := t.client.SetAccessPolicy(ctx, t.Name, options) if len(options.TableACL) > 5 { - err = tooManyAccessPoliciesError + err = errTooManyAccessPoliciesError } return response, err } diff --git a/sdk/tables/aztable/table_client_test.go b/sdk/tables/aztable/table_client_test.go index 1de071b483a3..62fcd7183cb4 100644 --- a/sdk/tables/aztable/table_client_test.go +++ b/sdk/tables/aztable/table_client_test.go @@ -4,16 +4,11 @@ package aztable import ( - "bytes" "context" "encoding/json" - "errors" "fmt" - "io/ioutil" - "net/http" "testing" - "github.com/Azure/azure-sdk-for-go/sdk/internal/runtime" "github.com/stretchr/testify/require" ) @@ -28,10 +23,6 @@ func TestServiceErrors(t *testing.T) { // Create a duplicate table to produce an error _, err := client.Create(ctx) require.Error(t, err) - - var svcErr *runtime.ResponseError - errors.As(err, &svcErr) - require.Equal(t, svcErr.RawResponse().StatusCode, http.StatusConflict) }) } } @@ -77,9 +68,7 @@ func TestAddComplexEntity(t *testing.T) { marshalledEntity, err := json.Marshal(entity) require.NoError(t, err) _, err = client.AddEntity(ctx, marshalledEntity) - var svcErr *runtime.ResponseError - errors.As(err, &svcErr) - require.Nilf(t, err, getStringFromBody(svcErr)) + require.NoError(t, err) }) } } @@ -187,6 +176,7 @@ func TestInsertEntity(t *testing.T) { mapEntity["MergeProperty"] = "foo" reMarshalled, err := json.Marshal(mapEntity) + require.NoError(err) // 4. Replace Entity with "bool"-less entity _, err = client.InsertEntity(ctx, reMarshalled, (ReplaceEntity)) @@ -201,6 +191,7 @@ func TestInsertEntity(t *testing.T) { postMerge := qResp.TableEntityQueryResponse.Value[0] var unmarshalledPostMerge map[string]interface{} err = json.Unmarshal(postMerge, &unmarshalledPostMerge) + require.NoError(err) // 6. Make assertions require.Less(len(unmarshalledPostMerge), len(unMarshalledPreMerge)) @@ -328,25 +319,7 @@ func TestInvalidEntity(t *testing.T) { _, err = client.AddEntity(ctx, badEntityMarshalled) require.NotNil(err) - require.Contains(err.Error(), partitionKeyRowKeyError.Error()) + require.Contains(err.Error(), errPartitionKeyRowKeyError.Error()) }) } } - -func getStringFromBody(e *runtime.ResponseError) string { - if e == nil { - return "Error is nil" - } - r := e.RawResponse() - body := bytes.Buffer{} - b := r.Body - b.Close() - if b != nil { - _, err := body.ReadFrom(b) - if err != nil { - return "" - } - _ = ioutil.NopCloser(&body) - } - return body.String() -} diff --git a/sdk/tables/aztable/table_pagers.go b/sdk/tables/aztable/table_pagers.go index fb1aa9dffdbc..2aa6875205db 100644 --- a/sdk/tables/aztable/table_pagers.go +++ b/sdk/tables/aztable/table_pagers.go @@ -5,8 +5,6 @@ package aztable import ( "context" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) // TableEntityListResponsePager is a Pager for Table entity query results. @@ -25,10 +23,14 @@ import ( // } // err := pager.Err() type TableEntityListResponsePager interface { - azcore.Pager + // azcore.Pager // PageResponse returns the current TableQueryResponseResponse. PageResponse() TableEntityListByteResponseResponse + // NextPage returns true if there is another page of data available, false if not + NextPage(context.Context) bool + // Err returns an error if there was an error on the last request + Err() error } type tableEntityQueryResponsePager struct { @@ -93,10 +95,14 @@ func (p *tableEntityQueryResponsePager) Err() error { // } // err := pager.Err() type TableListResponsePager interface { - azcore.Pager + // azcore.Pager // PageResponse returns the current TableQueryResponseResponse. PageResponse() TableListResponseResponse + // NextPage returns true if there is another page of data available, false if not + NextPage(context.Context) bool + // Err returns an error if there was an error on the last request + Err() error } type tableQueryResponsePager struct { diff --git a/sdk/tables/aztable/table_pagers_test.go b/sdk/tables/aztable/table_pagers_test.go deleted file mode 100644 index ef4f540e031b..000000000000 --- a/sdk/tables/aztable/table_pagers_test.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package aztable - -import ( - "io" - "io/ioutil" - "math" - "strconv" - "strings" -) - -func closerFromString(content string) io.ReadCloser { - return ioutil.NopCloser(strings.NewReader(content)) -} - -var odataHintProps = map[string]string{ - "SomeBinaryProperty": edmBinary, - "SomeDateProperty": edmDateTime, - "SomeDoubleProperty0": edmDouble, - "SomeDoubleProperty1": edmDouble, - "SomeGuidProperty": edmGuid, - "SomeInt64Property": edmInt64} - -var complexPayload = "{\"odata.etag\": \"W/\\\"datetime'2021-04-05T05%3A02%3A40.7371784Z'\\\"\"," + - "\"PartitionKey\": \"somePartition\"," + - "\"RowKey\": \"01\"," + - "\"Timestamp\": \"2021-03-23T18:29:15.9686039Z\"," + - "\"SomeBinaryProperty@odata.type\": \"Edm.Binary\"," + - "\"SomeBinaryProperty\": \"AQIDBAU=\"," + - "\"SomeDateProperty@odata.type\": \"Edm.DateTime\"," + - "\"SomeDateProperty\": \"2020-01-01T01:02:00Z\"," + - "\"SomeDoubleProperty0\": 1.0," + - "\"SomeDoubleProperty1\": 1.5," + - "\"SomeGuidProperty@odata.type\": \"Edm.Guid\"," + - "\"SomeGuidProperty\": \"0d391d16-97f1-4b9a-be68-4cc871f90001\"," + - "\"SomeInt64Property@odata.type\": \"Edm.Int64\"," + - "\"SomeInt64Property\": \"" + strconv.FormatInt(math.MaxInt64, 10) + "\"," + - "\"SomeIntProperty\": 42," + - "\"SomeStringProperty\": \"This is table entity number 01\"," + - "\"SomePtrStringProperty\": \"some pointer to string\" }" diff --git a/sdk/tables/aztable/table_service_client.go b/sdk/tables/aztable/table_service_client.go index 7f25d84229cb..878b3fc142e0 100644 --- a/sdk/tables/aztable/table_service_client.go +++ b/sdk/tables/aztable/table_service_client.go @@ -32,7 +32,7 @@ func NewTableServiceClient(serviceURL string, cred azcore.Credential, options *T if isCosmosEndpoint(serviceURL) { conOptions.PerCallPolicies = []azcore.Policy{cosmosPatchTransformPolicy{}} } - conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: options.Scopes}})) + conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, cred.NewAuthenticationPolicy(azcore.AuthenticationOptions{TokenRequest: azcore.TokenRequestOptions{Scopes: options.Scopes}})) conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, options.PerCallOptions...) con := newConnection(serviceURL, conOptions) return &TableServiceClient{client: &tableClient{con}, service: &serviceClient{con}, cred: cred}, nil diff --git a/sdk/tables/aztable/table_service_client_test.go b/sdk/tables/aztable/table_service_client_test.go index b6d0c2d435ce..444de6935415 100644 --- a/sdk/tables/aztable/table_service_client_test.go +++ b/sdk/tables/aztable/table_service_client_test.go @@ -5,14 +5,11 @@ package aztable import ( "context" - "errors" "fmt" - "net/http" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" - "github.com/Azure/azure-sdk-for-go/sdk/internal/runtime" "github.com/Azure/azure-sdk-for-go/sdk/to" "github.com/stretchr/testify/require" ) @@ -29,10 +26,6 @@ func TestServiceErrorsServiceClient(t *testing.T) { _, err = service.CreateTable(context.Background(), "tableName") require.Error(t, err) - var svcErr *runtime.ResponseError - errors.As(err, &svcErr) - require.Equal(t, svcErr.RawResponse().StatusCode, http.StatusConflict) - _, err = service.DeleteTable(context.Background(), "tableName", nil) require.NoError(t, err) }) @@ -73,7 +66,7 @@ func TestQueryTable(t *testing.T) { prefix1 := "zzza" prefix2 := "zzzb" - defer clearAllTables(service) + defer clearAllTables(service) //nolint //create 10 tables with our exected prefix and 1 with a different prefix for i := 0; i < tableCount; i++ { if i < (tableCount - 1) { diff --git a/sdk/tables/aztable/table_transactional_batch.go b/sdk/tables/aztable/table_transactional_batch.go index d4e7b6ff5d11..cb2227e2fd9d 100644 --- a/sdk/tables/aztable/table_transactional_batch.go +++ b/sdk/tables/aztable/table_transactional_batch.go @@ -83,7 +83,7 @@ type TableTransactionResponse struct { RequestID *string // The response for a single table. - TransactionResponses *[]azcore.Response + TransactionResponses *[]http.Response // Version contains the information returned from the x-ms-version header response. Version *string @@ -97,23 +97,31 @@ type TableSubmitTransactionOptions struct { } // SubmitTransaction submits the table transactional batch according to the slice of TableTransactionActions provided. -func (t *TableClient) SubmitTransaction(ctx context.Context, transactionActions []TableTransactionAction, tableSubmitTransactionOptions *TableSubmitTransactionOptions) (TableTransactionResponse, error) { - return t.submitTransactionInternal(ctx, &transactionActions, uuid.New(), uuid.New(), tableSubmitTransactionOptions) +func (t *TableClient) SubmitTransaction(ctx context.Context, transactionActions []TableTransactionAction, tableSubmitTransactionOptions *TableSubmitTransactionOptions) (*TableTransactionResponse, error) { + u1, err := uuid.New() + if err != nil { + return nil, err + } + u2, err := uuid.New() + if err != nil { + return nil, err + } + return t.submitTransactionInternal(ctx, &transactionActions, u1, u2, tableSubmitTransactionOptions) } // submitTransactionInternal is the internal implementation for SubmitTransaction. It allows for explicit configuration of the batch and changeset UUID values for testing. -func (t *TableClient) submitTransactionInternal(ctx context.Context, transactionActions *[]TableTransactionAction, batchUuid uuid.UUID, changesetUuid uuid.UUID, tableSubmitTransactionOptions *TableSubmitTransactionOptions) (TableTransactionResponse, error) { +func (t *TableClient) submitTransactionInternal(ctx context.Context, transactionActions *[]TableTransactionAction, batchUuid uuid.UUID, changesetUuid uuid.UUID, tableSubmitTransactionOptions *TableSubmitTransactionOptions) (*TableTransactionResponse, error) { if len(*transactionActions) == 0 { - return TableTransactionResponse{}, errors.New(error_empty_transaction) + return &TableTransactionResponse{}, errors.New(error_empty_transaction) } changesetBoundary := fmt.Sprintf("changeset_%s", changesetUuid.String()) changeSetBody, err := t.generateChangesetBody(changesetBoundary, transactionActions) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(t.client.con.Endpoint(), "$batch")) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } req.Header.Set("x-ms-version", "2019-02-02") if tableSubmitTransactionOptions != nil && tableSubmitTransactionOptions.RequestID != nil { @@ -127,28 +135,28 @@ func (t *TableClient) submitTransactionInternal(ctx context.Context, transaction writer := multipart.NewWriter(body) err = writer.SetBoundary(boundary) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } h := make(textproto.MIMEHeader) h.Set(headerContentType, fmt.Sprintf("multipart/mixed; boundary=%s", changesetBoundary)) batchWriter, err := writer.CreatePart(h) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } _, err = batchWriter.Write(changeSetBody.Bytes()) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } writer.Close() err = req.SetBody(azcore.NopCloser(bytes.NewReader(body.Bytes())), fmt.Sprintf("multipart/mixed; boundary=%s", boundary)) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } resp, err := t.client.con.Pipeline().Do(req) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } transactionResponse, err := buildTransactionResponse(req, resp, len(*transactionActions)) @@ -156,15 +164,15 @@ func (t *TableClient) submitTransactionInternal(ctx context.Context, transaction return transactionResponse, err } - if !resp.HasStatusCode(http.StatusAccepted, http.StatusNoContent) { - return TableTransactionResponse{}, azcore.NewResponseError(err, resp.Response) + if !azcore.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { + return &TableTransactionResponse{}, azcore.NewResponseError(err, resp) } return transactionResponse, nil } -func buildTransactionResponse(req *azcore.Request, resp *azcore.Response, itemCount int) (TableTransactionResponse, error) { - innerResponses := make([]azcore.Response, itemCount) - result := TableTransactionResponse{RawResponse: resp.Response, TransactionResponses: &innerResponses} +func buildTransactionResponse(req *azcore.Request, resp *http.Response, itemCount int) (*TableTransactionResponse, error) { + innerResponses := make([]http.Response, itemCount) + result := TableTransactionResponse{RawResponse: resp, TransactionResponses: &innerResponses} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -178,7 +186,7 @@ func buildTransactionResponse(req *azcore.Request, resp *azcore.Response, itemCo if val := resp.Header.Get("Date"); val != "" { date, err := time.Parse(time.RFC1123, val) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } result.Date = &date } @@ -192,19 +200,19 @@ func buildTransactionResponse(req *azcore.Request, resp *azcore.Response, itemCo bytesBody, err := ioutil.ReadAll(resp.Body) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } reader := bytes.NewReader(bytesBody) if bytes.IndexByte(bytesBody, '{') == 0 { // This is a failure and the body is json - return TableTransactionResponse{}, newTableTransactionError(bytesBody) + return &TableTransactionResponse{}, newTableTransactionError(bytesBody) } outerBoundary := getBoundaryName(bytesBody) mpReader := multipart.NewReader(reader, outerBoundary) outerPart, err := mpReader.NextPart() if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } innerBytes, err := ioutil.ReadAll(outerPart) //nolint @@ -220,22 +228,22 @@ func buildTransactionResponse(req *azcore.Request, resp *azcore.Response, itemCo } r, err := http.ReadResponse(bufio.NewReader(bytes.NewBuffer(part)), req.Request) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } if r.StatusCode >= 400 { errorBody, err := ioutil.ReadAll(r.Body) if err != nil { - return TableTransactionResponse{}, err + return &TableTransactionResponse{}, err } else { - innerResponses = []azcore.Response{{Response: r}} - return result, newTableTransactionError(errorBody) + innerResponses = []http.Response{*r} + return &result, newTableTransactionError(errorBody) } } - innerResponses[i] = azcore.Response{Response: r} + innerResponses[i] = *r i++ } - return result, nil + return &result, nil } func getBoundaryName(bytesBody []byte) string { diff --git a/sdk/tables/aztable/zc_client_options.go b/sdk/tables/aztable/zc_client_options.go index ef2678419057..7109060d7ac1 100644 --- a/sdk/tables/aztable/zc_client_options.go +++ b/sdk/tables/aztable/zc_client_options.go @@ -9,7 +9,7 @@ import ( type TableClientOptions struct { // HTTPClient sets the transport for making HTTP requests. - HTTPClient azcore.Transport + HTTPClient azcore.Transporter // Retry configures the built-in retry policy behavior. Retry azcore.RetryOptions // Telemetry configures the built-in telemetry policy behavior. diff --git a/sdk/tables/aztable/zc_table_constants.go b/sdk/tables/aztable/zc_table_constants.go index 476cd2ba81e0..34c70e703d9c 100644 --- a/sdk/tables/aztable/zc_table_constants.go +++ b/sdk/tables/aztable/zc_table_constants.go @@ -6,23 +6,14 @@ package aztable import "errors" const ( - timestamp = "Timestamp" - partitionKey = "PartitionKey" - rowKey = "RowKey" - etagOdata = "odata.etag" - etag = "ETag" - odataMetadata = "odata.metadata" - OdataType = "@odata.type" - edmBinary = "Edm.Binary" - edmBoolean = "Emd.Boolean" - edmDateTime = "Edm.DateTime" - edmDouble = "Edm.Double" - edmGuid = "Edm.Guid" - edmInt32 = "Edm.Int32" - edmInt64 = "Edm.Int64" - edmString = "Edm.String" - ISO8601 = "2006-01-02T15:04:05.9999999Z" + timestamp = "Timestamp" + partitionKey = "PartitionKey" + rowKey = "RowKey" + etagOdata = "odata.etag" + etag = "ETag" + OdataType = "@odata.type" + ISO8601 = "2006-01-02T15:04:05.9999999Z" ) -var partitionKeyRowKeyError = errors.New("Entity must have a PartitionKey and RowKey") -var tooManyAccessPoliciesError = errors.New("You cannot set more than five (5) access policies at a time.") +var errPartitionKeyRowKeyError = errors.New("entity must have a PartitionKey and RowKey") +var errTooManyAccessPoliciesError = errors.New("you cannot set more than five (5) access policies at a time.") diff --git a/sdk/tables/aztable/zt_table_recorded_tests.go b/sdk/tables/aztable/zt_table_recorded_tests.go index c6ea9f6a4c10..da90be062fda 100644 --- a/sdk/tables/aztable/zt_table_recorded_tests.go +++ b/sdk/tables/aztable/zt_table_recorded_tests.go @@ -10,26 +10,12 @@ import ( "testing" "time" - "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/stretchr/testify/require" ) -type testContext struct { - recording *recording.Recording - client *TableServiceClient - context *recording.TestContext -} - const ( - storageAccountNameEnvVar = "TABLES_STORAGE_ACCOUNT_NAME" - cosmosAccountNameEnnVar = "TABLES_COSMOS_ACCOUNT_NAME" - storageEndpointSuffixEnvVar = "STORAGE_ENDPOINT_SUFFIX" - cosmosEndpointSuffixEnvVar = "COSMOS_TABLES_ENDPOINT_SUFFIX" - storageAccountKeyEnvVar = "TABLES_PRIMARY_STORAGE_ACCOUNT_KEY" - cosmosAccountKeyEnvVar = "TABLES_PRIMARY_COSMOS_ACCOUNT_KEY" - tableNamePrefix = "gotable" - DefaultStorageSuffix = "core.windows.net" - DefaultCosmosSuffix = "cosmos.azure.com" + DefaultStorageSuffix = "core.windows.net" + DefaultCosmosSuffix = "cosmos.azure.com" ) type EndpointType string @@ -68,37 +54,6 @@ func insertNEntities(pk string, n int, client *TableClient) error { return nil } -// cleans up the specified tables. If tables is nil, all tables will be deleted -func cleanupTables(context *testContext, tables *[]string) { - c := context.client - if tables == nil { - pager := c.ListTables(nil) - for pager.NextPage(ctx) { - for _, t := range pager.PageResponse().TableListResponse.Value { - _, err := c.DeleteTable(ctx, *t.TableName, nil) - if err != nil { - fmt.Printf("Error cleaning up tables. %v\n", err.Error()) - } - } - } - } else { - for _, t := range *tables { - _, err := c.DeleteTable(ctx, t, nil) - if err != nil { - fmt.Printf("There was an error cleaning up tests. %v\n", err.Error()) - } - } - } -} - -func getTableName(context *testContext, prefix ...string) (string, error) { - if len(prefix) == 0 { - return context.recording.GenerateAlphaNumericID(tableNamePrefix, 20, true) - } else { - return context.recording.GenerateAlphaNumericID(prefix[0], 20, true) - } -} - type basicTestEntity struct { Entity Integer int32 diff --git a/sdk/tables/aztable/zz_generated_connection.go b/sdk/tables/aztable/zz_generated_connection.go index 6aa8ad00d8b3..ca47a829f076 100644 --- a/sdk/tables/aztable/zz_generated_connection.go +++ b/sdk/tables/aztable/zz_generated_connection.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -17,7 +18,7 @@ import ( // All zero-value fields will be initialized with their default values. type connectionOptions struct { // HTTPClient sets the transport for making HTTP requests. - HTTPClient azcore.Transport + HTTPClient azcore.Transporter // Retry configures the built-in retry policy behavior. Retry azcore.RetryOptions // Telemetry configures the built-in telemetry policy behavior. diff --git a/sdk/tables/aztable/zz_generated_constants.go b/sdk/tables/aztable/zz_generated_constants.go index 3e7b261c70c7..a1ff9041bd71 100644 --- a/sdk/tables/aztable/zz_generated_constants.go +++ b/sdk/tables/aztable/zz_generated_constants.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_models.go b/sdk/tables/aztable/zz_generated_models.go index 7094e996e262..2a31433b5e0c 100644 --- a/sdk/tables/aztable/zz_generated_models.go +++ b/sdk/tables/aztable/zz_generated_models.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_response_types.go b/sdk/tables/aztable/zz_generated_response_types.go index e962b27b4774..70aa81764405 100644 --- a/sdk/tables/aztable/zz_generated_response_types.go +++ b/sdk/tables/aztable/zz_generated_response_types.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_service_client.go b/sdk/tables/aztable/zz_generated_service_client.go index afa44c086aee..cfa06d54479e 100644 --- a/sdk/tables/aztable/zz_generated_service_client.go +++ b/sdk/tables/aztable/zz_generated_service_client.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -10,10 +11,11 @@ package aztable import ( "context" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "net/http" "strconv" "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) type serviceClient struct { @@ -31,7 +33,7 @@ func (client *serviceClient) GetProperties(ctx context.Context, options *Service if err != nil { return TableServicePropertiesResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return TableServicePropertiesResponse{}, client.getPropertiesHandleError(resp) } return client.getPropertiesHandleResponse(resp) @@ -60,12 +62,12 @@ func (client *serviceClient) getPropertiesCreateRequest(ctx context.Context, opt } // getPropertiesHandleResponse handles the GetProperties response. -func (client *serviceClient) getPropertiesHandleResponse(resp *azcore.Response) (TableServicePropertiesResponse, error) { +func (client *serviceClient) getPropertiesHandleResponse(resp *http.Response) (TableServicePropertiesResponse, error) { var val *TableServiceProperties - if err := resp.UnmarshalAsXML(&val); err != nil { + if err := azcore.UnmarshalAsXML(resp, &val); err != nil { return TableServicePropertiesResponse{}, err } - result := TableServicePropertiesResponse{RawResponse: resp.Response, StorageServiceProperties: val} + result := TableServicePropertiesResponse{RawResponse: resp, StorageServiceProperties: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -79,16 +81,16 @@ func (client *serviceClient) getPropertiesHandleResponse(resp *azcore.Response) } // getPropertiesHandleError handles the GetProperties error response. -func (client *serviceClient) getPropertiesHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *serviceClient) getPropertiesHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // GetStatistics - Retrieves statistics related to replication for the Table service. It is only available on the secondary location endpoint when read-access @@ -103,7 +105,7 @@ func (client *serviceClient) GetStatistics(ctx context.Context, options *Service if err != nil { return TableServiceStatsResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return TableServiceStatsResponse{}, client.getStatisticsHandleError(resp) } return client.getStatisticsHandleResponse(resp) @@ -132,12 +134,12 @@ func (client *serviceClient) getStatisticsCreateRequest(ctx context.Context, opt } // getStatisticsHandleResponse handles the GetStatistics response. -func (client *serviceClient) getStatisticsHandleResponse(resp *azcore.Response) (TableServiceStatsResponse, error) { +func (client *serviceClient) getStatisticsHandleResponse(resp *http.Response) (TableServiceStatsResponse, error) { var val *TableServiceStats - if err := resp.UnmarshalAsXML(&val); err != nil { + if err := azcore.UnmarshalAsXML(resp, &val); err != nil { return TableServiceStatsResponse{}, err } - result := TableServiceStatsResponse{RawResponse: resp.Response, StorageServiceStats: val} + result := TableServiceStatsResponse{RawResponse: resp, StorageServiceStats: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -158,16 +160,16 @@ func (client *serviceClient) getStatisticsHandleResponse(resp *azcore.Response) } // getStatisticsHandleError handles the GetStatistics error response. -func (client *serviceClient) getStatisticsHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *serviceClient) getStatisticsHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // SetProperties - Sets properties for an account's Table service endpoint, including properties for Analytics and CORS (Cross-Origin Resource Sharing) @@ -182,7 +184,7 @@ func (client *serviceClient) SetProperties(ctx context.Context, tableServiceProp if err != nil { return ServiceSetPropertiesResponse{}, err } - if !resp.HasStatusCode(http.StatusAccepted) { + if !azcore.HasStatusCode(resp, http.StatusAccepted) { return ServiceSetPropertiesResponse{}, client.setPropertiesHandleError(resp) } return client.setPropertiesHandleResponse(resp) @@ -211,8 +213,8 @@ func (client *serviceClient) setPropertiesCreateRequest(ctx context.Context, tab } // setPropertiesHandleResponse handles the SetProperties response. -func (client *serviceClient) setPropertiesHandleResponse(resp *azcore.Response) (ServiceSetPropertiesResponse, error) { - result := ServiceSetPropertiesResponse{RawResponse: resp.Response} +func (client *serviceClient) setPropertiesHandleResponse(resp *http.Response) (ServiceSetPropertiesResponse, error) { + result := ServiceSetPropertiesResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -226,14 +228,14 @@ func (client *serviceClient) setPropertiesHandleResponse(resp *azcore.Response) } // setPropertiesHandleError handles the SetProperties error response. -func (client *serviceClient) setPropertiesHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *serviceClient) setPropertiesHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } diff --git a/sdk/tables/aztable/zz_generated_table_client.go b/sdk/tables/aztable/zz_generated_table_client.go index 13645c322257..e942cb6f2c04 100644 --- a/sdk/tables/aztable/zz_generated_table_client.go +++ b/sdk/tables/aztable/zz_generated_table_client.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. @@ -12,12 +13,13 @@ import ( "encoding/xml" "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "net/http" "net/url" "strconv" "strings" "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) type tableClient struct { @@ -36,7 +38,7 @@ func (client *tableClient) Create(ctx context.Context, tableProperties TableProp if err != nil { return nil, err } - if !resp.HasStatusCode(http.StatusCreated, http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusCreated, http.StatusNoContent) { return nil, client.createHandleError(resp) } return client.createHandleResponse(resp) @@ -68,14 +70,14 @@ func (client *tableClient) createCreateRequest(ctx context.Context, tablePropert } // createHandleResponse handles the Create response. -func (client *tableClient) createHandleResponse(resp *azcore.Response) (interface{}, error) { +func (client *tableClient) createHandleResponse(resp *http.Response) (interface{}, error) { switch resp.StatusCode { case http.StatusCreated: var val *TableResponse - if err := resp.UnmarshalAsJSON(&val); err != nil { + if err := azcore.UnmarshalAsJSON(resp, &val); err != nil { return nil, err } - result := TableResponseResponse{RawResponse: resp.Response, TableResponse: val} + result := TableResponseResponse{RawResponse: resp, TableResponse: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -97,7 +99,7 @@ func (client *tableClient) createHandleResponse(resp *azcore.Response) (interfac } return result, nil case http.StatusNoContent: - result := TableCreateResponse{RawResponse: resp.Response} + result := TableCreateResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -124,16 +126,16 @@ func (client *tableClient) createHandleResponse(resp *azcore.Response) (interfac } // createHandleError handles the Create error response. -func (client *tableClient) createHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) createHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // Delete - Operation permanently deletes the specified table. @@ -147,7 +149,7 @@ func (client *tableClient) Delete(ctx context.Context, table string, options *Ta if err != nil { return TableDeleteResponse{}, err } - if !resp.HasStatusCode(http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusNoContent) { return TableDeleteResponse{}, client.deleteHandleError(resp) } return client.deleteHandleResponse(resp) @@ -174,8 +176,8 @@ func (client *tableClient) deleteCreateRequest(ctx context.Context, table string } // deleteHandleResponse handles the Delete response. -func (client *tableClient) deleteHandleResponse(resp *azcore.Response) (TableDeleteResponse, error) { - result := TableDeleteResponse{RawResponse: resp.Response} +func (client *tableClient) deleteHandleResponse(resp *http.Response) (TableDeleteResponse, error) { + result := TableDeleteResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -196,16 +198,16 @@ func (client *tableClient) deleteHandleResponse(resp *azcore.Response) (TableDel } // deleteHandleError handles the Delete error response. -func (client *tableClient) deleteHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) deleteHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // DeleteEntity - Deletes the specified entity in a table. @@ -219,7 +221,7 @@ func (client *tableClient) DeleteEntity(ctx context.Context, table string, parti if err != nil { return TableDeleteEntityResponse{}, err } - if !resp.HasStatusCode(http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusNoContent) { return TableDeleteEntityResponse{}, client.deleteEntityHandleError(resp) } return client.deleteEntityHandleResponse(resp) @@ -264,8 +266,8 @@ func (client *tableClient) deleteEntityCreateRequest(ctx context.Context, table } // deleteEntityHandleResponse handles the DeleteEntity response. -func (client *tableClient) deleteEntityHandleResponse(resp *azcore.Response) (TableDeleteEntityResponse, error) { - result := TableDeleteEntityResponse{RawResponse: resp.Response} +func (client *tableClient) deleteEntityHandleResponse(resp *http.Response) (TableDeleteEntityResponse, error) { + result := TableDeleteEntityResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -286,16 +288,16 @@ func (client *tableClient) deleteEntityHandleResponse(resp *azcore.Response) (Ta } // deleteEntityHandleError handles the DeleteEntity error response. -func (client *tableClient) deleteEntityHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) deleteEntityHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // GetAccessPolicy - Retrieves details about any stored access policies specified on the table that may be used with Shared Access Signatures. @@ -309,7 +311,7 @@ func (client *tableClient) GetAccessPolicy(ctx context.Context, table string, op if err != nil { return SignedIdentifierArrayResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return SignedIdentifierArrayResponse{}, client.getAccessPolicyHandleError(resp) } return client.getAccessPolicyHandleResponse(resp) @@ -342,9 +344,9 @@ func (client *tableClient) getAccessPolicyCreateRequest(ctx context.Context, tab } // getAccessPolicyHandleResponse handles the GetAccessPolicy response. -func (client *tableClient) getAccessPolicyHandleResponse(resp *azcore.Response) (SignedIdentifierArrayResponse, error) { - result := SignedIdentifierArrayResponse{RawResponse: resp.Response} - if err := resp.UnmarshalAsXML(&result); err != nil { +func (client *tableClient) getAccessPolicyHandleResponse(resp *http.Response) (SignedIdentifierArrayResponse, error) { + result := SignedIdentifierArrayResponse{RawResponse: resp} + if err := azcore.UnmarshalAsXML(resp, &result); err != nil { return SignedIdentifierArrayResponse{}, err } if val := resp.Header.Get("x-ms-client-request-id"); val != "" { @@ -367,16 +369,16 @@ func (client *tableClient) getAccessPolicyHandleResponse(resp *azcore.Response) } // getAccessPolicyHandleError handles the GetAccessPolicy error response. -func (client *tableClient) getAccessPolicyHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) getAccessPolicyHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // InsertEntity - Insert entity in a table. @@ -391,7 +393,7 @@ func (client *tableClient) InsertEntity(ctx context.Context, table string, table if err != nil { return nil, err } - if !resp.HasStatusCode(http.StatusCreated, http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusCreated, http.StatusNoContent) { return nil, client.insertEntityHandleError(resp) } return client.insertEntityHandleResponse(resp) @@ -433,14 +435,14 @@ func (client *tableClient) insertEntityCreateRequest(ctx context.Context, table } // insertEntityHandleResponse handles the InsertEntity response. -func (client *tableClient) insertEntityHandleResponse(resp *azcore.Response) (interface{}, error) { +func (client *tableClient) insertEntityHandleResponse(resp *http.Response) (interface{}, error) { switch resp.StatusCode { case http.StatusCreated: var val map[string]interface{} - if err := resp.UnmarshalAsJSON(&val); err != nil { + if err := azcore.UnmarshalAsJSON(resp, &val); err != nil { return nil, err } - result := MapOfInterfaceResponse{RawResponse: resp.Response, Value: val} + result := MapOfInterfaceResponse{RawResponse: resp, Value: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -474,7 +476,7 @@ func (client *tableClient) insertEntityHandleResponse(resp *azcore.Response) (in } return result, nil case http.StatusNoContent: - result := TableInsertEntityResponse{RawResponse: resp.Response} + result := TableInsertEntityResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -507,16 +509,16 @@ func (client *tableClient) insertEntityHandleResponse(resp *azcore.Response) (in } // insertEntityHandleError handles the InsertEntity error response. -func (client *tableClient) insertEntityHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) insertEntityHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // MergeEntity - Merge entity in a table. @@ -530,7 +532,7 @@ func (client *tableClient) MergeEntity(ctx context.Context, table string, partit if err != nil { return TableMergeEntityResponse{}, err } - if !resp.HasStatusCode(http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusNoContent) { return TableMergeEntityResponse{}, client.mergeEntityHandleError(resp) } return client.mergeEntityHandleResponse(resp) @@ -580,8 +582,8 @@ func (client *tableClient) mergeEntityCreateRequest(ctx context.Context, table s } // mergeEntityHandleResponse handles the MergeEntity response. -func (client *tableClient) mergeEntityHandleResponse(resp *azcore.Response) (TableMergeEntityResponse, error) { - result := TableMergeEntityResponse{RawResponse: resp.Response} +func (client *tableClient) mergeEntityHandleResponse(resp *http.Response) (TableMergeEntityResponse, error) { + result := TableMergeEntityResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -605,16 +607,16 @@ func (client *tableClient) mergeEntityHandleResponse(resp *azcore.Response) (Tab } // mergeEntityHandleError handles the MergeEntity error response. -func (client *tableClient) mergeEntityHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) mergeEntityHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // Query - Queries tables under the given account. @@ -628,7 +630,7 @@ func (client *tableClient) Query(ctx context.Context, tableQueryOptions *TableQu if err != nil { return TableQueryResponseResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return TableQueryResponseResponse{}, client.queryHandleError(resp) } return client.queryHandleResponse(resp) @@ -669,12 +671,12 @@ func (client *tableClient) queryCreateRequest(ctx context.Context, tableQueryOpt } // queryHandleResponse handles the Query response. -func (client *tableClient) queryHandleResponse(resp *azcore.Response) (TableQueryResponseResponse, error) { +func (client *tableClient) queryHandleResponse(resp *http.Response) (TableQueryResponseResponse, error) { var val *TableQueryResponse - if err := resp.UnmarshalAsJSON(&val); err != nil { + if err := azcore.UnmarshalAsJSON(resp, &val); err != nil { return TableQueryResponseResponse{}, err } - result := TableQueryResponseResponse{RawResponse: resp.Response, TableQueryResponse: val} + result := TableQueryResponseResponse{RawResponse: resp, TableQueryResponse: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -698,15 +700,15 @@ func (client *tableClient) queryHandleResponse(resp *azcore.Response) (TableQuer } // queryHandleError handles the Query error response. -func (client *tableClient) queryHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) queryHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } if len(body) == 0 { - return azcore.NewResponseError(errors.New(resp.Status), resp.Response) + return azcore.NewResponseError(errors.New(resp.Status), resp) } - return azcore.NewResponseError(errors.New(string(body)), resp.Response) + return azcore.NewResponseError(errors.New(string(body)), resp) } // QueryEntities - Queries entities in a table. @@ -720,7 +722,7 @@ func (client *tableClient) QueryEntities(ctx context.Context, table string, tabl if err != nil { return TableEntityQueryResponseResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return TableEntityQueryResponseResponse{}, client.queryEntitiesHandleError(resp) } return client.queryEntitiesHandleResponse(resp) @@ -771,12 +773,12 @@ func (client *tableClient) queryEntitiesCreateRequest(ctx context.Context, table } // queryEntitiesHandleResponse handles the QueryEntities response. -func (client *tableClient) queryEntitiesHandleResponse(resp *azcore.Response) (TableEntityQueryResponseResponse, error) { +func (client *tableClient) queryEntitiesHandleResponse(resp *http.Response) (TableEntityQueryResponseResponse, error) { var val *TableEntityQueryResponse - if err := resp.UnmarshalAsJSON(&val); err != nil { + if err := azcore.UnmarshalAsJSON(resp, &val); err != nil { return TableEntityQueryResponseResponse{}, err } - result := TableEntityQueryResponseResponse{RawResponse: resp.Response, TableEntityQueryResponse: val} + result := TableEntityQueryResponseResponse{RawResponse: resp, TableEntityQueryResponse: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -803,16 +805,16 @@ func (client *tableClient) queryEntitiesHandleResponse(resp *azcore.Response) (T } // queryEntitiesHandleError handles the QueryEntities error response. -func (client *tableClient) queryEntitiesHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) queryEntitiesHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // QueryEntityWithPartitionAndRowKey - Queries a single entity in a table. @@ -826,7 +828,7 @@ func (client *tableClient) QueryEntityWithPartitionAndRowKey(ctx context.Context if err != nil { return MapOfInterfaceResponse{}, err } - if !resp.HasStatusCode(http.StatusOK) { + if !azcore.HasStatusCode(resp, http.StatusOK) { return MapOfInterfaceResponse{}, client.queryEntityWithPartitionAndRowKeyHandleError(resp) } return client.queryEntityWithPartitionAndRowKeyHandleResponse(resp) @@ -876,12 +878,12 @@ func (client *tableClient) queryEntityWithPartitionAndRowKeyCreateRequest(ctx co } // queryEntityWithPartitionAndRowKeyHandleResponse handles the QueryEntityWithPartitionAndRowKey response. -func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp *azcore.Response) (MapOfInterfaceResponse, error) { +func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp *http.Response) (MapOfInterfaceResponse, error) { var val map[string]interface{} - if err := resp.UnmarshalAsJSON(&val); err != nil { + if err := azcore.UnmarshalAsJSON(resp, &val); err != nil { return MapOfInterfaceResponse{}, err } - result := MapOfInterfaceResponse{RawResponse: resp.Response, Value: val} + result := MapOfInterfaceResponse{RawResponse: resp, Value: val} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -917,16 +919,16 @@ func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp } // queryEntityWithPartitionAndRowKeyHandleError handles the QueryEntityWithPartitionAndRowKey error response. -func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // SetAccessPolicy - Sets stored access policies for the table that may be used with Shared Access Signatures. @@ -940,7 +942,7 @@ func (client *tableClient) SetAccessPolicy(ctx context.Context, table string, op if err != nil { return TableSetAccessPolicyResponse{}, err } - if !resp.HasStatusCode(http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusNoContent) { return TableSetAccessPolicyResponse{}, client.setAccessPolicyHandleError(resp) } return client.setAccessPolicyHandleResponse(resp) @@ -980,8 +982,8 @@ func (client *tableClient) setAccessPolicyCreateRequest(ctx context.Context, tab } // setAccessPolicyHandleResponse handles the SetAccessPolicy response. -func (client *tableClient) setAccessPolicyHandleResponse(resp *azcore.Response) (TableSetAccessPolicyResponse, error) { - result := TableSetAccessPolicyResponse{RawResponse: resp.Response} +func (client *tableClient) setAccessPolicyHandleResponse(resp *http.Response) (TableSetAccessPolicyResponse, error) { + result := TableSetAccessPolicyResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -1002,16 +1004,16 @@ func (client *tableClient) setAccessPolicyHandleResponse(resp *azcore.Response) } // setAccessPolicyHandleError handles the SetAccessPolicy error response. -func (client *tableClient) setAccessPolicyHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) setAccessPolicyHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } // UpdateEntity - Update entity in a table. @@ -1025,7 +1027,7 @@ func (client *tableClient) UpdateEntity(ctx context.Context, table string, parti if err != nil { return TableUpdateEntityResponse{}, err } - if !resp.HasStatusCode(http.StatusNoContent) { + if !azcore.HasStatusCode(resp, http.StatusNoContent) { return TableUpdateEntityResponse{}, client.updateEntityHandleError(resp) } return client.updateEntityHandleResponse(resp) @@ -1075,8 +1077,8 @@ func (client *tableClient) updateEntityCreateRequest(ctx context.Context, table } // updateEntityHandleResponse handles the UpdateEntity response. -func (client *tableClient) updateEntityHandleResponse(resp *azcore.Response) (TableUpdateEntityResponse, error) { - result := TableUpdateEntityResponse{RawResponse: resp.Response} +func (client *tableClient) updateEntityHandleResponse(resp *http.Response) (TableUpdateEntityResponse, error) { + result := TableUpdateEntityResponse{RawResponse: resp} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val } @@ -1100,14 +1102,14 @@ func (client *tableClient) updateEntityHandleResponse(resp *azcore.Response) (Ta } // updateEntityHandleError handles the UpdateEntity error response. -func (client *tableClient) updateEntityHandleError(resp *azcore.Response) error { - body, err := resp.Payload() +func (client *tableClient) updateEntityHandleError(resp *http.Response) error { + body, err := azcore.Payload(resp) if err != nil { - return azcore.NewResponseError(err, resp.Response) + return azcore.NewResponseError(err, resp) } errType := TableServiceError{raw: string(body)} - if err := resp.UnmarshalAsJSON(&errType); err != nil { - return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) + if err := azcore.UnmarshalAsJSON(resp, &errType); err != nil { + return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) } - return azcore.NewResponseError(&errType, resp.Response) + return azcore.NewResponseError(&errType, resp) } diff --git a/sdk/tables/aztable/zz_generated_time_rfc1123.go b/sdk/tables/aztable/zz_generated_time_rfc1123.go index e8cd4d9053de..f1ea29aa7efe 100644 --- a/sdk/tables/aztable/zz_generated_time_rfc1123.go +++ b/sdk/tables/aztable/zz_generated_time_rfc1123.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_time_rfc3339.go b/sdk/tables/aztable/zz_generated_time_rfc3339.go index dadfddb3cbd3..1388ade6d691 100644 --- a/sdk/tables/aztable/zz_generated_time_rfc3339.go +++ b/sdk/tables/aztable/zz_generated_time_rfc3339.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved.