Skip to content

Commit

Permalink
cmd/move-blobs: set api version for azure stack hub
Browse files Browse the repository at this point in the history
also use the client options on every instantiation
  • Loading branch information
flavianmissi committed Feb 19, 2024
1 parent c5aedae commit 819a476
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cmd/move-blobs/main.go
Expand Up @@ -299,34 +299,38 @@ func getClient(cloudConfig cloud.Configuration, opts *configOpts) (*container.Cl
opts.containerName,
)
var client *container.Client
clientOpts := azcore.ClientOptions{
Cloud: cloudConfig,
}

if strings.EqualFold(opts.environment, "AZURESTACKCLOUD") {
clientOpts.APIVersion = "2019-06-01"
}

if len(opts.accountKey) > 0 {
cred, err := container.NewSharedKeyCredential(opts.storageAccountName, opts.accountKey)
if err != nil {
return nil, err
}
client, err = container.NewClientWithSharedKeyCredential(containerURL, cred, nil)
client, err = container.NewClientWithSharedKeyCredential(containerURL, cred, &container.ClientOptions{ClientOptions: clientOpts})
if err != nil {
return nil, err
}
} else if len(opts.clientSecret) > 0 {
options := azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
ClientOptions: clientOpts,
}
cred, err := azidentity.NewClientSecretCredential(opts.tenantID, opts.clientID, opts.clientSecret, &options)
if err != nil {
return nil, err
}
client, err = container.NewClient(containerURL, cred, nil)
client, err = container.NewClient(containerURL, cred, &container.ClientOptions{ClientOptions: clientOpts})
if err != nil {
return nil, err
}
} else if len(opts.federatedTokenFile) > 0 {
options := azidentity.WorkloadIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: cloudConfig,
},
ClientOptions: clientOpts,
ClientID: opts.clientID,
TenantID: opts.tenantID,
TokenFilePath: opts.federatedTokenFile,
Expand All @@ -335,16 +339,16 @@ func getClient(cloudConfig cloud.Configuration, opts *configOpts) (*container.Cl
if err != nil {
return nil, err
}
client, err = container.NewClient(containerURL, cred, nil)
client, err = container.NewClient(containerURL, cred, &container.ClientOptions{ClientOptions: clientOpts})
if err != nil {
return nil, err
}
} else {
cred, err := azidentity.NewDefaultAzureCredential(nil)
cred, err := azidentity.NewDefaultAzureCredential(&azidentity.DefaultAzureCredentialOptions{ClientOptions: clientOpts})
if err != nil {
return nil, err
}
client, err = container.NewClient(containerURL, cred, nil)
client, err = container.NewClient(containerURL, cred, &container.ClientOptions{ClientOptions: clientOpts})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 819a476

Please sign in to comment.