| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package aws |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | _ "embed" |
| 8 | "net/http" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/netdata/netdata/go/plugins/pkg/confopt" |
| 12 | "github.com/netdata/netdata/go/plugins/plugin/agent/secrets/secretstore" |
| 13 | ) |
| 14 | |
| 15 | //go:embed config_schema.json |
| 16 | var configSchema string |
| 17 | |
| 18 | var defaultTimeout = confopt.Duration(3 * time.Second) |
| 19 | |
| 20 | type Config struct { |
| 21 | AuthMode string `json:"auth_mode" yaml:"auth_mode"` |
| 22 | Region string `json:"region" yaml:"region"` |
| 23 | Timeout confopt.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"` |
| 24 | } |
| 25 | |
| 26 | type credentials struct { |
| 27 | accessKeyID string |
| 28 | secretAccessKey string |
| 29 | sessionToken string |
| 30 | } |
| 31 | |
| 32 | type runtime struct { |
| 33 | apiClient *http.Client |
| 34 | imdsClient *http.Client |
| 35 | } |
| 36 | |
| 37 | type store struct { |
| 38 | Config `yaml:",inline" json:""` |
| 39 | runtime *runtime |
| 40 | published *publishedStore |
| 41 | } |
| 42 | |
| 43 | type publishedStore struct { |
| 44 | runtime *runtime |
| 45 | mode string |
| 46 | regionValue string |
| 47 | } |
| 48 | |
| 49 | func New() secretstore.Creator { |
| 50 | return secretstore.Creator{ |
| 51 | Kind: secretstore.KindAWSSM, |
| 52 | DisplayName: "AWS Secrets Manager", |
| 53 | Schema: configSchema, |
| 54 | Create: func() secretstore.Store { |
| 55 | return &store{ |
| 56 | Config: Config{ |
| 57 | Timeout: defaultTimeout, |
| 58 | }, |
| 59 | } |
| 60 | }, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func (s *store) Configuration() any { return &s.Config } |
| 65 | |
| 66 | func (s *store) Init(ctx context.Context) error { return s.init(ctx) } |
| 67 | |
| 68 | func (s *store) Publish() secretstore.PublishedStore { return s.published } |