Skip to content

Commit

Permalink
Fix issue #88: Use env to set Azure auth if existed (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
atlas-comstock authored Jun 2, 2022
1 parent edc2d8e commit c6fb73c
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions internal/storage/writer/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,20 @@ func (m *MultiAccountWriter) getContainerURL() (*azblob.ContainerURL, error) {
}

func getServicePrincipalToken(monitor monitor.Monitor) (*adal.ServicePrincipalToken, error) {

spt, err := adal.NewServicePrincipalTokenFromManagedIdentity(azure.PublicCloud.ResourceIdentifiers.Storage, &adal.ManagedIdentityOptions{})

if err == nil {
monitor.Info("azure: acquired Manange Identity Credentials")
return spt, err
if settings, err := auth.GetSettingsFromEnvironment(); err == nil {
if cc, err := settings.GetClientCredentials(); err == nil {
monitor.Info("azure: acquired Credentials from Environment")
return cc.ServicePrincipalToken()
}
}
monitor.Warning(errors.Internal("azure: unable to retrieve Manange Identity Credentials", err))

settings, err := auth.GetSettingsFromEnvironment()
if err != nil {
return nil, err
}
cc, err := settings.GetClientCredentials()
spt, err := adal.NewServicePrincipalTokenFromManagedIdentity(azure.PublicCloud.ResourceIdentifiers.Storage, &adal.ManagedIdentityOptions{})
if err != nil {
return nil, err
monitor.Warning(errors.Internal("azure: unable to retrieve Credentials", err))
return spt, err
}

spt, err = cc.ServicePrincipalToken()

monitor.Info("azure: acquired Credentials")
return spt, err

}

0 comments on commit c6fb73c

Please sign in to comment.