Skip to content

Commit

Permalink
Support both azid and autorest certificate env vars
Browse files Browse the repository at this point in the history
For certificate authentication, autorest uses the `AZURE_CERTIFICATE_`
prefix whereas azidentity uses `AZURE_CLIENT_CERTIFICATE_`. Let's make
sure the latter is set to the value of the former so as not to break
upgrades.
  • Loading branch information
r4f4 committed Dec 10, 2022
1 parent 815cc6e commit 598d788
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions azure/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ func (c *AzureClients) setCredentials(subscriptionID, environmentName string) er
Cloud: config,
},
}

// azidentity uses different envvars for certificate authentication
// Let's set it according to the envvars used by autorest, in case they are present
_, azidSet := os.LookupEnv("AZURE_CLIENT_CERTIFICATE_PATH")
path, autorestSet := os.LookupEnv("AZURE_CERTIFICATE_PATH")
if !azidSet && autorestSet {
os.Setenv("AZURE_CLIENT_CERTIFICATE_PATH", path)
os.Setenv("AZURE_CLIENT_CERTIFICATE_PASSWORD", os.Getenv("AZURE_CERTIFICATE_PASSWORD"))
}

cred, err := azidentity.NewDefaultAzureCredential(&options)
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ func GetAuthorizer(settings auth.EnvironmentSettings) (autorest.Authorizer, erro
Cloud: config,
},
}

// azidentity uses different envvars for certificate authentication
// Let's set it according to the envvars used by autorest, in case they are present
_, azidSet := os.LookupEnv("AZURE_CLIENT_CERTIFICATE_PATH")
path, autorestSet := os.LookupEnv("AZURE_CERTIFICATE_PATH")
if !azidSet && autorestSet {
os.Setenv("AZURE_CLIENT_CERTIFICATE_PATH", path)
os.Setenv("AZURE_CLIENT_CERTIFICATE_PASSWORD", os.Getenv("AZURE_CERTIFICATE_PASSWORD"))
}

cred, err := azidentity.NewDefaultAzureCredential(&options)
if err != nil {
return nil, err
Expand Down

0 comments on commit 598d788

Please sign in to comment.