-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab4ea56
commit c9fc63b
Showing
5 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
package config | ||
|
||
import "fmt" | ||
import ( | ||
"context" | ||
"fmt" | ||
|
||
func loadFromAzureKeyVault() (*Config, error) { | ||
return nil, fmt.Errorf("loading config from Azure Key Vault is not implemented yet") | ||
operatorcontext "altinn.studio/altinn-k8s-operator/internal/operator_context" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets" | ||
) | ||
|
||
func loadFromAzureKeyVault(operatorContext *operatorcontext.Context) (*Config, error) { | ||
context := context.Background() | ||
|
||
var cred azcore.TokenCredential | ||
var err error | ||
|
||
if operatorContext.IsLocal() { | ||
cred, err = azidentity.NewDefaultAzureCredential(nil) | ||
} else { | ||
cred, err = azidentity.NewWorkloadIdentityCredential(nil) | ||
} | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("error getting credentials for loading config: %w", err) | ||
} | ||
|
||
url := fmt.Sprintf("https://altinn-%s-operator-kv.vault.azure.net", operatorContext.Env) | ||
client, err := azsecrets.NewClient(url, cred, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("error building client for Azure KV: %w", err) | ||
} | ||
|
||
secretKeys := []string{"ClientId", "Url", "Jwk", "Scope"} | ||
|
||
config := &Config{} | ||
for _, secretKey := range secretKeys { | ||
secret, err := client.GetSecret(context, secretKey, "", nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting secret: %s, %w", secretKey, err) | ||
} | ||
|
||
switch secretKey { | ||
case "ClientId": | ||
config.MaskinportenApi.ClientId = *secret.Value | ||
case "Url": | ||
config.MaskinportenApi.Url = *secret.Value | ||
case "Jwk": | ||
config.MaskinportenApi.Jwk = *secret.Value | ||
case "Scope": | ||
config.MaskinportenApi.Scope = *secret.Value | ||
} | ||
} | ||
|
||
return config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters