// Package assets contains helper types used for loading in static assets when1// configuring the Grafana Agent.2package assets34import (5"fmt"67prom_v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"8v1 "k8s.io/api/core/v1"9)1011// Key is a path-like identifier representing a Secret or ConfigMap value. It is12// used for looking up values during config generation that cannot be loaded13// directly from a file (e.g., BasicAuth Username).14//15// The naming convention is either:16//17// /secrets/<namespace>/<name>/<key>18//19// or:20//21// /configMaps/<namespace>/<name>/<key>22//23// Resources associated with a key should be watched for changes and trigger a24// reconcile when modified.25type Key string2627// SecretStore is an in-memory cache for secrets, intended to be used for28// static secrets in generated configuration files.29type SecretStore map[Key]string3031// KeyForSecret returns the key for a given namespace and a secret key32// selector.33func KeyForSecret(namespace string, sel *v1.SecretKeySelector) Key {34if sel == nil {35return Key("")36}37return Key(fmt.Sprintf("/secrets/%s/%s/%s", namespace, sel.Name, sel.Key))38}3940// KeyForConfigMap returns the key for a given namespace and a config map41// key selector.42func KeyForConfigMap(namespace string, sel *v1.ConfigMapKeySelector) Key {43if sel == nil {44return Key("")45}46return Key(fmt.Sprintf("/configMaps/%s/%s/%s", namespace, sel.Name, sel.Key))47}4849// KeyForSelector retrieves the key for a SecretOrConfigMap.50func KeyForSelector(namespace string, sel *prom_v1.SecretOrConfigMap) Key {51switch {52case sel.ConfigMap != nil:53return KeyForConfigMap(namespace, sel.ConfigMap)54case sel.Secret != nil:55return KeyForSecret(namespace, sel.Secret)56default:57return Key("")58}59}606162