All checks were successful
Release Secrets Manager Action / build (push) Successful in 1m12s
31 lines
1 KiB
Go
31 lines
1 KiB
Go
package secretsmanager
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"secretsmanager/config"
|
|
|
|
"github.com/hashicorp/vault-client-go"
|
|
)
|
|
|
|
func (s *SecretsManager) GetSecrets(ctx context.Context, cfg config.Config) (map[string]interface{}, error) {
|
|
config.InfoLog("Attempting to read secret from mount '%s' at path '%s'", cfg.VaultSecretsManagerID, cfg.VaultPath)
|
|
secret, err := s.Client.Secrets.KvV2Read(ctx, cfg.VaultPath, vault.WithMountPath(cfg.VaultSecretsManagerID))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read secret from vault: %w", err)
|
|
}
|
|
|
|
if secret == nil || secret.Data.Data == nil {
|
|
return nil, fmt.Errorf("no data found at the specified secret path")
|
|
}
|
|
|
|
//var secretsAsKeyValue []string
|
|
//for key, value := range secret.Data.Data {
|
|
// secretsAsKeyValue = append(secretsAsKeyValue, fmt.Sprintf("%s=%v", key, value))
|
|
//}
|
|
//config.InfoLog("Successfully retrieved and formatted %d secrets.", len(secretsAsKeyValue))
|
|
|
|
config.InfoLog("Successfully retrieved and formatted %d secrets.", len(secret.Data.Data))
|
|
|
|
return secret.Data.Data, nil
|
|
}
|