Skip to content

Commit 837ae42

Browse files
committedJun 19, 2024··
Add username/password to dependency build/update subcommands
Signed-off-by: Evans Mungai <mbuevans@gmail.com>
1 parent 7672a17 commit 837ae42

12 files changed

+56
-26
lines changed
 

‎cmd/helm/dependency.go

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121

2222
"github.com/spf13/cobra"
23+
"github.com/spf13/pflag"
2324

2425
"helm.sh/helm/v3/cmd/helm/require"
2526
"helm.sh/helm/v3/pkg/action"
@@ -120,3 +121,16 @@ func newDependencyListCmd(out io.Writer) *cobra.Command {
120121
f.UintVar(&client.ColumnWidth, "max-col-width", 80, "maximum column width for output table")
121122
return cmd
122123
}
124+
125+
func addDependencySubcommandFlags(f *pflag.FlagSet, client *action.Dependency) {
126+
f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures")
127+
f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys")
128+
f.BoolVar(&client.SkipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
129+
f.StringVar(&client.Username, "username", "", "chart repository username where to locate the requested chart")
130+
f.StringVar(&client.Password, "password", "", "chart repository password where to locate the requested chart")
131+
f.StringVar(&client.CertFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
132+
f.StringVar(&client.KeyFile, "key-file", "", "identify HTTPS client using this SSL key file")
133+
f.BoolVar(&client.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download")
134+
f.BoolVar(&client.PlainHTTP, "plain-http", false, "use insecure HTTP connections for the chart download")
135+
f.StringVar(&client.CAFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
136+
}

‎cmd/helm/dependency_build.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If no lock file is found, 'helm dependency build' will mirror the behavior
4141
of 'helm dependency update'.
4242
`
4343

44-
func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
44+
func newDependencyBuildCmd(_ *action.Configuration, out io.Writer) *cobra.Command {
4545
client := action.NewDependency()
4646

4747
cmd := &cobra.Command{
@@ -54,21 +54,27 @@ func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Comm
5454
if len(args) > 0 {
5555
chartpath = filepath.Clean(args[0])
5656
}
57+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
58+
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
59+
if err != nil {
60+
return fmt.Errorf("missing registry client: %w", err)
61+
}
62+
5763
man := &downloader.Manager{
5864
Out: out,
5965
ChartPath: chartpath,
6066
Keyring: client.Keyring,
6167
SkipUpdate: client.SkipRefresh,
6268
Getters: getter.All(settings),
63-
RegistryClient: cfg.RegistryClient,
69+
RegistryClient: registryClient,
6470
RepositoryConfig: settings.RepositoryConfig,
6571
RepositoryCache: settings.RepositoryCache,
6672
Debug: settings.Debug,
6773
}
6874
if client.Verify {
6975
man.Verify = downloader.VerifyIfPossible
7076
}
71-
err := man.Build()
77+
err = man.Build()
7278
if e, ok := err.(downloader.ErrRepoNotFound); ok {
7379
return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error())
7480
}
@@ -77,9 +83,7 @@ func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Comm
7783
}
7884

7985
f := cmd.Flags()
80-
f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures")
81-
f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys")
82-
f.BoolVar(&client.SkipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
86+
addDependencySubcommandFlags(f, client)
8387

8488
return cmd
8589
}

‎cmd/helm/dependency_update.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19+
"fmt"
1920
"io"
2021
"path/filepath"
2122

@@ -43,7 +44,7 @@ in the Chart.yaml file, but (b) at the wrong version.
4344
`
4445

4546
// newDependencyUpdateCmd creates a new dependency update command.
46-
func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
47+
func newDependencyUpdateCmd(_ *action.Configuration, out io.Writer) *cobra.Command {
4748
client := action.NewDependency()
4849

4950
cmd := &cobra.Command{
@@ -57,13 +58,19 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com
5758
if len(args) > 0 {
5859
chartpath = filepath.Clean(args[0])
5960
}
61+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
62+
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
63+
if err != nil {
64+
return fmt.Errorf("missing registry client: %w", err)
65+
}
66+
6067
man := &downloader.Manager{
6168
Out: out,
6269
ChartPath: chartpath,
6370
Keyring: client.Keyring,
6471
SkipUpdate: client.SkipRefresh,
6572
Getters: getter.All(settings),
66-
RegistryClient: cfg.RegistryClient,
73+
RegistryClient: registryClient,
6774
RepositoryConfig: settings.RepositoryConfig,
6875
RepositoryCache: settings.RepositoryCache,
6976
Debug: settings.Debug,
@@ -76,9 +83,7 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com
7683
}
7784

7885
f := cmd.Flags()
79-
f.BoolVar(&client.Verify, "verify", false, "verify the packages against signatures")
80-
f.StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys")
81-
f.BoolVar(&client.SkipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
86+
addDependencySubcommandFlags(f, client)
8287

8388
return cmd
8489
}

‎cmd/helm/flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) {
6262
f.StringVar(&c.KeyFile, "key-file", "", "identify HTTPS client using this SSL key file")
6363
f.BoolVar(&c.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download")
6464
f.BoolVar(&c.PlainHTTP, "plain-http", false, "use insecure HTTP connections for the chart download")
65-
f.StringVar(&c.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
65+
f.StringVar(&c.CAFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
6666
f.BoolVar(&c.PassCredentialsAll, "pass-credentials", false, "pass credentials to all domains")
6767
}
6868

‎cmd/helm/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
140140
return compInstall(args, toComplete, client)
141141
},
142142
RunE: func(_ *cobra.Command, args []string) error {
143-
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CaFile,
143+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
144144
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
145145
if err != nil {
146146
return fmt.Errorf("missing registry client: %w", err)

‎cmd/helm/pull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func newPullCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
6464
client.Version = ">0.0.0-0"
6565
}
6666

67-
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CaFile,
67+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
6868
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
6969
if err != nil {
7070
return fmt.Errorf("missing registry client: %w", err)

‎cmd/helm/show.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func runShow(args []string, client *action.Show) (string, error) {
226226
}
227227

228228
func addRegistryClient(client *action.Show) error {
229-
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CaFile,
229+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
230230
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
231231
if err != nil {
232232
return fmt.Errorf("missing registry client: %w", err)

‎cmd/helm/template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
7373
client.KubeVersion = parsedKubeVersion
7474
}
7575

76-
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CaFile,
76+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
7777
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
7878
if err != nil {
7979
return fmt.Errorf("missing registry client: %w", err)

‎cmd/helm/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
102102
RunE: func(_ *cobra.Command, args []string) error {
103103
client.Namespace = settings.Namespace()
104104

105-
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CaFile,
105+
registryClient, err := newRegistryClient(client.CertFile, client.KeyFile, client.CAFile,
106106
client.InsecureSkipTLSverify, client.PlainHTTP, client.Username, client.Password)
107107
if err != nil {
108108
return fmt.Errorf("missing registry client: %w", err)

‎pkg/action/dependency.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ import (
3434
//
3535
// It provides the implementation of 'helm dependency' and its respective subcommands.
3636
type Dependency struct {
37-
Verify bool
38-
Keyring string
39-
SkipRefresh bool
40-
ColumnWidth uint
37+
Verify bool
38+
Keyring string
39+
SkipRefresh bool
40+
ColumnWidth uint
41+
Username string
42+
Password string
43+
CertFile string
44+
KeyFile string
45+
CAFile string
46+
InsecureSkipTLSverify bool
47+
PlainHTTP bool
4148
}
4249

4350
// NewDependency creates a new Dependency object with the given configuration.

‎pkg/action/install.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type Install struct {
115115

116116
// ChartPathOptions captures common options used for controlling chart paths
117117
type ChartPathOptions struct {
118-
CaFile string // --ca-file
118+
CAFile string // --ca-file
119119
CertFile string // --cert-file
120120
KeyFile string // --key-file
121121
InsecureSkipTLSverify bool // --insecure-skip-verify
@@ -759,7 +759,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
759759
Getters: getter.All(settings),
760760
Options: []getter.Option{
761761
getter.WithPassCredentialsAll(c.PassCredentialsAll),
762-
getter.WithTLSClientConfig(c.CertFile, c.KeyFile, c.CaFile),
762+
getter.WithTLSClientConfig(c.CertFile, c.KeyFile, c.CAFile),
763763
getter.WithInsecureSkipVerifyTLS(c.InsecureSkipTLSverify),
764764
getter.WithPlainHTTP(c.PlainHTTP),
765765
getter.WithBasicAuth(c.Username, c.Password),
@@ -778,7 +778,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
778778
}
779779
if c.RepoURL != "" {
780780
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(c.RepoURL, c.Username, c.Password, name, version,
781-
c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings))
781+
c.CertFile, c.KeyFile, c.CAFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings))
782782
if err != nil {
783783
return "", err
784784
}

‎pkg/action/pull.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (p *Pull) Run(chartRef string) (string, error) {
8888
Options: []getter.Option{
8989
getter.WithBasicAuth(p.Username, p.Password),
9090
getter.WithPassCredentialsAll(p.PassCredentialsAll),
91-
getter.WithTLSClientConfig(p.CertFile, p.KeyFile, p.CaFile),
91+
getter.WithTLSClientConfig(p.CertFile, p.KeyFile, p.CAFile),
9292
getter.WithInsecureSkipVerifyTLS(p.InsecureSkipTLSverify),
9393
getter.WithPlainHTTP(p.PlainHTTP),
9494
},
@@ -122,7 +122,7 @@ func (p *Pull) Run(chartRef string) (string, error) {
122122
}
123123

124124
if p.RepoURL != "" {
125-
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings))
125+
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CAFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings))
126126
if err != nil {
127127
return out.String(), err
128128
}

0 commit comments

Comments
 (0)
Please sign in to comment.