示例#1
0
文件: auth.go 项目: CodeJuan/deis
// 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
}
示例#2
0
文件: releases.go 项目: CodeJuan/deis
// 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
}
示例#3
0
文件: apps.go 项目: CodeJuan/deis
// 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
}
示例#4
0
文件: ps.go 项目: smt116/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
}
示例#5
0
文件: builds.go 项目: CodeJuan/deis
// 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
}
示例#6
0
文件: auth.go 项目: CodeJuan/deis
// 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
}
示例#7
0
文件: ps.go 项目: smt116/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
}
示例#8
0
文件: apps.go 项目: CodeJuan/deis
// Transfer an app to another user.
func Transfer(c *client.Client, appID string, username string) error {
	u := fmt.Sprintf("/v1/apps/%s/", appID)

	req := api.AppUpdateRequest{Owner: username}
	body, err := json.Marshal(req)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", u, body)
	return err
}
示例#9
0
文件: keys.go 项目: CodeJuan/deis
// 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
}
示例#10
0
文件: certs.go 项目: CodeJuan/deis
// 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
}
示例#11
0
文件: users.go 项目: CodeJuan/deis
// 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
}
示例#12
0
文件: apps.go 项目: CodeJuan/deis
// 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
}
示例#13
0
文件: perms.go 项目: CodeJuan/deis
// 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
}
示例#14
0
文件: ps.go 项目: smt116/deis
// List an app's processes.
func List(c *client.Client, appID string, results int) (api.Processes, int, error) {
	u := fmt.Sprintf("/v1/apps/%s/containers/", appID)
	body, count, err := c.LimitedRequest(u, results)

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

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

	return procs, count, nil
}
示例#15
0
文件: domains.go 项目: CodeJuan/deis
// List domains registered with an app.
func List(c *client.Client, appID string, results int) ([]api.Domain, int, error) {
	u := fmt.Sprintf("/v1/apps/%s/domains/", appID)
	body, count, err := c.LimitedRequest(u, results)

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

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

	return domains, count, nil
}
示例#16
0
文件: apps.go 项目: CodeJuan/deis
// 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
}
示例#17
0
文件: builds.go 项目: CodeJuan/deis
// 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
}
示例#18
0
文件: releases.go 项目: CodeJuan/deis
// List lists an app's releases.
func List(c *client.Client, appID string, results int) ([]api.Release, int, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/", appID)

	body, count, err := c.LimitedRequest(u, results)

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

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

	return releases, count, nil
}
示例#19
0
文件: releases.go 项目: CodeJuan/deis
// Get a release of an app.
func Get(c *client.Client, appID string, version int) (api.Release, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/v%d/", appID, version)

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

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

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

	return release, nil
}
示例#20
0
文件: auth.go 项目: CodeJuan/deis
// Passwd changes a user's password.
func Passwd(c *client.Client, username, password, newPassword string) error {
	req := api.AuthPasswdRequest{Password: password, NewPassword: newPassword}

	if username != "" {
		req.Username = username
	}

	body, err := json.Marshal(req)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", "/v1/auth/passwd/", body)
	return err
}
示例#21
0
文件: config.go 项目: CodeJuan/deis
// List lists an app's config.
func List(c *client.Client, app string) (api.Config, error) {
	u := fmt.Sprintf("/v1/apps/%s/config/", app)

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

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

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

	return config, nil
}
示例#22
0
文件: auth.go 项目: CodeJuan/deis
// Delete deletes a user.
func Delete(c *client.Client, username string) error {
	var body []byte
	var err error

	if username != "" {
		req := api.AuthCancelRequest{Username: username}
		body, err = json.Marshal(req)

		if err != nil {
			return err
		}
	}

	_, err = c.BasicRequest("DELETE", "/v1/auth/cancel/", body)
	return err
}
示例#23
0
文件: keys.go 项目: CodeJuan/deis
// New creates a new key.
func New(c *client.Client, id string, pubKey string) (api.Key, error) {
	req := api.KeyCreateRequest{ID: id, Public: pubKey}
	body, err := json.Marshal(req)

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

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

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

	return key, nil
}
示例#24
0
文件: apps.go 项目: CodeJuan/deis
// Get app details from a Deis controller.
func Get(c *client.Client, appID string) (api.App, error) {
	u := fmt.Sprintf("/v1/apps/%s/", appID)

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

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

	app := api.App{}

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

	return app, nil
}
示例#25
0
文件: perms.go 项目: CodeJuan/deis
func doNew(c *client.Client, u string, username string) error {
	req := api.PermsRequest{Username: username}

	reqBody, err := json.Marshal(req)

	if err != nil {
		return err
	}

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

	if err != nil {
		return err
	}

	return nil
}
示例#26
0
文件: auth.go 项目: robeferre/deis
func doLogin(c *client.Client, username, password string) error {
	token, err := auth.Login(c, username, password)

	if err != nil {
		return err
	}

	c.Token = token
	c.Username = username

	err = c.Save()

	if err != nil {
		return nil
	}

	fmt.Printf("Logged in as %s\n", username)
	return nil
}
示例#27
0
文件: perms.go 项目: CodeJuan/deis
// ListAdmins lists administrators.
func ListAdmins(c *client.Client, results int) ([]string, int, error) {
	body, count, err := c.LimitedRequest("/v1/admin/perms/", results)

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

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

	usersList := []string{}

	for _, user := range users {
		usersList = append(usersList, user.Username)
	}

	return usersList, count, nil
}
示例#28
0
文件: auth.go 项目: CodeJuan/deis
// Login to the controller and get a token
func Login(c *client.Client, username, password string) (string, error) {
	user := api.AuthLoginRequest{Username: username, Password: password}
	reqBody, err := json.Marshal(user)

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

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

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

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

	return token.Token, nil
}
示例#29
0
文件: certs.go 项目: CodeJuan/deis
// 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, err := c.BasicRequest("POST", "/v1/certs/", reqBody)

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

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

	return resCert, nil
}
示例#30
0
文件: config.go 项目: CodeJuan/deis
// 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, err := c.BasicRequest("POST", u, body)

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

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

	return newConfig, nil
}