| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package azure |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | _ "embed" |
| 8 | "net/http" |
| 9 | "regexp" |
| 10 | "time" |
| 11 | |
| 12 | "github.com/netdata/netdata/go/plugins/pkg/confopt" |
| 13 | "github.com/netdata/netdata/go/plugins/plugin/agent/secrets/secretstore" |
| 14 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/cloudauth" |
| 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | //go:embed config_schema.json |
| 19 | configSchema string |
| 20 | reAzureSafeName = regexp.MustCompile(`^[a-zA-Z0-9-]+$`) |
| 21 | ) |
| 22 | |
| 23 | var defaultTimeout = confopt.Duration(3 * time.Second) |
| 24 | |
| 25 | type Config struct { |
| 26 | cloudauth.AzureADAuthConfig `yaml:",inline" json:",inline"` |
| 27 | Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"` |
| 28 | } |
| 29 | |
| 30 | type runtime struct { |
| 31 | apiClient *http.Client |
| 32 | imdsClient *http.Client |
| 33 | } |
| 34 | |
| 35 | type store struct { |
| 36 | Config `yaml:",inline" json:""` |
| 37 | runtime *runtime |
| 38 | published *publishedStore |
| 39 | } |
| 40 | |
| 41 | type publishedStore struct { |
| 42 | runtime *runtime |
| 43 | tokenProvider *cloudauth.TokenProvider |
| 44 | } |
| 45 | |
| 46 | func New() secretstore.Creator { |
| 47 | return secretstore.Creator{ |
| 48 | Kind: secretstore.KindAzureKV, |
| 49 | DisplayName: "Azure Key Vault", |
| 50 | Schema: configSchema, |
| 51 | Create: func() secretstore.Store { |
| 52 | return &store{ |
| 53 | Config: Config{ |
| 54 | Timeout: defaultTimeout, |
| 55 | }, |
| 56 | } |
| 57 | }, |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func (s *store) Configuration() any { return &s.Config } |
| 62 | |
| 63 | func (s *store) Init(ctx context.Context) error { return s.init(ctx) } |
| 64 | |
| 65 | func (s *store) Publish() secretstore.PublishedStore { return s.published } |