MCPcopy
hub / github.com/grafana/k6 / Get

Method Get

secretsource/manager.go:56–76  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

54// It can be used with the [DefaultSourceName].
55// This automatically starts redacting the secret before returning it.
56func (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
79type UnknownSourceError string

Callers 1

TestSetConfigAndGetFunction · 0.95

Calls 5

UnknownSourceErrorTypeAlias · 0.85
LoadMethod · 0.80
StoreMethod · 0.80
GetMethod · 0.65
addMethod · 0.45

Tested by 1

TestSetConfigAndGetFunction · 0.76