Beispiel #1
0
// SetEnvVars adds new env vars or updates the values of existing ones
func SetEnvVars(envVars map[string]string, settings *models.Settings) {
	b, err := json.Marshal(envVars)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/env", settings.PaasHost, settings.EnvironmentID, settings.ServiceID), true, settings)
}
Beispiel #2
0
// RedeployService redeploys the associated code service
func RedeployService(settings *models.Settings) {
	redeploy := map[string]string{}
	b, err := json.Marshal(redeploy)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/redeploy", settings.PaasHost, settings.EnvironmentID, settings.ServiceID), true, settings)
}
Beispiel #3
0
// InitiateRakeTask kicks off a rake task for the associated code service. The
// logs for the rake task are viewable in the environments logging server.
func InitiateRakeTask(taskName string, settings *models.Settings) {
	rakeTask := map[string]string{}
	b, err := json.Marshal(rakeTask)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/rake/%s", settings.PaasHost, settings.EnvironmentID, settings.ServiceID, url.QueryEscape(taskName)), true, settings)
}
Beispiel #4
0
// AddUserToEnvironment grants a user access to the associated env
func AddUserToEnvironment(usersID string, settings *models.Settings) {
	body := map[string]string{}
	b, err := json.Marshal(body)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/users/%s", settings.PaasHost, settings.EnvironmentID, usersID), true, settings)
}
Beispiel #5
0
// InitiateWorker starts a background worker for the associated code service
// for the given Procfile target.
func InitiateWorker(target string, settings *models.Settings) {
	worker := map[string]string{
		"target": target,
	}
	b, err := json.Marshal(worker)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/background", settings.PaasHost, settings.EnvironmentID, settings.ServiceID), true, settings)
}
Beispiel #6
0
// CreateInvite invites a user by email to the associated environment. This user
// does not need to have a Dashboard account to send them an invite, but
// requires a Dashboard account to accept it.
func CreateInvite(email string, settings *models.Settings) *models.Invite {
	i := models.Invite{
		Email: email,
	}
	b, err := json.Marshal(i)
	if err != nil {
		panic(err)
	}
	resp := httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/invites", settings.PaasHost, settings.EnvironmentID), true, settings)
	var invite models.Invite
	json.Unmarshal(resp, &invite)
	return &invite
}
Beispiel #7
0
// CreateBackup kicks off a backup job for the given service. The task is
// returned which can be used to check on the status of the backup.
func CreateBackup(serviceID string, settings *models.Settings) *models.Task {
	backup := map[string]string{
		"archiveType":    "cf",
		"encryptionType": "aes",
	}
	b, err := json.Marshal(backup)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	resp := httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/backup", settings.PaasHost, settings.EnvironmentID, serviceID), true, settings)
	var m map[string]string
	json.Unmarshal(resp, &m)
	return &models.Task{
		ID: m["taskId"],
	}
}
Beispiel #8
0
// RequestConsole asks for a console to be setup. The console is not immediately
// ready but the resulting taskID should be used to check on its status.
func RequestConsole(command string, serviceID string, settings *models.Settings) *models.Task {
	console := map[string]string{}
	if command != "" {
		console["command"] = command
	}
	b, err := json.Marshal(console)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	resp := httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/console", settings.PaasHost, settings.EnvironmentID, serviceID), true, settings)
	var m map[string]string
	json.Unmarshal(resp, &m)
	return &models.Task{
		ID: m["taskId"],
	}
}
Beispiel #9
0
// InitiateImport starts an import job for the given database service
func InitiateImport(tempURL string, filePath string, key string, iv string, options map[string]string, wipeFirst bool, serviceID string, settings *models.Settings) *models.Task {
	httpclient.PutFile(filePath, tempURL, true, settings)
	importParams := models.Import{
		Location:  tempURL,
		Key:       key,
		IV:        iv,
		WipeFirst: wipeFirst,
		Options:   options,
	}
	b, err := json.Marshal(importParams)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	resp := httpclient.Post(b, fmt.Sprintf("%s/v1/environments/%s/services/%s/db/import", settings.PaasHost, settings.EnvironmentID, serviceID), true, settings)
	var task models.Task
	json.Unmarshal(resp, &task)
	return &task
}
Beispiel #10
0
// SignIn signs in the user and retrieves a session. The passed in Settings
// object is updated with the most up to date credentials
func SignIn(settings *models.Settings) {
	// if we're already signed in with a valid session, don't sign in again
	if verify(settings) {
		return
	}
	if settings.Username == "" || settings.Password == "" {
		promptForCredentials(settings)
	}
	login := models.Login{
		Username: settings.Username,
		Password: settings.Password,
	}
	b, err := json.Marshal(login)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	resp := httpclient.Post(b, fmt.Sprintf("%s/v2/auth/signin", settings.BaasHost), true, settings)
	var user models.User
	json.Unmarshal(resp, &user)
	settings.SessionToken = user.SessionToken
	settings.UsersID = user.UsersID
	config.SaveSettings(settings)
}