| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package vault |
| 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 | Mode string `json:"mode" yaml:"mode"` |
| 22 | ModeToken *ModeTokenConfig `json:"mode_token,omitempty" yaml:"mode_token,omitempty"` |
| 23 | ModeTokenFile *ModeTokenFileConfig `json:"mode_token_file,omitempty" yaml:"mode_token_file,omitempty"` |
| 24 | Addr string `json:"addr" yaml:"addr"` |
| 25 | Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` |
| 26 | TLSSkipVerify bool `json:"tls_skip_verify,omitempty" yaml:"tls_skip_verify,omitempty"` |
| 27 | Timeout confopt.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"` |
| 28 | } |
| 29 | |
| 30 | type ModeTokenConfig struct { |
| 31 | Token string `json:"token" yaml:"token"` |
| 32 | } |
| 33 | |
| 34 | type ModeTokenFileConfig struct { |
| 35 | Path string `json:"path" yaml:"path"` |
| 36 | } |
| 37 | |
| 38 | type runtime struct { |
| 39 | httpClient *http.Client |
| 40 | httpClientInsecure *http.Client |
| 41 | } |
| 42 | |
| 43 | type store struct { |
| 44 | Config `yaml:",inline" json:""` |
| 45 | runtime *runtime |
| 46 | published *publishedStore |
| 47 | } |
| 48 | |
| 49 | type publishedStore struct { |
| 50 | runtime *runtime |
| 51 | mode string |
| 52 | tokenValue string |
| 53 | tokenFilePath string |
| 54 | addr string |
| 55 | namespaceValue string |
| 56 | tlsSkipVerify bool |
| 57 | } |
| 58 | |
| 59 | func New() secretstore.Creator { |
| 60 | return secretstore.Creator{ |
| 61 | Kind: secretstore.KindVault, |
| 62 | DisplayName: "Vault", |
| 63 | Schema: configSchema, |
| 64 | Create: func() secretstore.Store { |
| 65 | return &store{ |
| 66 | Config: Config{ |
| 67 | Timeout: defaultTimeout, |
| 68 | }, |
| 69 | } |
| 70 | }, |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func (s *store) Configuration() any { return &s.Config } |
| 75 | |
| 76 | func (s *store) Init(ctx context.Context) error { return s.init(ctx) } |
| 77 | |
| 78 | func (s *store) Publish() secretstore.PublishedStore { return s.published } |