-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelm.go
More file actions
53 lines (33 loc) · 984 Bytes
/
helm.go
File metadata and controls
53 lines (33 loc) · 984 Bytes
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
package main
import (
"log"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/registry"
)
type RegistryAuth struct {
Username string `help:"Username for the registry."`
Password string `help:"Password for the registry."`
Registry string `help:"Registry URL."`
}
func helmLogin(auth RegistryAuth) {
settings := cli.New()
actionConfig := new(action.Configuration)
err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), "", log.Printf)
if err != nil {
log.Fatalf("Failed to initialize Helm action configuration: %v", err)
}
regClient, err := registry.NewClient()
if err != nil {
log.Fatalf("Failed to create Helm registry client: %v", err)
}
err = regClient.Login(
auth.Registry,
registry.LoginOptBasicAuth(auth.Username, auth.Password),
)
if err != nil {
log.Fatalf("Failed to log in to registry: %v", err)
} else {
log.Printf("Successfully logged in to registry %s", auth.Registry)
}
}