Example #1
0
// New adds a domain to an app.
func New(c *client.Client, appID string, domain string) (api.Domain, error) {
	u := fmt.Sprintf("/v1/apps/%s/domains/", appID)

	req := api.DomainCreateRequest{Domain: domain}

	body, err := json.Marshal(req)

	if err != nil {
		return api.Domain{}, err
	}

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Domain{}, err
	}

	if status != 201 {
		return api.Domain{}, errors.New(resBody)
	}

	res := api.Domain{}
	if err = json.Unmarshal([]byte(resBody), &res); err != nil {
		return api.Domain{}, err
	}

	return res, nil
}
Example #2
0
// New creates a build for an app.
func New(c *client.Client, appID string, image string,
	procfile map[string]string) (api.Build, error) {

	u := fmt.Sprintf("/v1/apps/%s/builds/", appID)

	req := api.CreateBuildRequest{Image: image, Procfile: procfile}

	body, err := json.Marshal(req)

	if err != nil {
		return api.Build{}, err
	}

	resBody, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Build{}, err
	}

	build := api.Build{}
	if err = json.Unmarshal([]byte(resBody), &build); err != nil {
		return api.Build{}, err
	}

	return build, nil
}
Example #3
0
// Rollback rolls back an app to a previous release.
func Rollback(c *client.Client, appID string, version int) (int, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/rollback/", appID)

	req := api.ReleaseRollback{Version: version}

	var err error
	var reqBody []byte
	if version != -1 {
		reqBody, err = json.Marshal(req)

		if err != nil {
			return -1, err
		}
	}

	body, err := c.BasicRequest("POST", u, reqBody)

	if err != nil {
		return -1, err
	}

	response := api.ReleaseRollback{}

	if err = json.Unmarshal([]byte(body), &response); err != nil {
		return -1, err
	}

	return response.Version, nil
}
Example #4
0
// Set sets an app's config variables.
func Set(c *client.Client, app string, config api.Config) (api.Config, error) {
	body, err := json.Marshal(config)

	if err != nil {
		return api.Config{}, err
	}

	u := fmt.Sprintf("/v1/apps/%s/config/", app)

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.Config{}, err
	}

	if status != 201 {
		return api.Config{}, errors.New(resBody)
	}

	newConfig := api.Config{}
	if err = json.Unmarshal([]byte(resBody), &newConfig); err != nil {
		return api.Config{}, err
	}

	return newConfig, nil
}
Example #5
0
File: ps.go Project: laurrentt/deis
// Restart an app's processes.
func Restart(c *client.Client, appID string, procType string, num int) ([]api.Process, error) {
	u := fmt.Sprintf("/v1/apps/%s/containers/", appID)

	if procType == "" {
		u += "restart/"
	} else {
		if num == -1 {
			u += procType + "/restart/"
		} else {
			u += procType + "/" + strconv.Itoa(num) + "/restart/"
		}
	}

	body, err := c.BasicRequest("POST", u, nil)

	if err != nil {
		return []api.Process{}, err
	}

	procs := []api.Process{}
	if err = json.Unmarshal([]byte(body), &procs); err != nil {
		return []api.Process{}, err
	}

	return procs, nil
}
Example #6
0
// New creates a new cert.
func New(c *client.Client, cert string, key string, commonName string) (api.Cert, error) {
	req := api.CertCreateRequest{Certificate: cert, Key: key, Name: commonName}
	reqBody, err := json.Marshal(req)

	if err != nil {
		return api.Cert{}, err
	}

	resBody, status, err := c.BasicRequest("POST", "/v1/certs/", reqBody)

	if err != nil {
		return api.Cert{}, err
	}

	if status != 201 {
		return api.Cert{}, errors.New(resBody)
	}

	resCert := api.Cert{}
	if err = json.Unmarshal([]byte(resBody), &resCert); err != nil {
		return api.Cert{}, err
	}

	return resCert, nil
}
Example #7
0
// Regenerate user's auth tokens.
func Regenerate(c *client.Client, username string, all bool) (string, error) {
	var reqBody []byte
	var err error

	if all == true {
		reqBody, err = json.Marshal(api.AuthRegenerateRequest{All: all})
	} else if username != "" {
		reqBody, err = json.Marshal(api.AuthRegenerateRequest{Name: username})
	}

	if err != nil {
		return "", err
	}

	body, err := c.BasicRequest("POST", "/v1/auth/tokens/", reqBody)

	if err != nil {
		return "", err
	}

	if all == true {
		return "", nil
	}

	token := api.AuthRegenerateResponse{}
	if err = json.Unmarshal([]byte(body), &token); err != nil {
		return "", err
	}

	return token.Token, nil
}
Example #8
0
// New creates a new app.
func New(c *client.Client, id string) (api.App, error) {
	body := []byte{}

	var err error
	if id != "" {
		req := api.AppCreateRequest{ID: id}
		body, err = json.Marshal(req)

		if err != nil {
			return api.App{}, err
		}
	}

	resBody, err := c.BasicRequest("POST", "/v1/apps/", body)

	if err != nil {
		return api.App{}, err
	}

	app := api.App{}
	if err = json.Unmarshal([]byte(resBody), &app); err != nil {
		return api.App{}, err
	}

	return app, nil
}
Example #9
0
File: apps.go Project: Kazanz/deis
// Run one time command in an app.
func Run(c *client.Client, appID string, command string) (api.AppRunResponse, error) {
	req := api.AppRunRequest{Command: command}
	body, err := json.Marshal(req)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	u := fmt.Sprintf("/v1/apps/%s/run", appID)

	resBody, status, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	if status != 200 {
		return api.AppRunResponse{}, errors.New(resBody)
	}

	out := make([]interface{}, 2)

	if err = json.Unmarshal([]byte(resBody), &out); err != nil {
		return api.AppRunResponse{}, err
	}

	return api.AppRunResponse{Output: out[1].(string), ReturnCode: int(out[0].(float64))}, nil
}
Example #10
0
func doList(c *client.Client, u string) (string, error) {
	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	return body, nil
}
Example #11
0
// Register a new user with the controller.
func Register(c *client.Client, username, password, email string) error {
	user := api.AuthRegisterRequest{Username: username, Password: password, Email: email}
	body, err := json.Marshal(user)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", "/v1/auth/register/", body)
	return err
}
Example #12
0
File: ps.go Project: laurrentt/deis
// Scale an app's processes.
func Scale(c *client.Client, appID string, targets map[string]int) error {
	u := fmt.Sprintf("/v1/apps/%s/scale/", appID)

	body, err := json.Marshal(targets)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", u, body)
	return err
}
Example #13
0
func doDelete(c *client.Client, u string) error {
	body, status, err := c.BasicRequest("DELETE", u, nil)

	if err != nil {
		return err
	}

	if status != 204 {
		return errors.New(body)
	}

	return nil
}
Example #14
0
func doList(c *client.Client, u string) (string, error) {
	body, status, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	if status != 200 {
		return "", errors.New(body)
	}

	return body, nil
}
Example #15
0
// Delete removes a domain from an app.
func Delete(c *client.Client, appID string, domain string) error {
	u := fmt.Sprintf("/v1/apps/%s/domains/%s", appID, domain)
	body, status, err := c.BasicRequest("DELETE", u, nil)

	if err != nil {
		return err
	}

	if status != 204 {
		return errors.New(body)
	}

	return nil
}
Example #16
0
// List users registered with the controller.
func List(c *client.Client) ([]api.User, error) {
	body, err := c.BasicRequest("GET", "/v1/users/", nil)

	if err != nil {
		return []api.User{}, err
	}

	users := api.Users{}
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []api.User{}, err
	}

	return users.Users, nil
}
Example #17
0
// List users that can access an app.
func List(c *client.Client, appID string) ([]string, error) {
	body, err := c.BasicRequest("GET", fmt.Sprintf("/v1/apps/%s/perms/", appID), nil)

	if err != nil {
		return []string{}, err
	}

	var users api.PermsAppResponse
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []string{}, err
	}

	return users.Users, nil
}
Example #18
0
// List users registered with the controller.
func List(c *client.Client, results int) ([]api.User, int, error) {
	body, count, err := c.LimitedRequest("/v1/users/", results)

	if err != nil {
		return []api.User{}, -1, err
	}

	var users []api.User
	if err = json.Unmarshal([]byte(body), &users); err != nil {
		return []api.User{}, -1, err
	}

	return users, count, nil
}
Example #19
0
// List keys on a controller.
func List(c *client.Client) ([]api.Key, error) {
	body, err := c.BasicRequest("GET", "/v1/keys/", nil)

	if err != nil {
		return []api.Key{}, err
	}

	keys := api.Keys{}
	if err = json.Unmarshal([]byte(body), &keys); err != nil {
		return []api.Key{}, err
	}

	return keys.Keys, nil
}
Example #20
0
// List certs registered with the controller.
func List(c *client.Client) ([]api.Cert, error) {
	body, err := c.BasicRequest("GET", "/v1/certs/", nil)

	if err != nil {
		return []api.Cert{}, err
	}

	res := api.Certs{}
	if err = json.Unmarshal([]byte(body), &res); err != nil {
		return []api.Cert{}, err
	}

	return res.Certs, nil
}
Example #21
0
// List lists apps on a Deis controller.
func List(c *client.Client) ([]api.App, error) {
	body, err := c.BasicRequest("GET", "/v1/apps/", nil)

	if err != nil {
		return []api.App{}, err
	}

	apps := api.Apps{}
	if err = json.Unmarshal([]byte(body), &apps); err != nil {
		return []api.App{}, err
	}

	return apps.Apps, nil
}
Example #22
0
// List keys on a controller.
func List(c *client.Client, results int) ([]api.Key, int, error) {
	body, count, err := c.LimitedRequest("/v1/keys/", results)

	if err != nil {
		return []api.Key{}, -1, err
	}

	var keys []api.Key
	if err = json.Unmarshal([]byte(body), &keys); err != nil {
		return []api.Key{}, -1, err
	}

	return keys, count, nil
}
Example #23
0
// List certs registered with the controller.
func List(c *client.Client, results int) ([]api.Cert, int, error) {
	body, count, err := c.LimitedRequest("/v1/certs/", results)

	if err != nil {
		return []api.Cert{}, -1, err
	}

	var res []api.Cert
	if err = json.Unmarshal([]byte(body), &res); err != nil {
		return []api.Cert{}, -1, err
	}

	return res, count, nil
}
Example #24
0
// List lists apps on a Deis controller.
func List(c *client.Client, results int) ([]api.App, int, error) {
	body, count, err := c.LimitedRequest("/v1/apps/", results)

	if err != nil {
		return []api.App{}, -1, err
	}

	var apps []api.App
	if err = json.Unmarshal([]byte(body), &apps); err != nil {
		return []api.App{}, -1, err
	}

	return apps, count, nil
}
Example #25
0
// List domains registered with an app.
func List(c *client.Client, appID string) ([]api.Domain, error) {
	u := fmt.Sprintf("/v1/apps/%s/domains/", appID)
	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return []api.Domain{}, err
	}

	domains := api.Domains{}
	if err = json.Unmarshal([]byte(body), &domains); err != nil {
		return []api.Domain{}, err
	}

	return domains.Domains, nil
}
Example #26
0
// Logs retrieves logs from an app.
func Logs(c *client.Client, appID string, lines int) (string, error) {
	u := fmt.Sprintf("/v1/apps/%s/logs", appID)

	if lines > 0 {
		u += "?log_lines=" + strconv.Itoa(lines)
	}

	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	return strings.Trim(body, `"`), nil
}
Example #27
0
File: ps.go Project: laurrentt/deis
// List an app's processes.
func List(c *client.Client, appID string) ([]api.Process, error) {
	u := fmt.Sprintf("/v1/apps/%s/containers/", appID)
	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return []api.Process{}, err
	}

	procs := api.Processes{}
	if err = json.Unmarshal([]byte(body), &procs); err != nil {
		return []api.Process{}, err
	}

	return procs.Processes, nil
}
Example #28
0
// List lists an app's builds.
func List(c *client.Client, appID string, results int) ([]api.Build, int, error) {
	u := fmt.Sprintf("/v1/apps/%s/builds/", appID)
	body, count, err := c.LimitedRequest(u, results)

	if err != nil {
		return []api.Build{}, -1, err
	}

	var builds []api.Build
	if err = json.Unmarshal([]byte(body), &builds); err != nil {
		return []api.Build{}, -1, err
	}

	return builds, count, nil
}
Example #29
0
// Delete removes a cert.
func Delete(c *client.Client, commonName string) error {
	u := fmt.Sprintf("/v1/certs/%s", commonName)

	resBody, status, err := c.BasicRequest("DELETE", u, nil)

	if err != nil {
		return err
	}

	if status != 204 {
		return errors.New(resBody)
	}

	return nil
}
Example #30
0
// List lists an app's builds.
func List(c *client.Client, appID string) ([]api.Build, error) {
	u := fmt.Sprintf("/v1/apps/%s/builds/", appID)
	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return []api.Build{}, err
	}

	builds := api.Builds{}
	if err = json.Unmarshal([]byte(body), &builds); err != nil {
		return []api.Build{}, err
	}

	return builds.Builds, nil
}