SaveCredentials saves credentials. If opts includes WithExistingSecret, upserts at the given path.
(ctx context.Context, orgID string, creds any, opts ...credentials.SaveOption)
| 122 | |
| 123 | // SaveCredentials saves credentials. If opts includes WithExistingSecret, upserts at the given path. |
| 124 | func (m *Manager) SaveCredentials(ctx context.Context, orgID string, creds any, opts ...credentials.SaveOption) (string, error) { |
| 125 | o := credentials.ApplySaveOptions(opts...) |
| 126 | secretName := o.SecretName |
| 127 | if secretName == "" { |
| 128 | secretName = strings.Join([]string{m.secretPrefix, orgID, uuid.New().String()}, "-") |
| 129 | } |
| 130 | |
| 131 | // Store the credentials as json key pairs |
| 132 | c, err := json.Marshal(creds) |
| 133 | if err != nil { |
| 134 | return "", fmt.Errorf("marshaling credentials to be stored: %w", err) |
| 135 | } |
| 136 | |
| 137 | if _, err := m.client.SetSecret(ctx, secretName, azsecrets.SetSecretParameters{Value: strPtr(string(c))}, nil); err != nil { |
| 138 | return "", fmt.Errorf("failed to set secret: %w", err) |
| 139 | } |
| 140 | |
| 141 | return secretName, nil |
| 142 | } |
| 143 | |
| 144 | // ReadCredentials reads the latest version of the credentials |
| 145 | func (m *Manager) ReadCredentials(ctx context.Context, secretName string, creds any) error { |