From args to flags, fetch command fix and backward compatibility fix.

pull/3206/head
eyalbe4 8 years ago
parent 37adf2c5e8
commit 4175b5dba0

@ -96,6 +96,8 @@ func newFetchCmd(out io.Writer) *cobra.Command {
}
f := cmd.Flags()
f.StringVar(&fch.username, "username", "", "chart repository username")
f.StringVar(&fch.password, "password", "", "chart repository password")
f.BoolVar(&fch.untar, "untar", false, "if set to true, will untar the chart after downloading it")
f.StringVar(&fch.untardir, "untardir", ".", "if untar is specified, this flag specifies the name of the directory into which the chart is expanded")
f.BoolVar(&fch.verify, "verify", false, "verify the package against its signature")
@ -142,7 +144,7 @@ func (f *fetchCmd) run() error {
}
if f.repoURL != "" {
chartURL, err := repo.FindChartInRepoURL(f.repoURL, f.username, f.password, f.chartRef, f.version, f.certFile, f.keyFile, f.caFile, getter.All(settings))
chartURL, err := repo.FindChartInAuthRepoURL(f.repoURL, f.username, f.password, f.chartRef, f.version, f.certFile, f.keyFile, f.caFile, getter.All(settings))
if err != nil {
return err
}

@ -425,7 +425,7 @@ func locateChartPath(repoURL, username, password, name, version string, verify b
dl.Verify = downloader.VerifyAlways
}
if repoURL != "" {
chartURL, err := repo.FindChartInRepoURL(repoURL, username, password, name, version,
chartURL, err := repo.FindChartInAuthRepoURL(repoURL, username, password, name, version,
certFile, keyFile, caFile, getter.All(settings))
if err != nil {
return "", err

@ -46,30 +46,15 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
add := &repoAddCmd{out: out}
cmd := &cobra.Command{
Use: "add [flags] [NAME] [URL] [USERNAME] [PASSWORD]",
Use: "add [flags] [NAME] [URL]",
Short: "add a chart repository",
RunE: func(cmd *cobra.Command, args []string) error {
argsDesc := []string{
"name for the chart repository",
"the url of the chart repository",
"the username for the chart repository",
"the password of the chart repository",
}
if len(args) <= 2 {
if err := checkArgsLength(len(args), argsDesc[0], argsDesc[1]); err != nil {
return err
}
} else if err := checkArgsLength(len(args), argsDesc[0], argsDesc[1], argsDesc[2], argsDesc[3]); err != nil {
if err := checkArgsLength(len(args), "name for the chart repository", "the url of the chart repository"); err != nil {
return err
}
add.name = args[0]
add.url = args[1]
if len(args) == 4 {
add.username = args[2]
add.password = args[3]
}
add.home = settings.Home
return add.run()
@ -77,6 +62,8 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
}
f := cmd.Flags()
f.StringVar(&add.username, "username", "", "chart repository username")
f.StringVar(&add.password, "password", "", "chart repository password")
f.BoolVar(&add.noupdate, "no-update", false, "raise error if repo is already registered")
f.StringVar(&add.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&add.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")

@ -275,8 +275,8 @@ fantastic-charts https://fantastic-charts.storage.googleapis.com
If the charts are backed by HTTP basic authentication, you can also supply the
username and password here:
```console
$ helm repo add fantastic-charts https://username:password@fantastic-charts.storage.googleapis.com my-username my-password
``console
$ helm repo add fantastic-charts https://fantastic-charts.storage.googleapis.com --username my-username--password my-password
$ helm repo list
fantastic-charts https://username:password@fantastic-charts.storage.googleapis.com
```

@ -188,7 +188,14 @@ func (r *ChartRepository) generateIndex() error {
// FindChartInRepoURL finds chart in chart repository pointed by repoURL
// without adding repo to repositories
func FindChartInRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) {
func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) {
return FindChartInAuthRepoURL(repoURL, "", "", chartName, chartVersion, certFile, keyFile, caFile, getters)
}
// FindChartInRepoURL finds chart in chart repository pointed by repoURL
// without adding repo to repositories.
// Unlike the FindChartInRepoURL function, this function also receives credentials for the chart repository.
func FindChartInAuthRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) {
// Download and write the index file to a temporary location
tempIndexFile, err := ioutil.TempFile("", "tmp-repo-file")

@ -221,7 +221,7 @@ func TestFindChartInRepoURL(t *testing.T) {
}
defer srv.Close()
chartURL, err := FindChartInRepoURL(srv.URL, "", "", "nginx", "", "", "", "", getter.All(environment.EnvSettings{}))
chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(environment.EnvSettings{}))
if err != nil {
t.Errorf("%s", err)
}
@ -229,7 +229,7 @@ func TestFindChartInRepoURL(t *testing.T) {
t.Errorf("%s is not the valid URL", chartURL)
}
chartURL, err = FindChartInRepoURL(srv.URL, "", "", "nginx", "0.1.0", "", "", "", getter.All(environment.EnvSettings{}))
chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(environment.EnvSettings{}))
if err != nil {
t.Errorf("%s", err)
}
@ -239,7 +239,7 @@ func TestFindChartInRepoURL(t *testing.T) {
}
func TestErrorFindChartInRepoURL(t *testing.T) {
_, err := FindChartInRepoURL("http://someserver/something", "", "", "nginx", "", "", "", "", getter.All(environment.EnvSettings{}))
_, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", getter.All(environment.EnvSettings{}))
if err == nil {
t.Errorf("Expected error for bad chart URL, but did not get any errors")
}
@ -253,7 +253,7 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
}
defer srv.Close()
_, err = FindChartInRepoURL(srv.URL, "", "", "nginx1", "", "", "", "", getter.All(environment.EnvSettings{}))
_, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", getter.All(environment.EnvSettings{}))
if err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors")
}
@ -261,7 +261,7 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err)
}
_, err = FindChartInRepoURL(srv.URL, "", "", "nginx1", "0.1.0", "", "", "", getter.All(environment.EnvSettings{}))
_, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", getter.All(environment.EnvSettings{}))
if err == nil {
t.Errorf("Expected error for chart not found, but did not get any errors")
}
@ -269,7 +269,7 @@ func TestErrorFindChartInRepoURL(t *testing.T) {
t.Errorf("Expected error for chart not found, but got a different error (%v)", err)
}
_, err = FindChartInRepoURL(srv.URL, "", "", "chartWithNoURL", "", "", "", "", getter.All(environment.EnvSettings{}))
_, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", getter.All(environment.EnvSettings{}))
if err == nil {
t.Errorf("Expected error for no chart URLs available, but did not get any errors")
}

Loading…
Cancel
Save