Repository navigation
Add credential refresh for track2 SDKs #5124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+441
−67
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7fc7309
ARO-30032 add multiple rebuilder support
rajdeepc2792 206fdfc
ARO-30032 use multiple rebuilder for refreshing FP credentials
rajdeepc2792 023e151
ARO-30032 BearerTokenPolicy must ask GetToken asap
rajdeepc2792 8a43b00
ARO-30032 separate rebuilder interface and token implementations
rajdeepc2792 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package refreshable | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "github.com/Azure/go-autorest/autorest" | ||
|
|
||
| "github.com/Azure/ARO-RP/pkg/env" | ||
| ) | ||
|
|
||
| type Authorizer interface { | ||
| autorest.Authorizer | ||
| Rebuilder | ||
| } | ||
|
|
||
| type authorizer struct { | ||
| auth autorest.Authorizer | ||
| env env.Interface | ||
| tenantID string | ||
| } | ||
|
|
||
| func (a *authorizer) Rebuild() error { | ||
| auth, err := a.env.FPAuthorizer(a.tenantID, nil, a.env.Environment().ResourceManagerScope) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| a.auth = auth | ||
| return nil | ||
| } | ||
|
|
||
| func (a *authorizer) WithAuthorization() autorest.PrepareDecorator { | ||
| return a.auth.WithAuthorization() | ||
| } | ||
|
|
||
| // NewAuthorizer creates an Authorizer that can be rebuilt when needed to force | ||
| // token recreation. | ||
| func NewAuthorizer(_env env.Interface, tenantID string) (Authorizer, error) { | ||
| a := &authorizer{ | ||
| env: _env, | ||
| tenantID: tenantID, | ||
| } | ||
| err := a.Rebuild() | ||
| return a, err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package refreshable | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
| ) | ||
|
|
||
| type fakeRebuilder struct { | ||
| calls int | ||
| err error | ||
| } | ||
|
|
||
| func (r *fakeRebuilder) Rebuild() error { | ||
| r.calls++ | ||
| return r.err | ||
| } | ||
|
|
||
| func TestMultiRebuilder(t *testing.T) { | ||
| wantErr := errors.New("boom") | ||
|
rajdeepc2792 marked this conversation as resolved.
|
||
|
|
||
| for _, tt := range []struct { | ||
| name string | ||
| first *fakeRebuilder | ||
| second *fakeRebuilder | ||
| wantErr error | ||
| wantCalls []int | ||
| }{ | ||
| { | ||
| name: "rebuilds all", | ||
| first: &fakeRebuilder{}, | ||
| second: &fakeRebuilder{}, | ||
| wantCalls: []int{1, 1}, | ||
| }, | ||
| { | ||
| name: "stops at first error", | ||
| first: &fakeRebuilder{err: wantErr}, | ||
| second: &fakeRebuilder{}, | ||
| wantErr: wantErr, | ||
| wantCalls: []int{1, 0}, | ||
| }, | ||
| } { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := NewMultiRebuilder(tt.first, nil, tt.second).Rebuild() | ||
| if !errors.Is(err, tt.wantErr) { | ||
| t.Errorf("got %v, wanted %v", err, tt.wantErr) | ||
| } | ||
| if tt.first.calls != tt.wantCalls[0] || tt.second.calls != tt.wantCalls[1] { | ||
| t.Errorf("got calls %d,%d wanted %v", tt.first.calls, tt.second.calls, tt.wantCalls) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.