From a5c229bd9d0d685cad6af8f93df42fe7001aab57 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Thu, 22 Jul 2021 14:49:32 -0700 Subject: [PATCH 1/5] add auxiliary tenants to options --- sdk/armcore/connection.go | 13 ++++++++++++- sdk/armcore/connection_test.go | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sdk/armcore/connection.go b/sdk/armcore/connection.go index edcdb447bffa..b673d1fc1761 100644 --- a/sdk/armcore/connection.go +++ b/sdk/armcore/connection.go @@ -25,6 +25,10 @@ const ( // ConnectionOptions contains configuration settings for the connection's pipeline. // All zero-value fields will be initialized with their default values. type ConnectionOptions struct { + // AuxiliaryTenants contains a list of additional tenants to be used to authenticate + // across multiple tenants. + AuxiliaryTenants []string + // HTTPClient sets the transport for making HTTP requests. HTTPClient azcore.Transport @@ -95,7 +99,14 @@ func NewConnection(endpoint string, cred azcore.TokenCredential, options *Connec policies = append(policies, azcore.NewRetryPolicy(&options.Retry)) policies = append(policies, options.PerRetryPolicies...) policies = append(policies, - cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: []string{endpointToScope(endpoint)}}}), + cred.NewAuthenticationPolicy( + azcore.AuthenticationOptions{ + TokenRequest: azcore.TokenRequestOptions{ + Scopes: []string{endpointToScope(endpoint)}, + }, + AuxiliaryTenants: options.AuxiliaryTenants, + }, + ), azcore.NewLogPolicy(&options.Logging)) p := azcore.NewPipeline(options.HTTPClient, policies...) return &Connection{u: endpoint, p: p} diff --git a/sdk/armcore/connection_test.go b/sdk/armcore/connection_test.go index 0e765383c42e..67c6db25b758 100644 --- a/sdk/armcore/connection_test.go +++ b/sdk/armcore/connection_test.go @@ -18,7 +18,7 @@ import ( type mockTokenCred struct{} -func (mockTokenCred) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { +func (mockTokenCred) NewAuthenticationPolicy(azcore.AuthenticationOptions) azcore.Policy { return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { return req.Next() }) @@ -68,7 +68,7 @@ func TestNewConnectionWithOptions(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, UserAgent) { + if ua := resp.Request.Header.Get("User-Agent"); !strings.HasPrefix(ua, UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } @@ -99,7 +99,7 @@ func TestNewConnectionWithCustomTelemetry(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - if ua := resp.Request.Header.Get(azcore.HeaderUserAgent); !strings.HasPrefix(ua, myTelemetry+" "+UserAgent) { + if ua := resp.Request.Header.Get("User-Agent"); !strings.HasPrefix(ua, myTelemetry+" "+UserAgent) { t.Fatalf("unexpected User-Agent %s", ua) } } From bce43e2f73aac49952dfa5ec7ed5c1832104ccfe Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Thu, 22 Jul 2021 14:50:28 -0700 Subject: [PATCH 2/5] update based on latest azcore --- sdk/armcore/policy_register_rp.go | 2 +- sdk/armcore/policy_register_rp_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/armcore/policy_register_rp.go b/sdk/armcore/policy_register_rp.go index 8960b90dc610..d5aacca1420f 100644 --- a/sdk/armcore/policy_register_rp.go +++ b/sdk/armcore/policy_register_rp.go @@ -87,7 +87,7 @@ func NewRPRegistrationPolicy(endpoint string, cred azcore.Credential, o *Registr pipeline: azcore.NewPipeline(o.HTTPClient, azcore.NewTelemetryPolicy(&o.Telemetry), azcore.NewRetryPolicy(&o.Retry), - cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: []string{endpointToScope(endpoint)}}}), + cred.NewAuthenticationPolicy(azcore.AuthenticationOptions{TokenRequest: azcore.TokenRequestOptions{Scopes: []string{endpointToScope(endpoint)}}}), azcore.NewLogPolicy(&o.Logging)), options: *o, } diff --git a/sdk/armcore/policy_register_rp_test.go b/sdk/armcore/policy_register_rp_test.go index 2c2dfbe6f636..7ab4646a3812 100644 --- a/sdk/armcore/policy_register_rp_test.go +++ b/sdk/armcore/policy_register_rp_test.go @@ -108,7 +108,7 @@ func TestRPRegistrationPolicyNA(t *testing.T) { defer close() // response indicates no RP registration is required, policy does nothing srv.AppendResponse(mock.WithStatusCode(http.StatusOK)) - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), testRPRegistrationOptions(srv))) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), testRPRegistrationOptions(srv))) req, err := azcore.NewRequest(context.Background(), http.MethodGet, srv.URL()) if err != nil { t.Fatal(err) @@ -147,7 +147,7 @@ func TestRPRegistrationPolicy409Other(t *testing.T) { defer close() // test getting a 409 but not due to registration required srv.AppendResponse(mock.WithStatusCode(http.StatusConflict), mock.WithBody([]byte(failedResp))) - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), testRPRegistrationOptions(srv))) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), testRPRegistrationOptions(srv))) req, err := azcore.NewRequest(context.Background(), http.MethodGet, srv.URL()) if err != nil { t.Fatal(err) @@ -178,7 +178,7 @@ func TestRPRegistrationPolicyTimesOut(t *testing.T) { // polling responses to Register() and Get(), in progress but slow // tests registration takes too long, times out srv.RepeatResponse(10, mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(rpRegisteringResp)), mock.WithSlowResponse(400*time.Millisecond)) - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), testRPRegistrationOptions(srv))) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), testRPRegistrationOptions(srv))) req, err := azcore.NewRequest(context.Background(), http.MethodGet, azcore.JoinPaths(srv.URL(), requestEndpoint)) if err != nil { t.Fatal(err) @@ -222,7 +222,7 @@ func TestRPRegistrationPolicyExceedsAttempts(t *testing.T) { // polling response, successful registration srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(rpRegisteredResp))) } - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), testRPRegistrationOptions(srv))) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), testRPRegistrationOptions(srv))) req, err := azcore.NewRequest(context.Background(), http.MethodGet, azcore.JoinPaths(srv.URL(), requestEndpoint)) if err != nil { t.Fatal(err) @@ -270,7 +270,7 @@ func TestRPRegistrationPolicyCanCancel(t *testing.T) { srv.RepeatResponse(10, mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(rpRegisteringResp)), mock.WithSlowResponse(300*time.Millisecond)) opts := RegistrationOptions{} opts.HTTPClient = srv - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), &opts)) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), &opts)) // log only RP registration azcore.Log().SetClassifications(LogRPRegistration) defer func() { @@ -323,7 +323,7 @@ func TestRPRegistrationPolicyDisabled(t *testing.T) { srv.AppendResponse(mock.WithStatusCode(http.StatusConflict), mock.WithBody([]byte(rpUnregisteredResp))) ops := testRPRegistrationOptions(srv) ops.MaxAttempts = -1 - pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.AnonymousCredential(), ops)) + pl := azcore.NewPipeline(srv, NewRPRegistrationPolicy(srv.URL(), azcore.NewAnonymousCredential(), ops)) req, err := azcore.NewRequest(context.Background(), http.MethodGet, azcore.JoinPaths(srv.URL(), requestEndpoint)) if err != nil { t.Fatal(err) From 53ba4edcfb8df7ecd0640a81c800e8c0f5f24370 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Tue, 27 Jul 2021 13:09:24 -0700 Subject: [PATCH 3/5] update to latest azcore --- sdk/armcore/go.mod | 2 +- sdk/armcore/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/armcore/go.mod b/sdk/armcore/go.mod index 91c7df6b1aeb..2bd49163fd56 100644 --- a/sdk/armcore/go.mod +++ b/sdk/armcore/go.mod @@ -3,6 +3,6 @@ module github.com/Azure/azure-sdk-for-go/sdk/armcore go 1.14 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 ) diff --git a/sdk/armcore/go.sum b/sdk/armcore/go.sum index 50a97bab95d6..fa04cccc1563 100644 --- a/sdk/armcore/go.sum +++ b/sdk/armcore/go.sum @@ -1,5 +1,5 @@ -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/azcore v0.17.0 h1:j9ra6YGWu3TqNmCprpWYFCqQ3aizqujxrqhI7KLu6qg= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0/go.mod h1:MVdrcUC4Hup35qHym3VdzoW+NBgBxrta9Vei97jRtM8= github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 h1:vx8McI56N5oLSQu8xa+xdiE0fjQq8W8Zt49vHP8Rygw= github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1/go.mod h1:k4KbFSunV/+0hOHL1vyFaPsiYQ1Vmvy1TBpmtvCDLZM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= From cb8bdfa61db8061ba3c2c892d3618e985457a6a0 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Tue, 27 Jul 2021 13:48:31 -0700 Subject: [PATCH 4/5] lint updates --- sdk/armcore/internal/pollers/async/async.go | 2 +- sdk/armcore/internal/pollers/loc/loc_test.go | 1 - sdk/armcore/internal/pollers/pollers_test.go | 12 ++++++------ sdk/armcore/poller.go | 2 +- sdk/armcore/poller_test.go | 11 ++++++++++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sdk/armcore/internal/pollers/async/async.go b/sdk/armcore/internal/pollers/async/async.go index 7476b55ee76e..bc1a7f46e82a 100644 --- a/sdk/armcore/internal/pollers/async/async.go +++ b/sdk/armcore/internal/pollers/async/async.go @@ -16,7 +16,7 @@ import ( const ( finalStateAsync = "azure-async-operation" - finalStateLoc = "location" + finalStateLoc = "location" //nolint:deadcode finalStateOrig = "original-uri" ) diff --git a/sdk/armcore/internal/pollers/loc/loc_test.go b/sdk/armcore/internal/pollers/loc/loc_test.go index ce14b9393bf3..c9969b8a43e4 100644 --- a/sdk/armcore/internal/pollers/loc/loc_test.go +++ b/sdk/armcore/internal/pollers/loc/loc_test.go @@ -19,7 +19,6 @@ import ( const ( fakePollingURL1 = "https://foo.bar.baz/status" fakePollingURL2 = "https://foo.bar.baz/updated" - fakeResourceURL = "https://foo.bar.baz/resource" ) func initialResponse(method string) *azcore.Response { diff --git a/sdk/armcore/internal/pollers/pollers_test.go b/sdk/armcore/internal/pollers/pollers_test.go index 0523387daba9..123a252f1f78 100644 --- a/sdk/armcore/internal/pollers/pollers_test.go +++ b/sdk/armcore/internal/pollers/pollers_test.go @@ -133,27 +133,27 @@ func TestMakeID(t *testing.T) { } func TestDecodeID(t *testing.T) { - id, kind, err := DecodeID("") + _, _, err := DecodeID("") if err == nil { t.Fatal("unexpected nil error") } - id, kind, err = DecodeID("invalid_token") + _, _, err = DecodeID("invalid_token") if err == nil { t.Fatal("unexpected nil error") } - id, kind, err = DecodeID("invalid_token;") + _, _, err = DecodeID("invalid_token;") if err == nil { t.Fatal("unexpected nil error") } - id, kind, err = DecodeID(" ;invalid_token") + _, _, err = DecodeID(" ;invalid_token") if err == nil { t.Fatal("unexpected nil error") } - id, kind, err = DecodeID("invalid;token;too") + _, _, err = DecodeID("invalid;token;too") if err == nil { t.Fatal("unexpected nil error") } - id, kind, err = DecodeID("pollerID;kind") + id, kind, err := DecodeID("pollerID;kind") if err != nil { t.Fatal(err) } diff --git a/sdk/armcore/poller.go b/sdk/armcore/poller.go index 6927406b9f4d..75e00060cc9d 100644 --- a/sdk/armcore/poller.go +++ b/sdk/armcore/poller.go @@ -219,7 +219,7 @@ func (l *LROPoller) FinalResponse(ctx context.Context, respType interface{}) (*h func (l *LROPoller) PollUntilDone(ctx context.Context, freq time.Duration, respType interface{}) (*http.Response, error) { start := time.Now() logPollUntilDoneExit := func(v interface{}) { - azcore.Log().Writef(azcore.LogLongRunningOperation, "END PollUntilDone() for %T: %v, total time: %s", l.lro, v, time.Now().Sub(start)) + azcore.Log().Writef(azcore.LogLongRunningOperation, "END PollUntilDone() for %T: %v, total time: %s", l.lro, v, time.Since(start)) } azcore.Log().Writef(azcore.LogLongRunningOperation, "BEGIN PollUntilDone() for %T", l.lro) if l.resp != nil { diff --git a/sdk/armcore/poller_test.go b/sdk/armcore/poller_test.go index b71aa9f7ed95..15fa8f7d9aaf 100644 --- a/sdk/armcore/poller_test.go +++ b/sdk/armcore/poller_test.go @@ -26,7 +26,7 @@ const ( provStateStarted = `{ "properties": { "provisioningState": "Started" } }` provStateUpdating = `{ "properties": { "provisioningState": "Updating" } }` provStateSucceeded = `{ "properties": { "provisioningState": "Succeeded" }, "field": "value" }` - provStateFailed = `{ "properties": { "provisioningState": "Failed" } }` + provStateFailed = `{ "properties": { "provisioningState": "Failed" } }` //nolint:deadcode statusInProgress = `{ "status": "InProgress" }` statusSucceeded = `{ "status": "Succeeded" }` statusCanceled = `{ "status": "Canceled" }` @@ -97,6 +97,9 @@ func TestNewLROPollerAsync(t *testing.T) { t.Fatal(err) } poller, err = NewLROPollerFromResumeToken("pollerID", tk, pl, handleError) + if err != nil { + t.Fatal(err) + } var result mockType _, err = poller.PollUntilDone(context.Background(), 10*time.Millisecond, &result) if err != nil { @@ -127,6 +130,9 @@ func TestNewLROPollerBody(t *testing.T) { t.Fatal(err) } poller, err = NewLROPollerFromResumeToken("pollerID", tk, pl, handleError) + if err != nil { + t.Fatal(err) + } var result mockType _, err = poller.PollUntilDone(context.Background(), 10*time.Millisecond, &result) if err != nil { @@ -158,6 +164,9 @@ func TestNewLROPollerLoc(t *testing.T) { t.Fatal(err) } poller, err = NewLROPollerFromResumeToken("pollerID", tk, pl, handleError) + if err != nil { + t.Fatal(err) + } var result mockType _, err = poller.PollUntilDone(context.Background(), 10*time.Millisecond, &result) if err != nil { From 7d5682e17b97a8eff198bc938a19d05708a2cc27 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Tue, 27 Jul 2021 15:09:57 -0700 Subject: [PATCH 5/5] update nolint --- sdk/armcore/internal/pollers/async/async.go | 2 +- sdk/armcore/poller_test.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/armcore/internal/pollers/async/async.go b/sdk/armcore/internal/pollers/async/async.go index bc1a7f46e82a..6080e7fc4f94 100644 --- a/sdk/armcore/internal/pollers/async/async.go +++ b/sdk/armcore/internal/pollers/async/async.go @@ -16,7 +16,7 @@ import ( const ( finalStateAsync = "azure-async-operation" - finalStateLoc = "location" //nolint:deadcode + finalStateLoc = "location" //nolint finalStateOrig = "original-uri" ) diff --git a/sdk/armcore/poller_test.go b/sdk/armcore/poller_test.go index 15fa8f7d9aaf..b4f8fe8a62d0 100644 --- a/sdk/armcore/poller_test.go +++ b/sdk/armcore/poller_test.go @@ -26,7 +26,7 @@ const ( provStateStarted = `{ "properties": { "provisioningState": "Started" } }` provStateUpdating = `{ "properties": { "provisioningState": "Updating" } }` provStateSucceeded = `{ "properties": { "provisioningState": "Succeeded" }, "field": "value" }` - provStateFailed = `{ "properties": { "provisioningState": "Failed" } }` //nolint:deadcode + provStateFailed = `{ "properties": { "provisioningState": "Failed" } }` //nolint statusInProgress = `{ "status": "InProgress" }` statusSucceeded = `{ "status": "Succeeded" }` statusCanceled = `{ "status": "Canceled" }` @@ -306,6 +306,9 @@ func TestNewLROPollerSuccessNoContent(t *testing.T) { t.Fatal(err) } poller, err = NewLROPollerFromResumeToken("pollerID", tk, pl, handleError) + if err != nil { + t.Fatal(err) + } var result mockType _, err = poller.PollUntilDone(context.Background(), 10*time.Millisecond, &result) if err != nil {