-
Notifications
You must be signed in to change notification settings - Fork 13
/
client.go
68 lines (55 loc) · 1.31 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package argocd
import (
"fmt"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/intelops/go-common/logging"
"github.com/kelseyhightower/envconfig"
"github.com/kube-tarian/kad/capten/common-pkg/k8s"
)
type ArgoCDClient struct {
conf *Configuration
logger logging.Logger
client apiclient.Client
}
func GetConfig(logger logging.Logger) (*Configuration, error) {
cfg := &Configuration{}
err := envconfig.Process("", cfg)
if err != nil {
return nil, err
}
k8sClient, err := k8s.NewK8SClient(logger)
if err != nil {
return nil, err
}
if cfg.Password == "" {
res, err := k8sClient.GetSecretData("argo-cd", "argocd-initial-admin-secret")
if err != nil {
return nil, err
}
password := res.Data["password"]
if len(password) == 0 {
return nil, fmt.Errorf("argo-cd credentials not found in the secret")
}
cfg.Password = password
}
if !cfg.IsSSLEnabled {
// TODO: Configure SSL certificates
logger.Errorf("SSL not yet supported, continuing with insecure verify true")
}
return cfg, nil
}
func NewClient(logger logging.Logger) (*ArgoCDClient, error) {
cfg, err := GetConfig(logger)
if err != nil {
return nil, err
}
client, err := getNewAPIClient(cfg)
if err != nil {
return nil, err
}
return &ArgoCDClient{
conf: cfg,
logger: logger,
client: client,
}, nil
}