in cmd/sync.go [691:770]
func (cca *cookedSyncCmdArgs) process() (err error) {
ctx := context.WithValue(context.TODO(), ste.ServiceAPIVersionOverride, ste.DefaultServiceApiVersion)
err = common.SetBackupMode(cca.backupMode, cca.fromTo)
if err != nil {
return err
}
if err := common.VerifyIsURLResolvable(cca.source.Value); cca.fromTo.From().IsRemote() && err != nil {
return fmt.Errorf("failed to resolve source: %w", err)
}
if err := common.VerifyIsURLResolvable(cca.destination.Value); cca.fromTo.To().IsRemote() && err != nil {
return fmt.Errorf("failed to resolve destination: %w", err)
}
// Verifies credential type and initializes credential info.
// Note that this is for the destination.
cca.credentialInfo, _, err = GetCredentialInfoForLocation(ctx, cca.fromTo.To(), cca.destination, false, cca.cpkOptions)
if err != nil {
return err
}
srcCredInfo, _, err := GetCredentialInfoForLocation(ctx, cca.fromTo.From(), cca.source, true, cca.cpkOptions)
if err != nil {
return err
}
cca.s2sSourceCredentialType = srcCredInfo.CredentialType
// Download is the only time our primary credential type will be based on source
if cca.fromTo.IsDownload() {
cca.credentialInfo = srcCredInfo
} else if cca.fromTo.IsS2S() {
cca.s2sSourceCredentialType = srcCredInfo.CredentialType // Assign the source credential type in S2S
}
// For OAuthToken credential, assign OAuthTokenInfo to CopyJobPartOrderRequest properly,
// the info will be transferred to STE.
if cca.credentialInfo.CredentialType.IsAzureOAuth() || srcCredInfo.CredentialType.IsAzureOAuth() {
uotm := GetUserOAuthTokenManagerInstance()
// Get token from env var or cache.
if tokenInfo, err := uotm.GetTokenInfo(ctx); err != nil {
return err
} else if _, err := tokenInfo.GetTokenCredential(); err != nil {
return err
}
}
// TODO: Remove this check when FileBlob w/ File OAuth works.
if cca.fromTo.IsS2S() && cca.fromTo.From() == common.ELocation.File() && srcCredInfo.CredentialType.IsAzureOAuth() && cca.fromTo.To() != common.ELocation.File() {
return fmt.Errorf("S2S sync from Azure File authenticated with Azure AD to Blob/BlobFS is not supported")
}
// Check if destination is system container
if cca.fromTo.IsS2S() || cca.fromTo.IsUpload() {
dstContainerName, err := GetContainerName(cca.destination.Value, cca.fromTo.To())
if err != nil {
return fmt.Errorf("failed to get container name from destination (is it formatted correctly?)")
}
if common.IsSystemContainer(dstContainerName) {
return fmt.Errorf("cannot copy to system container '%s'", dstContainerName)
}
}
enumerator, err := cca.initEnumerator(ctx)
if err != nil {
return err
}
// trigger the progress reporting
if !cca.dryrunMode {
cca.waitUntilJobCompletion(false)
}
// trigger the enumeration
err = enumerator.enumerate()
if err != nil {
return err
}
return nil
}