Commit efe31779 authored by Michelle Noorali's avatar Michelle Noorali

feat(repo): add Name to Repo struct

* also added name as arg in helm repo add cmd
parent 0ccb8d75
......@@ -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
}
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
......
......@@ -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) {
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment