azure: deduplicate cli and default credentials case

This commit is contained in:
Michael Eischer 2024-05-18 22:15:38 +02:00
parent 355f520936
commit c56ecec9aa

View file

@ -101,23 +101,21 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
if err != nil { if err != nil {
return nil, errors.Wrap(err, "NewAccountSASClientFromEndpointToken") return nil, errors.Wrap(err, "NewAccountSASClientFromEndpointToken")
} }
} else if cfg.ForceCliCredential {
debug.Log(" - using AzureCLICredential")
cred, err := azidentity.NewAzureCLICredential(nil)
if err != nil {
return nil, errors.Wrap(err, "NewAzureCLICredential")
}
client, err = azContainer.NewClient(url, cred, opts)
if err != nil {
return nil, errors.Wrap(err, "NewClient")
}
} else { } else {
debug.Log(" - using DefaultAzureCredential") var cred azcore.TokenCredential
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil { if cfg.ForceCliCredential {
return nil, errors.Wrap(err, "NewDefaultAzureCredential") debug.Log(" - using AzureCLICredential")
cred, err = azidentity.NewAzureCLICredential(nil)
if err != nil {
return nil, errors.Wrap(err, "NewAzureCLICredential")
}
} else {
debug.Log(" - using DefaultAzureCredential")
cred, err = azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, errors.Wrap(err, "NewDefaultAzureCredential")
}
} }
client, err = azContainer.NewClient(url, cred, opts) client, err = azContainer.NewClient(url, cred, opts)