| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package aws |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "fmt" |
| 8 | "strings" |
| 9 | |
| 10 | "github.com/netdata/netdata/go/plugins/plugin/agent/secrets/secretstore" |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/agent/secrets/secretstore/internal/httpx" |
| 12 | ) |
| 13 | |
| 14 | func (s *store) init(_ context.Context) error { |
| 15 | switch strings.TrimSpace(s.Config.AuthMode) { |
| 16 | case "env", "ecs", "imds": |
| 17 | s.Config.AuthMode = strings.TrimSpace(s.Config.AuthMode) |
| 18 | default: |
| 19 | return fmt.Errorf("auth_mode '%s' is invalid for kind '%s'", s.Config.AuthMode, secretstore.KindAWSSM) |
| 20 | } |
| 21 | |
| 22 | region := strings.TrimSpace(s.Config.Region) |
| 23 | if region == "" { |
| 24 | return fmt.Errorf("region is required") |
| 25 | } |
| 26 | s.Config.Region = region |
| 27 | |
| 28 | switch { |
| 29 | case s.Config.Timeout.Duration() < 0: |
| 30 | return fmt.Errorf("timeout cannot be negative") |
| 31 | case s.Config.Timeout.Duration() == 0: |
| 32 | s.Config.Timeout = defaultTimeout |
| 33 | } |
| 34 | s.runtime = &runtime{ |
| 35 | apiClient: httpx.APIClient(s.Config.Timeout.Duration()), |
| 36 | imdsClient: httpx.NoProxyClient(s.Config.Timeout.Duration()), |
| 37 | } |
| 38 | |
| 39 | published := &publishedStore{ |
| 40 | runtime: s.runtime, |
| 41 | mode: s.Config.AuthMode, |
| 42 | regionValue: region, |
| 43 | } |
| 44 | |
| 45 | s.published = published |
| 46 | return nil |
| 47 | } |