master
go 71 lines 1.71 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package gcp
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 )
15
16 var (
17 //go:embed config_schema.json
18 configSchema string
19 reGCPSafeProjectID = regexp.MustCompile(`^[a-zA-Z0-9._:-]+$`)
20 reGCPSafeName = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
21 )
22
23 var defaultTimeout = confopt.Duration(3 * time.Second)
24
25 type Config struct {
26 Mode string `json:"mode" yaml:"mode"`
27 ModeServiceAccountFile *ModeServiceAccountFileConfig `json:"mode_service_account_file,omitempty" yaml:"mode_service_account_file,omitempty"`
28 Timeout confopt.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
29 }
30
31 type ModeServiceAccountFileConfig struct {
32 Path string `json:"path" yaml:"path"`
33 }
34
35 type runtime struct {
36 apiClient *http.Client
37 metadataClient *http.Client
38 }
39
40 type store struct {
41 Config `yaml:",inline" json:""`
42 runtime *runtime
43 published *publishedStore
44 }
45
46 type publishedStore struct {
47 runtime *runtime
48 mode string
49 serviceAccountFilePath string
50 }
51
52 func New() secretstore.Creator {
53 return secretstore.Creator{
54 Kind: secretstore.KindGCPSM,
55 DisplayName: "Google Secret Manager",
56 Schema: configSchema,
57 Create: func() secretstore.Store {
58 return &store{
59 Config: Config{
60 Timeout: defaultTimeout,
61 },
62 }
63 },
64 }
65 }
66
67 func (s *store) Configuration() any { return &s.Config }
68
69 func (s *store) Init(ctx context.Context) error { return s.init(ctx) }
70
71 func (s *store) Publish() secretstore.PublishedStore { return s.published }