diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 1d2169492..c79105544 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -19,6 +19,7 @@ package main import ( "encoding/json" "errors" + "github.com/codegangsta/cli" "github.com/kubernetes/helm/pkg/format" "github.com/kubernetes/helm/pkg/repo" @@ -39,7 +40,7 @@ func repoCommands() cli.Command { { Name: "add", Usage: "Add a chart repository to the remote manager.", - ArgsUsage: "REPOSITORY_URL", + ArgsUsage: "[NAME] [REPOSITORY_URL]", Action: func(c *cli.Context) { run(c, addRepo) }, }, { @@ -61,11 +62,12 @@ func repoCommands() cli.Command { func addRepo(c *cli.Context) error { args := c.Args() - if len(args) < 1 { - return errors.New("'helm repo add' requires a repository url as an argument") + if len(args) < 2 { + return errors.New("'helm repo add' requires a name and repository url as arguments") } + name := args[0] repoURL := args[0] - payload, _ := json.Marshal(repo.Repo{URL: repoURL}) + payload, _ := json.Marshal(repo.Repo{URL: repoURL, Name: name}) msg := "" if _, err := NewClient(c).Post(chartRepoPath, payload, &msg); err != nil { //TODO: Return more specific errors to the user @@ -95,10 +97,16 @@ func removeRepo(c *cli.Context) error { if len(args) < 1 { return errors.New("'helm repo remove' requires a repository url as an argument") } - repoURL := args[0] - if _, err := NewClient(c).Delete(chartRepoPath, repoURL); err != nil { - return err - } - format.Msg(repoURL + "has been removed.\n") + //arg := args[0] + //u, err := url.Parse(arg) + //if err != nil { + //return err + //} + //p := filepath.Join(chartRepoPath, u.String()) + //if _, err := NewClient(c).Delete(p, nil); err != nil { + //return err + //} + //format.Msg(arg + " has been removed.\n") + format.Info("TO BE IMPLEMENTED") return nil } diff --git a/cmd/manager/chartrepos.go b/cmd/manager/chartrepos.go index d4d90593e..addd2d00c 100644 --- a/cmd/manager/chartrepos.go +++ b/cmd/manager/chartrepos.go @@ -7,6 +7,7 @@ import ( "github.com/kubernetes/helm/pkg/util" "encoding/json" + "fmt" "net/http" "net/url" "regexp" @@ -18,7 +19,7 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) { h.Add("GET /repositories/*/charts", listRepoChartsHandlerFunc) h.Add("GET /repositories/*/charts/*", getRepoChartHandlerFunc) h.Add("POST /repositories", addChartRepoHandlerFunc) - h.Add("DELETE /repositories", removeChartRepoHandlerFunc) + h.Add("DELETE /repositories/*", removeChartRepoHandlerFunc) } func listChartReposHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error { @@ -47,7 +48,7 @@ func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C return nil } - msg, _ := json.Marshal(cr.URL + " has been added to the list of chart repositories.") + msg, _ := json.Marshal(cr.Name + " has been added to the list of chart repositories.") util.LogHandlerExitWithJSON(handler, w, msg, http.StatusCreated) return nil } @@ -55,17 +56,20 @@ func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C func removeChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error { handler := "manager: remove chart repository" util.LogHandlerEntry(handler, r) + defer r.Body.Close() URL, err := pos(w, r, 2) if err != nil { return err } + fmt.Printf("URL: %#v \n", URL) err = c.Manager.RemoveChartRepo(URL) if err != nil { return err } - util.LogHandlerExitWithText(handler, w, "removed", http.StatusOK) + msg, _ := json.Marshal(URL + " has been removed from the list of chart repositories.") + util.LogHandlerExitWithJSON(handler, w, msg, http.StatusOK) return nil } diff --git a/pkg/repo/gcs_repo.go b/pkg/repo/gcs_repo.go index 95d7b2705..8209fd7f5 100644 --- a/pkg/repo/gcs_repo.go +++ b/pkg/repo/gcs_repo.go @@ -60,12 +60,12 @@ type GCSRepo struct { // NewPublicGCSRepo creates a new an IStorageRepo for the public GCS repository. func NewPublicGCSRepo(httpClient *http.Client) (IStorageRepo, error) { - return NewGCSRepo(GCSPublicRepoURL, "", nil) + return NewGCSRepo(GCSPublicRepoURL, "", GCSPublicRepoBucket, nil) } // NewGCSRepo creates a new IStorageRepo for a given GCS repository. -func NewGCSRepo(URL, credentialName string, httpClient *http.Client) (IStorageRepo, error) { - r, err := newRepo(URL, credentialName, GCSRepoFormat, GCSRepoType) +func NewGCSRepo(URL, credentialName, repoName string, httpClient *http.Client) (IStorageRepo, error) { + r, err := newRepo(URL, credentialName, repoName, GCSRepoFormat, GCSRepoType) if err != nil { return nil, err } diff --git a/pkg/repo/repo.go b/pkg/repo/repo.go index ec5751ea4..ce2a29cb3 100644 --- a/pkg/repo/repo.go +++ b/pkg/repo/repo.go @@ -22,11 +22,11 @@ import ( ) // NewRepo takes params and returns a IRepo -func NewRepo(URL, credentialName, repoFormat, repoType string) (IRepo, error) { - return newRepo(URL, credentialName, ERepoFormat(repoFormat), ERepoType(repoType)) +func NewRepo(URL, credentialName, repoName, repoFormat, repoType string) (IRepo, error) { + return newRepo(URL, credentialName, repoName, ERepoFormat(repoFormat), ERepoType(repoType)) } -func newRepo(URL, credentialName string, repoFormat ERepoFormat, repoType ERepoType) (*Repo, error) { +func newRepo(URL, credentialName, repoName string, repoFormat ERepoFormat, repoType ERepoType) (*Repo, error) { _, err := url.Parse(URL) if err != nil { return nil, fmt.Errorf("invalid URL (%s): %s", URL, err) @@ -41,6 +41,7 @@ func newRepo(URL, credentialName string, repoFormat ERepoFormat, repoType ERepoT } r := &Repo{ + Name: repoName, URL: URL, CredentialName: credentialName, Type: repoType, @@ -65,6 +66,11 @@ func (r *Repo) GetType() ERepoType { return r.Type } +// GetName returns the name of this repository. +func (r *Repo) GetName() string { + return r.Name +} + // GetURL returns the URL to the root of this repository. func (r *Repo) GetURL() string { return r.URL diff --git a/pkg/repo/repoprovider.go b/pkg/repo/repoprovider.go index 4661717e3..f5139d8d6 100644 --- a/pkg/repo/repoprovider.go +++ b/pkg/repo/repoprovider.go @@ -225,7 +225,7 @@ func (gcsrp gcsRepoProvider) GetGCSRepo(r IRepo) (IStorageRepo, error) { return nil, err } - return NewGCSRepo(r.GetURL(), r.GetCredentialName(), client) + return NewGCSRepo(r.GetURL(), r.GetCredentialName(), r.GetName(), client) } func (gcsrp gcsRepoProvider) createGCSClient(credentialName string) (*http.Client, error) { diff --git a/pkg/repo/types.go b/pkg/repo/types.go index d65e7b2ab..55d248374 100644 --- a/pkg/repo/types.go +++ b/pkg/repo/types.go @@ -70,6 +70,7 @@ const ( // Repo describes a repository type Repo struct { + Name string `json:"name"` // Name of repository URL string `json:"url"` // URL to the root of this repository CredentialName string `json:"credentialname,omitempty"` // Credential name used to access this repository Format ERepoFormat `json:"format,omitempty"` // Format of this repository @@ -78,6 +79,8 @@ type Repo struct { // IRepo abstracts a repository. type IRepo interface { + // GetName returns the name of the repository + GetName() string // GetURL returns the URL to the root of this repository. GetURL() string // GetCredentialName returns the credential name used to access this repository.