-
Notifications
You must be signed in to change notification settings - Fork 250
Cleanup in preparation for sync refactor #3217
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
base: gapra/libraryPhase2
Are you sure you want to change the base?
Changes from all commits
6d4f600
0d1228d
5ba554e
3049e9e
52bea7b
c0c2822
45e9681
87a9b52
bb095b0
c8d149e
c1371d2
bc96906
799ef32
ce78780
9f9b142
cdb0354
e51f126
614ccc7
b3c108a
d9e535b
4dea252
38f2af2
f1e9a26
c41eace
1347da7
ab61190
e00fd6c
628e056
1fc66f8
632fb35
3b01f17
f6713dc
887a26c
7118d16
69cfa68
ce0d360
53c1f4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,144 @@ | ||||||
| package azcopy | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
|
|
||||||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||||||
| "github.com/Azure/azure-storage-azcopy/v10/common" | ||||||
| "github.com/Azure/azure-storage-azcopy/v10/traverser" | ||||||
| ) | ||||||
|
|
||||||
| func GetSourceServiceClient(ctx context.Context, | ||||||
adreed-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| source common.ResourceString, | ||||||
| loc common.Location, | ||||||
| trailingDot common.TrailingDotOption, | ||||||
| cpk common.CpkOptions, | ||||||
| uotm *common.UserOAuthTokenManager) (*common.ServiceClient, common.CredentialType, error) { | ||||||
| srcCredType, _, err := GetCredentialTypeForLocation(ctx, | ||||||
| loc, | ||||||
| source, | ||||||
| true, | ||||||
| uotm, | ||||||
| cpk) | ||||||
| if err != nil { | ||||||
| return nil, srcCredType, err | ||||||
| } | ||||||
| var tc azcore.TokenCredential | ||||||
| if srcCredType.IsAzureOAuth() { | ||||||
| // Get token from env var or cache. | ||||||
| tokenInfo, err := uotm.GetTokenInfo(ctx) | ||||||
| if err != nil { | ||||||
| return nil, srcCredType, err | ||||||
| } | ||||||
|
|
||||||
| tc, err = tokenInfo.GetTokenCredential() | ||||||
| if err != nil { | ||||||
| return nil, srcCredType, err | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| var srcReauthTok *common.ScopedAuthenticator | ||||||
| if at, ok := tc.(common.AuthenticateToken); ok { // We don't need two different tokens here since it gets passed in just the same either way. | ||||||
| // This will cause a reauth with StorageScope, which is fine, that's the original Authenticate call as it stands. | ||||||
| srcReauthTok = (*common.ScopedAuthenticator)(common.NewScopedCredential(at, common.ECredentialType.OAuthToken())) | ||||||
| } | ||||||
|
|
||||||
| options := traverser.CreateClientOptions(common.AzcopyCurrentJobLogger, nil, srcReauthTok) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a condition in the client creation for if we're not using OAuth tokens? |
||||||
|
|
||||||
| // Create Source Client. | ||||||
| var azureFileSpecificOptions any | ||||||
| if loc == common.ELocation.File() || loc == common.ELocation.FileNFS() { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loc.IsFile()
Suggested change
|
||||||
| azureFileSpecificOptions = &common.FileClientOptions{ | ||||||
| AllowTrailingDot: trailingDot == common.ETrailingDotOption.Enable(), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| srcServiceClient, err := common.GetServiceClientForLocation( | ||||||
| loc, | ||||||
| source, | ||||||
| srcCredType, | ||||||
| tc, | ||||||
| &options, | ||||||
| azureFileSpecificOptions, | ||||||
| ) | ||||||
| if err != nil { | ||||||
| return nil, srcCredType, err | ||||||
| } | ||||||
| return srcServiceClient, srcCredType, nil | ||||||
| } | ||||||
|
|
||||||
| func GetDestinationServiceClient(ctx context.Context, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating an item for this. There are some updates I need to make with the method args so I'll clean it up at once after the core of the migration is done |
||||||
| destination common.ResourceString, | ||||||
| fromTo common.FromTo, | ||||||
| srcCredType common.CredentialType, | ||||||
| trailingDot common.TrailingDotOption, | ||||||
| cpk common.CpkOptions, | ||||||
| uotm *common.UserOAuthTokenManager) (*common.ServiceClient, common.CredentialType, error) { | ||||||
| dstCredType, _, err := GetCredentialTypeForLocation(ctx, | ||||||
| fromTo.To(), | ||||||
| destination, | ||||||
| false, | ||||||
| uotm, | ||||||
| cpk) | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
| var tc azcore.TokenCredential | ||||||
| if dstCredType.IsAzureOAuth() { | ||||||
| // Get token from env var or cache. | ||||||
| tokenInfo, err := uotm.GetTokenInfo(ctx) | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
|
|
||||||
| tc, err = tokenInfo.GetTokenCredential() | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| var dstReauthTok *common.ScopedAuthenticator | ||||||
| if at, ok := tc.(common.AuthenticateToken); ok { // We don't need two different tokens here since it gets passed in just the same either way. | ||||||
| // This will cause a reauth with StorageScope, which is fine, that's the original Authenticate call as it stands. | ||||||
| dstReauthTok = (*common.ScopedAuthenticator)(common.NewScopedCredential(at, common.ECredentialType.OAuthToken())) | ||||||
| } | ||||||
|
|
||||||
| var srcTokenCred *common.ScopedToken | ||||||
| if fromTo.IsS2S() && srcCredType.IsAzureOAuth() { | ||||||
| // Get token from env var or cache. | ||||||
| srcTokenInfo, err := uotm.GetTokenInfo(ctx) | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
|
|
||||||
| sourceTc, err := srcTokenInfo.GetTokenCredential() | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
| srcTokenCred = common.NewScopedCredential(sourceTc, srcCredType) | ||||||
| } | ||||||
|
|
||||||
| options := traverser.CreateClientOptions(common.AzcopyCurrentJobLogger, srcTokenCred, dstReauthTok) | ||||||
|
|
||||||
| // Create Destination Client. | ||||||
| var azureFileSpecificOptions any | ||||||
| if fromTo.To() == common.ELocation.File() || fromTo.To() == common.ELocation.FileNFS() { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fromTo.To().IsFile()
Suggested change
|
||||||
| azureFileSpecificOptions = &common.FileClientOptions{ | ||||||
| AllowTrailingDot: trailingDot == common.ETrailingDotOption.Enable(), | ||||||
| AllowSourceTrailingDot: trailingDot == common.ETrailingDotOption.Enable() && fromTo.To() == common.ELocation.File(), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| dstServiceClient, err := common.GetServiceClientForLocation( | ||||||
| fromTo.To(), | ||||||
| destination, | ||||||
| dstCredType, | ||||||
| tc, | ||||||
| &options, | ||||||
| azureFileSpecificOptions, | ||||||
| ) | ||||||
| if err != nil { | ||||||
| return nil, dstCredType, err | ||||||
| } | ||||||
| return dstServiceClient, dstCredType, nil | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need the microsoft licensing header?