Skip to content

Commit 5babfa7

Browse files
Receivers initial commit
Signed-off-by: Anand Rajagopal <anrajag@amazon.com>
1 parent cc6f106 commit 5babfa7

File tree

9 files changed

+453
-37
lines changed

9 files changed

+453
-37
lines changed

cmd/alertmanager/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20+
"github.com/prometheus/alertmanager/secrets"
21+
"github.com/prometheus/alertmanager/secrets/providers"
2022
"log/slog"
2123
"net"
2224
"net/http"
@@ -158,10 +160,10 @@ func run() int {
158160
httpTimeout = kingpin.Flag("web.timeout", "Timeout for HTTP requests. If negative or zero, no timeout is set.").Default("0").Duration()
159161

160162
memlimitRatio = kingpin.Flag("auto-gomemlimit.ratio", "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value must be greater than 0 and less than or equal to 1.").
161-
Default("0.9").Float64()
163+
Default("0.9").Float64()
162164

163165
clusterBindAddr = kingpin.Flag("cluster.listen-address", "Listen address for cluster. Set to empty string to disable HA mode.").
164-
Default(defaultClusterAddr).String()
166+
Default(defaultClusterAddr).String()
165167
clusterAdvertiseAddr = kingpin.Flag("cluster.advertise-address", "Explicit address to advertise in cluster.").String()
166168
peers = kingpin.Flag("cluster.peer", "Initial peers (may be repeated).").Strings()
167169
peerTimeout = kingpin.Flag("cluster.peer-timeout", "Time to wait between peers to send notifications.").Default("15s").Duration()
@@ -402,8 +404,9 @@ func run() int {
402404
}
403405

404406
var (
405-
inhibitor *inhibit.Inhibitor
406-
tmpl *template.Template
407+
inhibitor *inhibit.Inhibitor
408+
tmpl *template.Template
409+
secretsProviderRegistry *secrets.SecretsProviderRegistry
407410
)
408411

409412
dispMetrics := dispatch.NewDispatcherMetrics(false, prometheus.DefaultRegisterer)
@@ -414,6 +417,9 @@ func run() int {
414417
prometheus.DefaultRegisterer,
415418
configLogger,
416419
)
420+
defer func() {
421+
secretsProviderRegistry.Stop()
422+
}()
417423
configCoordinator.Subscribe(func(conf *config.Config) error {
418424
tmpl, err = template.FromGlobs(conf.Templates)
419425
if err != nil {
@@ -428,6 +434,10 @@ func run() int {
428434
activeReceivers[r.RouteOpts.Receiver] = struct{}{}
429435
})
430436

437+
spRegistry := secrets.NewSecretsProviderRegistry(logger, prometheus.NewRegistry())
438+
// currently only one secrets providers is supported
439+
spRegistry.Register(providers.AWSSecretsManagerSecretProviderDiscoveryConfig{})
440+
spRegistry.Init()
431441
// Build the map of receiver to integrations.
432442
receivers := make(map[string][]notify.Integration, len(activeReceivers))
433443
var integrationsNum int
@@ -437,7 +447,7 @@ func run() int {
437447
configLogger.Info("skipping creation of receiver not referenced by any route", "receiver", rcv.Name)
438448
continue
439449
}
440-
integrations, err := receiver.BuildReceiverIntegrations(rcv, tmpl, logger)
450+
integrations, err := receiver.BuildReceiverIntegrations(rcv, tmpl, logger, spRegistry)
441451
if err != nil {
442452
return err
443453
}
@@ -460,10 +470,13 @@ func run() int {
460470

461471
inhibitor.Stop()
462472
disp.Stop()
473+
if secretsProviderRegistry != nil {
474+
secretsProviderRegistry.Stop()
475+
}
463476

464477
inhibitor = inhibit.NewInhibitor(alerts, conf.InhibitRules, marker, logger)
465478
silencer := silence.NewSilencer(silences, marker, logger)
466-
479+
secretsProviderRegistry = spRegistry
467480
// An interface value that holds a nil concrete value is non-nil.
468481
// Therefore we explicly pass an empty interface, to detect if the
469482
// cluster is not enabled in notify.

config/notifiers.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package config
1616
import (
1717
"errors"
1818
"fmt"
19+
"github.com/prometheus/alertmanager/secrets"
1920
"net/textproto"
2021
"regexp"
2122
"strings"
@@ -328,22 +329,22 @@ type PagerdutyConfig struct {
328329

329330
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
330331

331-
ServiceKey Secret `yaml:"service_key,omitempty" json:"service_key,omitempty"`
332-
ServiceKeyFile string `yaml:"service_key_file,omitempty" json:"service_key_file,omitempty"`
333-
RoutingKey Secret `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
334-
RoutingKeyFile string `yaml:"routing_key_file,omitempty" json:"routing_key_file,omitempty"`
335-
URL *URL `yaml:"url,omitempty" json:"url,omitempty"`
336-
Client string `yaml:"client,omitempty" json:"client,omitempty"`
337-
ClientURL string `yaml:"client_url,omitempty" json:"client_url,omitempty"`
338-
Description string `yaml:"description,omitempty" json:"description,omitempty"`
339-
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
340-
Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
341-
Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
342-
Source string `yaml:"source,omitempty" json:"source,omitempty"`
343-
Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
344-
Class string `yaml:"class,omitempty" json:"class,omitempty"`
345-
Component string `yaml:"component,omitempty" json:"component,omitempty"`
346-
Group string `yaml:"group,omitempty" json:"group,omitempty"`
332+
ServiceKey *secrets.GenericSecret `yaml:"service_key,omitempty" json:"service_key,omitempty"`
333+
ServiceKeyFile string `yaml:"service_key_file,omitempty" json:"service_key_file,omitempty"`
334+
RoutingKey *secrets.GenericSecret `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
335+
RoutingKeyFile string `yaml:"routing_key_file,omitempty" json:"routing_key_file,omitempty"`
336+
URL *URL `yaml:"url,omitempty" json:"url,omitempty"`
337+
Client string `yaml:"client,omitempty" json:"client,omitempty"`
338+
ClientURL string `yaml:"client_url,omitempty" json:"client_url,omitempty"`
339+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
340+
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
341+
Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
342+
Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
343+
Source string `yaml:"source,omitempty" json:"source,omitempty"`
344+
Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
345+
Class string `yaml:"class,omitempty" json:"class,omitempty"`
346+
Component string `yaml:"component,omitempty" json:"component,omitempty"`
347+
Group string `yaml:"group,omitempty" json:"group,omitempty"`
347348
}
348349

349350
// PagerdutyLink is a link.
@@ -366,13 +367,13 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
366367
if err := unmarshal((*plain)(c)); err != nil {
367368
return err
368369
}
369-
if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" {
370+
if c.RoutingKey == nil && c.ServiceKey == nil && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" {
370371
return errors.New("missing service or routing key in PagerDuty config")
371372
}
372-
if len(c.RoutingKey) > 0 && len(c.RoutingKeyFile) > 0 {
373+
if c.RoutingKey != nil && len(c.RoutingKeyFile) > 0 {
373374
return errors.New("at most one of routing_key & routing_key_file must be configured")
374375
}
375-
if len(c.ServiceKey) > 0 && len(c.ServiceKeyFile) > 0 {
376+
if c.ServiceKey != nil && len(c.ServiceKeyFile) > 0 {
376377
return errors.New("at most one of service_key & service_key_file must be configured")
377378
}
378379
if c.Details == nil {

config/receiver/receiver.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package receiver
1515

1616
import (
17+
"github.com/prometheus/alertmanager/secrets"
1718
"log/slog"
1819

1920
commoncfg "github.com/prometheus/common/config"
@@ -43,7 +44,7 @@ import (
4344

4445
// BuildReceiverIntegrations builds a list of integration notifiers off of a
4546
// receiver config.
46-
func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger *slog.Logger, httpOpts ...commoncfg.HTTPClientOption) ([]notify.Integration, error) {
47+
func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger *slog.Logger, spRegistry *secrets.SecretsProviderRegistry, httpOpts ...commoncfg.HTTPClientOption) ([]notify.Integration, error) {
4748
if logger == nil {
4849
logger = promslog.NewNopLogger()
4950
}
@@ -68,7 +69,9 @@ func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg
6869
add("email", i, c, func(l *slog.Logger) (notify.Notifier, error) { return email.New(c, tmpl, l), nil })
6970
}
7071
for i, c := range nc.PagerdutyConfigs {
71-
add("pagerduty", i, c, func(l *slog.Logger) (notify.Notifier, error) { return pagerduty.New(c, tmpl, l, httpOpts...) })
72+
add("pagerduty", i, c, func(l *slog.Logger) (notify.Notifier, error) {
73+
return pagerduty.New(c, tmpl, l, spRegistry, httpOpts...)
74+
})
7275
}
7376
for i, c := range nc.OpsGenieConfigs {
7477
add("opsgenie", i, c, func(l *slog.Logger) (notify.Notifier, error) { return opsgenie.New(c, tmpl, l, httpOpts...) })

go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ require (
77
github.com/alecthomas/kingpin/v2 v2.4.0
88
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b
99
github.com/aws/aws-sdk-go v1.55.5
10+
github.com/aws/aws-sdk-go-v2 v1.36.3
11+
github.com/aws/aws-sdk-go-v2/config v1.29.14
12+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.4
1013
github.com/cenkalti/backoff/v4 v4.3.0
1114
github.com/cespare/xxhash/v2 v2.3.0
1215
github.com/coder/quartz v0.1.2
@@ -53,6 +56,17 @@ require (
5356
require (
5457
github.com/armon/go-metrics v0.3.10 // indirect
5558
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
59+
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
60+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
61+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
62+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
63+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
64+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
65+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
66+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
67+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
68+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
69+
github.com/aws/smithy-go v1.22.2 // indirect
5670
github.com/beorn7/perks v1.0.1 // indirect
5771
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
5872
github.com/davecgh/go-spew v1.1.1 // indirect

go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d
8080
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
8181
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
8282
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
83+
github.com/aws/aws-sdk-go-v2 v1.36.3 h1:mJoei2CxPutQVxaATCzDUjcZEjVRdpsiiXi2o38yqWM=
84+
github.com/aws/aws-sdk-go-v2 v1.36.3/go.mod h1:LLXuLpgzEbD766Z5ECcRmi8AzSwfZItDtmABVkRLGzg=
85+
github.com/aws/aws-sdk-go-v2/config v1.29.14 h1:f+eEi/2cKCg9pqKBoAIwRGzVb70MRKqWX4dg1BDcSJM=
86+
github.com/aws/aws-sdk-go-v2/config v1.29.14/go.mod h1:wVPHWcIFv3WO89w0rE10gzf17ZYy+UVS1Geq8Iei34g=
87+
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 h1:9KxtdcIA/5xPNQyZRgUSpYOE6j9Bc4+D7nZua0KGYOM=
88+
github.com/aws/aws-sdk-go-v2/credentials v1.17.67/go.mod h1:p3C44m+cfnbv763s52gCqrjaqyPikj9Sg47kUVaNZQQ=
89+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 h1:x793wxmUWVDhshP8WW2mlnXuFrO4cOd3HLBroh1paFw=
90+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30/go.mod h1:Jpne2tDnYiFascUEs2AWHJL9Yp7A5ZVy3TNyxaAjD6M=
91+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 h1:ZK5jHhnrioRkUNOc+hOgQKlUL5JeC3S6JgLxtQ+Rm0Q=
92+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34/go.mod h1:p4VfIceZokChbA9FzMbRGz5OV+lekcVtHlPKEO0gSZY=
93+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 h1:SZwFm17ZUNNg5Np0ioo/gq8Mn6u9w19Mri8DnJ15Jf0=
94+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34/go.mod h1:dFZsC0BLo346mvKQLWmoJxT+Sjp+qcVR1tRVHQGOH9Q=
95+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 h1:bIqFDwgGXXN1Kpp99pDOdKMTTb5d2KyU5X/BZxjOkRo=
96+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3/go.mod h1:H5O/EsxDWyU+LP/V8i5sm8cxoZgc2fdNR9bxlOFrQTo=
97+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 h1:eAh2A4b5IzM/lum78bZ590jy36+d/aFLgKF/4Vd1xPE=
98+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3/go.mod h1:0yKJC/kb8sAnmlYa6Zs3QVYqaC8ug2AbnNChv5Ox3uA=
99+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 h1:dM9/92u2F1JbDaGooxTq18wmmFzbJRfXfVfy96/1CXM=
100+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15/go.mod h1:SwFBy2vjtA0vZbjjaFtfN045boopadnoVPhu4Fv66vY=
101+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.4 h1:EKXYJ8kgz4fiqef8xApu7eH0eae2SrVG+oHCLFybMRI=
102+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.4/go.mod h1:yGhDiLKguA3iFJYxbrQkQiNzuy+ddxesSZYWVeeEH5Q=
103+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 h1:1Gw+9ajCV1jogloEv1RRnvfRFia2cL6c9cuKV2Ps+G8=
104+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3/go.mod h1:qs4a9T5EMLl/Cajiw2TcbNt2UNo/Hqlyp+GiuG4CFDI=
105+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 h1:hXmVKytPfTy5axZ+fYbR5d0cFmC3JvwLm5kM83luako=
106+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1/go.mod h1:MlYRNmYu/fGPoxBQVvBYr9nyr948aY/WLUvwBMBJubs=
107+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 h1:1XuUZ8mYJw9B6lzAkXhqHlJd/XvaX32evhproijJEZY=
108+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19/go.mod h1:cQnB8CUnxbMU82JvlqjKR2HBOm3fe9pWorWBza6MBJ4=
109+
github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ=
110+
github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
83111
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
84112
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
85113
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

notify/pagerduty/pagerduty.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22+
"github.com/prometheus/alertmanager/secrets"
2223
"io"
2324
"log/slog"
2425
"net/http"
@@ -45,27 +46,30 @@ const (
4546

4647
// Notifier implements a Notifier for PagerDuty notifications.
4748
type Notifier struct {
48-
conf *config.PagerdutyConfig
49-
tmpl *template.Template
50-
logger *slog.Logger
51-
apiV1 string // for tests.
52-
client *http.Client
53-
retrier *notify.Retrier
49+
conf *config.PagerdutyConfig
50+
tmpl *template.Template
51+
logger *slog.Logger
52+
apiV1 string // for tests.
53+
client *http.Client
54+
retrier *notify.Retrier
55+
secretsFetcher secrets.SecretsFetcher
5456
}
5557

5658
// New returns a new PagerDuty notifier.
57-
func New(c *config.PagerdutyConfig, t *template.Template, l *slog.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
59+
func New(c *config.PagerdutyConfig, t *template.Template, l *slog.Logger, spRegistry *secrets.SecretsProviderRegistry, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
5860
client, err := commoncfg.NewClientFromConfig(*c.HTTPConfig, "pagerduty", httpOpts...)
5961
if err != nil {
6062
return nil, err
6163
}
6264
n := &Notifier{conf: c, tmpl: t, logger: l, client: client}
63-
if c.ServiceKey != "" || c.ServiceKeyFile != "" {
65+
if c.ServiceKey != nil || c.ServiceKeyFile != "" {
66+
n.secretsFetcher, err = spRegistry.RegisterSecret(c.ServiceKey)
6467
n.apiV1 = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
6568
// Retrying can solve the issue on 403 (rate limiting) and 5xx response codes.
6669
// https://v2.developer.pagerduty.com/docs/trigger-events
6770
n.retrier = &notify.Retrier{RetryCodes: []int{http.StatusForbidden}, CustomDetailsFunc: errDetails}
6871
} else {
72+
n.secretsFetcher, err = spRegistry.RegisterSecret(c.RoutingKey)
6973
// Retrying can solve the issue on 429 (rate limiting) and 5xx response codes.
7074
// https://v2.developer.pagerduty.com/docs/events-api-v2#api-response-codes--retry-logic
7175
n.retrier = &notify.Retrier{RetryCodes: []int{http.StatusTooManyRequests}, CustomDetailsFunc: errDetails}
@@ -143,6 +147,22 @@ func (n *Notifier) encodeMessage(msg *pagerDutyMessage) (bytes.Buffer, error) {
143147
return buf, nil
144148
}
145149

150+
func (n *Notifier) getSecret(ctx context.Context) string {
151+
var secret *secrets.GenericSecret
152+
if n.conf.ServiceKey != nil {
153+
secret = n.conf.ServiceKey
154+
} else {
155+
secret = n.conf.RoutingKey
156+
}
157+
158+
if sec, err := n.secretsFetcher.FetchSecret(ctx, secret); err != nil {
159+
n.logger.Error("unable to fetch secret", err)
160+
return ""
161+
} else {
162+
return sec
163+
}
164+
}
165+
146166
func (n *Notifier) notifyV1(
147167
ctx context.Context,
148168
eventType string,
@@ -159,7 +179,8 @@ func (n *Notifier) notifyV1(
159179
n.logger.Warn("Truncated description", "key", key, "max_runes", maxV1DescriptionLenRunes)
160180
}
161181

162-
serviceKey := string(n.conf.ServiceKey)
182+
//serviceKey := string(n.conf.ServiceKey)
183+
serviceKey := n.getSecret(ctx)
163184
if serviceKey == "" {
164185
content, fileErr := os.ReadFile(n.conf.ServiceKeyFile)
165186
if fileErr != nil {
@@ -224,7 +245,8 @@ func (n *Notifier) notifyV2(
224245
n.logger.Warn("Truncated summary", "key", key, "max_runes", maxV2SummaryLenRunes)
225246
}
226247

227-
routingKey := string(n.conf.RoutingKey)
248+
//routingKey := string(n.conf.RoutingKey)
249+
routingKey := n.getSecret(ctx)
228250
if routingKey == "" {
229251
content, fileErr := os.ReadFile(n.conf.RoutingKeyFile)
230252
if fileErr != nil {

secrets/generic_secret.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package secrets
2+
3+
import (
4+
"errors"
5+
"time"
6+
)
7+
8+
type GenericSecret struct {
9+
AWSSecretsManagerConfig *AWSSecretsManagerConfig `yaml:"aws_secrets_manager" json:"aws_secrets_manager_config"`
10+
}
11+
12+
// TODO implement this correctly
13+
func (gs *GenericSecret) String() string {
14+
return ""
15+
}
16+
17+
// TODO implement Marshal and JSON equivalent methods
18+
func (gs *GenericSecret) UnmarshalYAML(unmarshalFn func(any) error) error {
19+
var inlineForm string
20+
if err := unmarshalFn(&inlineForm); err == nil {
21+
return errors.New("inline form is not supported")
22+
}
23+
type plain GenericSecret
24+
// We need to do this to avoid infinite recursion.
25+
return unmarshalFn((*plain)(gs))
26+
}
27+
28+
type AWSSecretsManagerConfig struct {
29+
SecretARN string `yaml:"secret_arn"`
30+
SecretKey string `yaml:"secret_key"`
31+
RefreshInterval time.Duration `yaml:"refresh_interval"`
32+
}

0 commit comments

Comments
 (0)