From 899dc0b225869223de4d1913a95e5c9ff480f9eb Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 17 Mar 2016 16:37:35 -0600 Subject: [PATCH 1/4] feat(repo): hook up `helm repo list` cmd --- cmd/helm/helm.go | 26 ++++++++++++++++++++++++++ cmd/helm/repository.go | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index c7a02585d..b355b0c86 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -17,7 +17,11 @@ limitations under the License. package main import ( + "io/ioutil" + "net/http" + "net/url" "os" + "strings" "github.com/codegangsta/cli" "github.com/kubernetes/helm/pkg/client" @@ -84,3 +88,25 @@ func NewClient(c *cli.Context) *client.Client { timeout := c.GlobalInt("timeout") return client.NewClient(host).SetDebug(debug).SetTimeout(timeout) } + +func callService(path, method, description string) ([]byte, error) { + dmURL := "http://localhost:8080" + //dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" + var URL *url.URL + URL, err := url.Parse(dmURL) + if err != nil { + return nil, err + } + URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(path, "/") + resp, err := http.Get(URL.Path) //TODO: change later + if err != nil { + return nil, err + } + + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return body, nil +} diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 8cd52273d..7863cd05f 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -91,6 +91,12 @@ func addRepo(c *cli.Context) error { } func listRepos(c *cli.Context) error { + path := "chart_repositories" + body, err := callService(path, "GET", "list chart repos") + if err != nil { + return err + } + format.Msg(string(body)) return nil } From 17143feb878f35c68f1db79bfa37b420ba38df75 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 17 Mar 2016 16:47:01 -0600 Subject: [PATCH 2/4] ref(helm): clean up callService --- cmd/helm/helm.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index b355b0c86..2f09be067 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -91,14 +91,17 @@ func NewClient(c *cli.Context) *client.Client { func callService(path, method, description string) ([]byte, error) { dmURL := "http://localhost:8080" - //dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" - var URL *url.URL - URL, err := url.Parse(dmURL) + //TODO: dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" + client := &http.Client{} + url, err := formatPath(dmURL, path) + req, err := http.NewRequest(method, url.Path, nil) + if err != nil { + return nil, err + } + resp, err := client.Do(req) if err != nil { return nil, err } - URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(path, "/") - resp, err := http.Get(URL.Path) //TODO: change later if err != nil { return nil, err } @@ -110,3 +113,13 @@ func callService(path, method, description string) ([]byte, error) { } return body, nil } + +func formatPath(rawURL, route string) (*url.URL, error) { + var URL *url.URL + URL, err := url.Parse(rawURL) + if err != nil { + return nil, err + } + URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(route, "/") + return URL, nil +} From 10153528a0546d0d3cfef585524b3866fbf619b9 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 17 Mar 2016 17:19:03 -0600 Subject: [PATCH 3/4] feat(repos): hook up helm repo add cmd * use pkg/httputil instead of func in helm client --- cmd/helm/helm.go | 35 ----------------------------------- cmd/helm/repository.go | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 2f09be067..eaad0b2c3 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -88,38 +88,3 @@ func NewClient(c *cli.Context) *client.Client { timeout := c.GlobalInt("timeout") return client.NewClient(host).SetDebug(debug).SetTimeout(timeout) } - -func callService(path, method, description string) ([]byte, error) { - dmURL := "http://localhost:8080" - //TODO: dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" - client := &http.Client{} - url, err := formatPath(dmURL, path) - req, err := http.NewRequest(method, url.Path, nil) - if err != nil { - return nil, err - } - resp, err := client.Do(req) - if err != nil { - return nil, err - } - if err != nil { - return nil, err - } - - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - return body, nil -} - -func formatPath(rawURL, route string) (*url.URL, error) { - var URL *url.URL - URL, err := url.Parse(rawURL) - if err != nil { - return nil, err - } - URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(route, "/") - return URL, nil -} diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 7863cd05f..69f3ac29d 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -19,6 +19,7 @@ package main import ( "errors" "github.com/codegangsta/cli" + "github.com/kubernetes/helm/pkg/client" "github.com/kubernetes/helm/pkg/format" "os" ) @@ -87,16 +88,29 @@ func addRepo(c *cli.Context) error { if len(args) < 1 { return errors.New("'helm repo add' requires a repository as an argument") } + + dmURL := "http://localhost:8080" + path := "chart_repositories" + client := client.NewClient(dmURL) + var dest string = "" + err := client.CallService(path, "POST", "add a chart repository", &dest, nil) + if err != nil { + return err + } + format.Msg(dest) return nil } func listRepos(c *cli.Context) error { + dmURL := "http://localhost:8080" path := "chart_repositories" - body, err := callService(path, "GET", "list chart repos") + client := client.NewClient(dmURL) + var dest string = "" + err := client.CallService(path, "GET", "list chart repos", &dest, nil) if err != nil { return err } - format.Msg(string(body)) + format.Msg(dest) return nil } From cb41b2090954fbacc572407c5c500f16d74a0f96 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 17 Mar 2016 17:25:15 -0600 Subject: [PATCH 4/4] feat(repo): hook up helm repo remove cmd --- cmd/helm/helm.go | 4 ---- cmd/helm/repository.go | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index eaad0b2c3..c7a02585d 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -17,11 +17,7 @@ limitations under the License. package main import ( - "io/ioutil" - "net/http" - "net/url" "os" - "strings" "github.com/codegangsta/cli" "github.com/kubernetes/helm/pkg/client" diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 69f3ac29d..56420dd1f 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -28,6 +28,9 @@ func init() { addCommands(repoCommands()) } +var dmURL string = "http://localhost:8080" +var chartRepoPath string = "chart_repositories" + func repoCommands() cli.Command { return cli.Command{ Name: "repository", @@ -89,11 +92,9 @@ func addRepo(c *cli.Context) error { return errors.New("'helm repo add' requires a repository as an argument") } - dmURL := "http://localhost:8080" - path := "chart_repositories" client := client.NewClient(dmURL) var dest string = "" - err := client.CallService(path, "POST", "add a chart repository", &dest, nil) + err := client.CallService(chartRepoPath, "POST", "add a chart repository", &dest, nil) if err != nil { return err } @@ -102,11 +103,9 @@ func addRepo(c *cli.Context) error { } func listRepos(c *cli.Context) error { - dmURL := "http://localhost:8080" - path := "chart_repositories" client := client.NewClient(dmURL) var dest string = "" - err := client.CallService(path, "GET", "list chart repos", &dest, nil) + err := client.CallService(chartRepoPath, "GET", "list chart repos", &dest, nil) if err != nil { return err } @@ -119,5 +118,12 @@ func removeRepo(c *cli.Context) error { if len(args) < 1 { return errors.New("'helm repo remove' requires a repository as an argument") } + client := client.NewClient(dmURL) + var dest string = "" + err := client.CallService(chartRepoPath, "DELETE", "delete a chart repository from list", &dest, nil) + if err != nil { + return err + } + format.Msg(dest) return nil }