feat(repos): hook up helm repo add cmd

* use pkg/httputil instead of func in helm client
pull/404/head
Michelle Noorali 9 years ago
parent 17143feb87
commit 10153528a0

@ -88,38 +88,3 @@ func NewClient(c *cli.Context) *client.Client {
timeout := c.GlobalInt("timeout") timeout := c.GlobalInt("timeout")
return client.NewClient(host).SetDebug(debug).SetTimeout(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
}

@ -19,6 +19,7 @@ package main
import ( import (
"errors" "errors"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/kubernetes/helm/pkg/client"
"github.com/kubernetes/helm/pkg/format" "github.com/kubernetes/helm/pkg/format"
"os" "os"
) )
@ -87,16 +88,29 @@ func addRepo(c *cli.Context) error {
if len(args) < 1 { if len(args) < 1 {
return errors.New("'helm repo add' requires a repository as an argument") 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 return nil
} }
func listRepos(c *cli.Context) error { func listRepos(c *cli.Context) error {
dmURL := "http://localhost:8080"
path := "chart_repositories" 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 { if err != nil {
return err return err
} }
format.Msg(string(body)) format.Msg(dest)
return nil return nil
} }

Loading…
Cancel
Save