Пример #1
0
func Destroy(app, resourceID string) error {
	if app == "" {
		return errgo.New("no app defined")
	} else if resourceID == "" {
		return errgo.New("no addon ID defined")
	}

	addon, err := checkAddonExist(app, resourceID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status("Destroy", resourceID)
	io.Warning("This operation is irreversible")
	io.Warning("All related data will be destroyed")
	io.Info("To confirm, type the ID of the addon:")
	fmt.Print("-----> ")

	var validationName string
	fmt.Scan(&validationName)

	if validationName != resourceID {
		return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, resourceID)
	}

	err = api.AddonDestroy(app, addon.ID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status("Addon", resourceID, "has been destroyed")
	return nil
}
Пример #2
0
func Provision(app, addon, plan string) error {
	if app == "" {
		return errgo.New("no app defined")
	} else if addon == "" {
		return errgo.New("no addon defined")
	} else if plan == "" {
		return errgo.New("no plan defined")
	}

	planID, err := checkPlanExist(addon, plan)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	params, err := scalingo.AddonProvision(app, addon, planID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status("Addon", addon, "has been provisionned")
	io.Info("ID:", params.Addon.ResourceID)
	if len(params.Variables) > 0 {
		io.Info("Modified variables:", params.Variables)
	}
	if len(params.Message) > 0 {
		io.Info("Message from addon provider:", params.Message)
	}
	return nil
}
Пример #3
0
func Destroy(appName string) error {
	var validationName string

	_, err := scalingo.AppsShow(appName)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
	validationName, err = bufio.NewReader(os.Stdin).ReadString('\n')
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}
	if validationName != appName {
		return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
	}

	res, err := scalingo.AppsDestroy(appName, validationName)
	if err != nil {
		return errgo.Notef(err, "fail to destroy app")
	}
	defer res.Body.Close()

	io.Status("App " + appName + " has been deleted")
	return nil
}
Пример #4
0
func Upgrade(app, resourceID, plan string) error {
	if app == "" {
		return errgo.New("no app defined")
	} else if resourceID == "" {
		return errgo.New("no addon ID defined")
	} else if plan == "" {
		return errgo.New("no plan defined")
	}

	addon, err := checkAddonExist(app, resourceID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	planID, err := checkPlanExist(addon.AddonProvider.Name, plan)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	params, err := api.AddonUpgrade(app, addon.ID, planID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status("Addon", resourceID, "has been upgraded")
	if len(params.Variables) > 0 {
		io.Info("Modified variables:", params.Variables)
	}
	if len(params.Message) > 0 {
		io.Info("Message from addon provider:", params.Message)
	}
	return nil
}
Пример #5
0
Файл: add.go Проект: Zyko0/cli
func Add(app, email string) error {
	collaborator, err := scalingo.CollaboratorAdd(app, email)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status(collaborator.Email, "has been invited to collaborate to", app)
	return nil
}
Пример #6
0
Файл: ssl.go Проект: yannski/cli
func DisableSSL(app string, domain string) error {
	d, err := findDomain(app, domain)
	if err != nil {
		return errgo.Mask(err)
	}

	_, err = api.DomainsUpdate(app, d.ID, "", "")
	if err != nil {
		return errgo.Mask(err)
	}
	io.Status("SSL of " + domain + " has been disabled.")
	return nil
}
Пример #7
0
func Remove(app string, domain string) error {
	d, err := findDomain(app, domain)
	if err != nil {
		return errgo.Mask(err)
	}

	err = api.DomainsRemove(app, d.ID)
	if err != nil {
		return errgo.Mask(err)
	}

	io.Status("The domain", d.Name, "has been deleted")
	return nil
}
Пример #8
0
func DisableSSL(app string, domain string) error {
	d, err := findDomain(app, domain)
	if err != nil {
		return errgo.Mask(err)
	}

	c := config.ScalingoClient()
	_, err = c.DomainsUpdate(app, d.ID, "", "")
	if err != nil {
		return errgo.Mask(err)
	}
	io.Status("SSL of " + domain + " has been disabled.")
	return nil
}
Пример #9
0
func Remove(app string, domain string) error {
	d, err := findDomain(app, domain)
	if err != nil {
		return errgo.Mask(err)
	}

	c := config.ScalingoClient()
	err = c.DomainsRemove(app, d.ID)
	if err != nil {
		return errgo.Mask(err)
	}

	io.Status("The domain", d.Name, "has been deleted")
	return nil
}
Пример #10
0
func Login() error {
	user, err := api.AuthFromConfig()
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}
	if user == nil {
		fmt.Println("You need to be authenticated to use Scalingo client.\nNo account ? → https://my.scalingo.com/users/signup")
		user, err = api.Auth()
		if err != nil {
			return errgo.Mask(err, errgo.Any)
		}
	} else {
		io.Status("You are already identified as", user.Username, "<"+user.Email+">")
	}
	return nil
}
Пример #11
0
func Destroy(appName string) error {
	var validationName string
	fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
	fmt.Scan(&validationName)
	if validationName != appName {
		return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
	}

	res, err := api.AppsDestroy(appName, validationName)
	if err != nil {
		return errgo.Notef(err, "fail to destroy app")
	}
	defer res.Body.Close()

	io.Status("App " + appName + " has been deleted")
	return nil
}
Пример #12
0
Файл: ssl.go Проект: yannski/cli
func EnableSSL(app, domain, certPath, keyPath string) error {
	d, err := findDomain(app, domain)
	if err != nil {
		return errgo.Mask(err)
	}

	certContent, keyContent, err := validateSSL(certPath, keyPath)
	if err != nil {
		return errgo.Mask(err)
	}

	d, err = api.DomainsUpdate(app, d.ID, certContent, keyContent)
	if err != nil {
		return errgo.Mask(err)
	}

	io.Status("The certificate and key have been installed for " + d.Name + " (Validity: " + d.Validity.UTC().String() + ")")
	return nil
}
Пример #13
0
func Remove(app, email string) error {
	collaborator, err := getFromEmail(app, email)
	if err != nil {
		if err == notFound {
			io.Error(email + " is not a collaborator of " + app + ".")
			return nil
		} else {
			return errgo.Mask(err, errgo.Any)
		}
	}

	err = scalingo.CollaboratorRemove(app, collaborator.ID)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status(email, "has been removed from the collaborators of", app)
	return nil
}
Пример #14
0
Файл: add.go Проект: Zyko0/cli
func Add(app string, domain string, cert string, key string) error {
	certContent, keyContent, err := validateSSL(cert, key)
	if err != nil {
		return errgo.Mask(err)
	}

	d, err := scalingo.DomainsAdd(app, scalingo.Domain{
		Name:    domain,
		TlsCert: certContent,
		TlsKey:  keyContent,
	})

	if err != nil {
		return errgo.Mask(err)
	}

	io.Status("Domain", d.Name, "has been created, access your app at the following URL:\n")
	io.Info("http://" + d.Name)
	return nil
}
Пример #15
0
func Provision(app, webHookURL string) error {
	if app == "" {
		return errgo.New("no app defined")
	} else if webHookURL == "" {
		return errgo.New("no url defined")
	}

	c := config.ScalingoClient()
	params, err := c.NotificationProvision(app, webHookURL)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	io.Status("Notifications to", webHookURL, "have been provisionned")
	if len(params.Variables) > 0 {
		io.Info("Modified variables:", params.Variables)
	}
	if len(params.Message) > 0 {
		io.Info("Message from notification provider:", params.Message)
	}
	return nil
}