Commit 0cdd0771 authored by Matt Butcher's avatar Matt Butcher

fix(*): minor codebase cleanups

Cleaned up some of the code we inherited from DM.
parent 1058fb9c
...@@ -29,7 +29,7 @@ func main() { ...@@ -29,7 +29,7 @@ func main() {
Name: "host,u", Name: "host,u",
Usage: "The URL of the DM server.", Usage: "The URL of the DM server.",
EnvVar: "HELM_HOST", EnvVar: "HELM_HOST",
Value: "https://localhost:8181/FIXME_NOT_RIGHT", Value: "https://localhost:8000/",
}, },
cli.IntFlag{ cli.IntFlag{
Name: "timeout", Name: "timeout",
......
...@@ -85,6 +85,10 @@ func (c *Client) url(rawurl string) (string, error) { ...@@ -85,6 +85,10 @@ func (c *Client) url(rawurl string) (string, error) {
return c.baseURL.ResolveReference(u).String(), nil return c.baseURL.ResolveReference(u).String(), nil
} }
func (c *Client) agent() string {
return fmt.Sprintf("helm/%s", "0.0.1")
}
// CallService is a low-level function for making an API call. // CallService is a low-level function for making an API call.
// //
// This calls the service and then unmarshals the returned data into dest. // This calls the service and then unmarshals the returned data into dest.
...@@ -109,29 +113,28 @@ func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (st ...@@ -109,29 +113,28 @@ func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (st
request, err := http.NewRequest(method, path, reader) request, err := http.NewRequest(method, path, reader)
// TODO: dynamically set version // TODO: dynamically set version
request.Header.Set("User-Agent", "helm/0.0.1") request.Header.Set("User-Agent", c.agent())
request.Header.Add("Content-Type", "application/json") request.Header.Add("Content-Type", "application/json")
client := http.Client{ client := &http.Client{
Timeout: time.Duration(time.Duration(DefaultHTTPTimeout) * time.Second), Timeout: c.HTTPTimeout,
Transport: c.transport(), Transport: c.transport(),
} }
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
return "", fmt.Errorf("cannot %s: %s\n", action, err) return "", err
} }
defer response.Body.Close() defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body) body, err := ioutil.ReadAll(response.Body)
if err != nil { if err != nil {
return "", fmt.Errorf("cannot %s: %s\n", action, err) return "", err
} }
if response.StatusCode < http.StatusOK || s := response.StatusCode
response.StatusCode >= http.StatusMultipleChoices { if s < http.StatusOK || s >= http.StatusMultipleChoices {
message := fmt.Sprintf("status code: %d status: %s : %s", response.StatusCode, response.Status, body) return "", fmt.Errorf("request '%s %s' failed with %d: %s\n", action, path, s, body)
return "", fmt.Errorf("cannot %s: %s\n", action, message)
} }
return string(body), nil return string(body), nil
...@@ -194,9 +197,10 @@ func (c *Client) DeployChart(filename, deployname string) error { ...@@ -194,9 +197,10 @@ func (c *Client) DeployChart(filename, deployname string) error {
request.Header.Add("Content-Encoding", "gzip") request.Header.Add("Content-Encoding", "gzip")
request.Header.Add("X-Deployment-Name", deployname) request.Header.Add("X-Deployment-Name", deployname)
request.Header.Add("X-Chart-Name", filepath.Base(filename)) request.Header.Add("X-Chart-Name", filepath.Base(filename))
request.Header.Set("User-Agent", c.agent())
client := http.Client{ client := &http.Client{
Timeout: time.Duration(time.Duration(DefaultHTTPTimeout) * time.Second), Timeout: c.HTTPTimeout,
Transport: c.transport(), Transport: c.transport(),
} }
......
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