| 137 | } |
| 138 | |
| 139 | func (m *Manager) SaveCredentials(ctx context.Context, orgID string, creds any, opts ...credentials.SaveOption) (string, error) { |
| 140 | credsM, err := structToMap(creds) |
| 141 | if err != nil { |
| 142 | return "", fmt.Errorf("converting struct to map: %w", err) |
| 143 | } |
| 144 | |
| 145 | o := credentials.ApplySaveOptions(opts...) |
| 146 | secretName := o.SecretName |
| 147 | if secretName == "" { |
| 148 | secretName = strings.Join([]string{m.secretPrefix, orgID, uuid.Generate().String()}, "/") |
| 149 | } |
| 150 | m.logger.Infow("msg", "storing credentials", "path", secretName) |
| 151 | |
| 152 | _, err = m.client.Put(ctx, secretName, credsM) |
| 153 | if err != nil { |
| 154 | return "", fmt.Errorf("storing secret in Vault: %w", err) |
| 155 | } |
| 156 | |
| 157 | return secretName, nil |
| 158 | } |
| 159 | |
| 160 | func (m *Manager) ReadCredentials(ctx context.Context, secretID string, creds any) error { |
| 161 | m.logger.Infow("msg", "reading credentials", "path", secretID) |