Skip to content

Commit

Permalink
chore: Load keyvault url from environment variable in example (#561)
Browse files Browse the repository at this point in the history
* Load keyvault url from environment variable in example

Make it easy to test in sovereign clouds

* chore: update example

* fix log
  • Loading branch information
karataliu committed Sep 14, 2022
1 parent 1f67e29 commit c91eb15
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/msal-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import (
)

func main() {
keyvaultName := os.Getenv("KEYVAULT_NAME")
secretName := os.Getenv("SECRET_NAME")

keyvaultURL := fmt.Sprintf("https://%s.vault.azure.net/", keyvaultName)
keyvaultURL := os.Getenv("KEYVAULT_URL")
if keyvaultURL == "" {
keyvaultName := os.Getenv("KEYVAULT_NAME")
// fallback to use global cloud
keyvaultURL = fmt.Sprintf("https://%s.vault.azure.net/", keyvaultName)
}
secretName := os.Getenv("SECRET_NAME")

// initialize keyvault client with custom authorizer
kvClient := keyvault.New()
Expand All @@ -24,7 +27,7 @@ func main() {
for {
secretBundle, err := kvClient.GetSecret(context.Background(), keyvaultURL, secretName, "")
if err != nil {
klog.ErrorS(err, "failed to get secret from keyvault", "keyvault", keyvaultName, "secretName", secretName)
klog.ErrorS(err, "failed to get secret from keyvault", "keyvault", keyvaultURL, "secretName", secretName)
os.Exit(1)
}
klog.InfoS("successfully got secret", "secret", *secretBundle.Value)
Expand Down

0 comments on commit c91eb15

Please sign in to comment.