Commit 9cc3688e authored by Matt Butcher's avatar Matt Butcher

feat(*): add DM client, fix makefile

parent 69e62568
......@@ -4,8 +4,8 @@ endif
BIN_DIR := bin
DIST_DIR := _dist
GO_PACKAGES := action chart config dependency log manifest release plugins/sec plugins/example codec
MAIN_GO := helm.go
GO_PACKAGES := cmd dm
MAIN_GO := cmd/helm.go
HELM_BIN := $(BIN_DIR)/helm
PATH_WITH_HELM = PATH="$(shell pwd)/$(BIN_DIR):$(PATH)"
......@@ -18,7 +18,7 @@ ifndef VERSION
endif
build: $(MAIN_GO)
go build -o $(HELM_BIN) -ldflags "-X github.com/helm/helm/cli.version=${VERSION}" $<
go build -o $(HELM_BIN) -ldflags "-X github.com/helm/helm/cmd.version=${VERSION}" $<
bootstrap:
go get -u github.com/golang/lint/golint github.com/mitchellh/gox
......@@ -54,7 +54,7 @@ else
endif
quicktest:
$(PATH_WITH_HELM) go test -short ./ $(addprefix ./,$(GO_PACKAGES))
$(PATH_WITH_HELM) go test -short $(addprefix ./,$(GO_PACKAGES))
test: test-style
$(PATH_WITH_HELM) go test -v ./ $(addprefix ./,$(GO_PACKAGES))
......
package dm
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
"github.com/ghodss/yaml"
)
var DefaultHTTPTimeout time.Duration
type Client struct {
// Timeout on HTTP connections.
HTTPTimeout time.Duration
// The remote host
Host string
// The protocol. Currently only http and https are supported.
Protocol string
}
func NewClient(host string) *Client {
return &Client{
HTTPTimeout: DefaultHTTPTimeout,
Protocol: "https",
Host: host,
}
}
func (c *Client) url(path string) string {
// TODO: Switch to net.URL
return c.Protocol + "://" + c.Host + "/" + path
}
// CallService is a low-level function for making an API call.
func (c *Client) CallService(path, method, action string, reader io.ReadCloser) {
u := c.url(path)
resp := c.callHttp(u, method, action, reader)
var j interface{}
if err := json.Unmarshal([]byte(resp), &j); err != nil {
panic(fmt.Errorf("Failed to parse JSON response from service: %s", resp))
}
y, err := yaml.Marshal(j)
if err != nil {
panic(fmt.Errorf("Failed to serialize JSON response from service: %s", resp))
}
fmt.Println(string(y))
}
func (c *Client) callHttp(path, method, action string, reader io.ReadCloser) string {
request, err := http.NewRequest(method, path, reader)
request.Header.Add("Content-Type", "application/json")
client := http.Client{
Timeout: time.Duration(time.Duration(DefaultHTTPTimeout) * time.Second),
}
response, err := client.Do(request)
if err != nil {
panic(fmt.Errorf("cannot %s: %s\n", action, err))
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(fmt.Errorf("cannot %s: %s\n", action, err))
}
if response.StatusCode < http.StatusOK ||
response.StatusCode >= http.StatusMultipleChoices {
message := fmt.Sprintf("status code: %d status: %s : %s", response.StatusCode, response.Status, body)
panic(fmt.Errorf("cannot %s: %s\n", action, message))
}
return string(body)
}
hash: 2f47b12bf634894e182800b5565efd124c6defff6291b60408cbba6a038778ae
updated: 2016-01-06T13:51:49.954407735-08:00
hash: 4cc1aba06a344d43c0c1005d71dc0659ada5d90f0b2235b1d8e8c7352d1251a7
updated: 2016-01-06T14:30:55.041267875-08:00
imports:
- name: github.com/codegangsta/cli
version: c31a7975863e7810c92e2e288a9ab074f9a88f29
- name: github.com/emicklei/go-restful
version: ce94a9f819d7dd2b5599ff0c017b1124595a64fb
- name: github.com/ghodss/yaml
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
- name: github.com/golang/glog
version: fca8c8854093a154ff1eb580aae10276ad6b1b5f
- name: github.com/golang/protobuf
version: 2402d76f3d41f928c7902a765dfc872356dd3aad
- name: github.com/google/go-github
version: 63fbbb283ce4913a5ac1b6de7abae50dbf594a04
- name: github.com/google/go-querystring
version: 2a60fc2ba6c19de80291203597d752e9ba58e4c0
- name: github.com/gorilla/context
version: 1c83b3eabd45b6d76072b66b746c20815fb2872d
- name: github.com/gorilla/handlers
version: 1af6d56d7cd39d982856bc0cee11142baf392c52
- name: github.com/gorilla/mux
version: 26a6070f849969ba72b72256e9f14cf519751690
- name: github.com/gorilla/schema
version: 14c555599c2a4f493c1e13fd1ea6fdf721739028
- name: github.com/kubernetes/deployment-manager
version: 62f19486073edd020a11922304130f0c5c1dff20
subpackages:
- /common
- name: github.com/mjibson/appstats
version: 0542d5f0e87ea3a8fa4174322b9532f5d04f9fa8
- name: golang.org/x/crypto
version: 552e9d568fde9701ea1944fb01c8aadaceaa7353
- name: golang.org/x/net
version: 1ade16a5450925b7496e1031938175d1f5d30d31
- name: golang.org/x/oauth2
version: 2baa8a1b9338cf13d9eeb27696d761155fa480be
- name: golang.org/x/text
version: cf4986612c83df6c55578ba198316d1684a9a287
- name: google.golang.com/appengine
version: ""
repo: https://google.golang.com/appengine
- name: google.golang.org/api
version: f5b7ec483f357a211c03c6722a840444c2d395dc
- name: google.golang.org/appengine
version: 54bf9150c922186bfc45a00bf9dfcb91a5063275
- name: google.golang.org/cloud
version: 1bff51b8fae8d33cb3dab8f7858c266ce001ee3e
- name: google.golang.org/grpc
version: 78905999da08d7f87d5dd11608fa79ff8700daa8
- name: gopkg.in/yaml.v2
version: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4
devImports: []
package: github.com/engineyard/helm-dm
import:
- package: github.com/codegangsta/cli
- package: github.com/kubernetes/deployment-manager
subpackages:
- /common
- package: github.com/ghodss/yaml
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