Get is the way to get a secret for the provided source name and key of the secret. It can be used with the [DefaultSourceName]. This automatically starts redacting the secret before returning it.
(sourceName, key string)
| 54 | // It can be used with the [DefaultSourceName]. |
| 55 | // This automatically starts redacting the secret before returning it. |
| 56 | func (sm *Manager) Get(sourceName, key string) (string, error) { |
| 57 | if len(sm.cache) == 0 { |
| 58 | return "", errors.New("no secret sources are configured") |
| 59 | } |
| 60 | sourceCache, ok := sm.cache[sourceName] |
| 61 | if !ok { |
| 62 | return "", UnknownSourceError(sourceName) |
| 63 | } |
| 64 | v, ok := sourceCache.Load(key) |
| 65 | if ok { |
| 66 | return v.(string), nil //nolint:forcetypeassert |
| 67 | } |
| 68 | source := sm.sources[sourceName] |
| 69 | value, err := source.Get(key) |
| 70 | if err != nil { |
| 71 | return "", err |
| 72 | } |
| 73 | sourceCache.Store(key, value) |
| 74 | sm.hook.add(value) |
| 75 | return value, err |
| 76 | } |
| 77 | |
| 78 | // UnknownSourceError is returned when a unknown source is requested |
| 79 | type UnknownSourceError string |