From 434058c60846c126fecda9634f6226fa81f9f41c Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Fri, 1 Apr 2016 10:04:33 -0600 Subject: [PATCH 1/3] feat(repo): validate repo url format --- pkg/repo/inmem_repo_service.go | 6 ++++++ pkg/repo/inmem_repo_service_test.go | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/repo/inmem_repo_service.go b/pkg/repo/inmem_repo_service.go index 7e048e373..3865f8947 100644 --- a/pkg/repo/inmem_repo_service.go +++ b/pkg/repo/inmem_repo_service.go @@ -17,6 +17,7 @@ limitations under the License. package repo import ( + "errors" "fmt" "strings" "sync" @@ -62,6 +63,11 @@ func (rs *inmemRepoService) CreateRepo(repository IRepo) error { URL := repository.GetURL() name := repository.GetName() + valid := GCSRepoURLMatcher.MatchString(URL) + if !valid { + return errors.New(URL + " is an invalid Repo URL") + } + for u, r := range rs.repositories { if u == URL { return fmt.Errorf("Repository with URL %s already exists", URL) diff --git a/pkg/repo/inmem_repo_service_test.go b/pkg/repo/inmem_repo_service_test.go index 4c214188b..119c8535f 100644 --- a/pkg/repo/inmem_repo_service_test.go +++ b/pkg/repo/inmem_repo_service_test.go @@ -85,6 +85,19 @@ func TestCreateRepoWithDuplicateURL(t *testing.T) { } } +func TestCreateRepoWithInvalidURL(t *testing.T) { + rs := NewInmemRepoService() + invalidURL := "fake://sfds" + r, err := newRepo(invalidURL, "", TestName, GCSRepoFormat, GCSRepoType) + if err != nil { + t.Fatalf("cannot create test repo: %v", err) + } + + if err = rs.CreateRepo(r); err == nil { + t.Fatalf("created repo with invalid URL: %s", invalidURL) + } +} + func TestGetRepoWithInvalidURL(t *testing.T) { invalidURL := "https://not.a.valid/url" rs := NewInmemRepoService() @@ -96,7 +109,7 @@ func TestGetRepoWithInvalidURL(t *testing.T) { func TestGetRepoURLByName(t *testing.T) { rs := NewInmemRepoService() - testURL := "gcs://helm-test-charts" + testURL := "gs://helm-test-charts" r, err := newRepo(testURL, "", TestName, GCSRepoFormat, GCSRepoType) err = rs.CreateRepo(r) if err != nil { From 41f4705ec992ee63fc692586f4401024c8e5b2c9 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Fri, 1 Apr 2016 10:04:59 -0600 Subject: [PATCH 2/3] feat(repo): add `repo add` command description --- cmd/helm/repository.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 549a39f46..7acfa6a6f 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -43,6 +43,14 @@ const repoDesc = `Helm repositories store Helm charts. For more details, use 'helm repo CMD -h'. ` +const addRepoDesc = `The add repository command is used to add a name a repository url to your + chart repository list. The repository url must begin with a valid protocoal. At the moment, + we only support google cloud storage for chart repositories. + + A valid command might look like: + $ helm repo add charts gs://kubernetes-charts +` + func repoCommands() cli.Command { return cli.Command{ Name: "repository", @@ -51,10 +59,11 @@ func repoCommands() cli.Command { Description: repoDesc, Subcommands: []cli.Command{ { - Name: "add", - Usage: "Add a chart repository to the remote manager.", - ArgsUsage: "[NAME] [REPOSITORY_URL]", - Action: func(c *cli.Context) { run(c, addRepo) }, + Name: "add", + Usage: "Add a chart repository to the remote manager.", + Description: addRepoDesc, + ArgsUsage: "[NAME] [REPOSITORY_URL]", + Action: func(c *cli.Context) { run(c, addRepo) }, }, { Name: "list", From d732e83839d67fd786cf159450f1d49fc8616071 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Fri, 1 Apr 2016 10:05:31 -0600 Subject: [PATCH 3/3] fix(repo): fix args description --- cmd/helm/repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 7acfa6a6f..f17c2fae2 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -75,7 +75,7 @@ func repoCommands() cli.Command { Name: "remove", Aliases: []string{"rm"}, Usage: "Remove a chart repository from the remote manager.", - ArgsUsage: "REPOSITORY_URL", + ArgsUsage: "REPOSITORY_NAME", Action: func(c *cli.Context) { run(c, removeRepo) }, }, },