Exemple #1
0
func CmdSet(path string, settings *models.Settings) error {
	fullPath, err := homedir.Expand(path)
	if err != nil {
		return err
	}

	// make sure both files exist
	_, err = os.Stat(fullPath + ".pub")
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("Public key file '%s' does not exist.", fullPath+".pub")
		}
		return err
	}

	_, err = os.Stat(fullPath)
	if err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("Private key file '%s' does not exist.", fullPath)
		}
		return err
	}

	settings.PrivateKeyPath = fullPath
	settings.SessionToken = ""
	a := auth.New(settings, prompts.New())
	user, err := a.Signin()
	if err != nil {
		return err
	}
	logrus.Printf("Successfully added key and signed in as %s.", user.Email)
	return nil
}
Exemple #2
0
// Cmd is the contract between the user and the CLI. This specifies the command
// name, arguments, and required/optional arguments and flags for the command.
var Cmd = models.Command{
	Name:      "rollback",
	ShortHelp: "Rollback a code service to a specific release",
	LongHelp: "`rollback` is a way to redeploy older versions of your code service. " +
		"You must specify the name of the service to rollback and the name of an existing release to rollback to. " +
		"Releases can be found with the [releases list](#releases-list) command. Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" rollback code-1 f93ced037f828dcaabccfc825e6d8d32cc5a1883\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			serviceName := cmd.StringArg("SERVICE_NAME", "", "The name of the service to rollback")
			releaseName := cmd.StringArg("RELEASE_NAME", "", "The name of the release to rollback to")
			cmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdRollback(*serviceName, *releaseName, jobs.New(settings), releases.New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			cmd.Spec = "SERVICE_NAME RELEASE_NAME"
		}
	},
}
Exemple #3
0
	"github.com/jault3/mow.cli"
)

// Cmd is the contract between the user and the CLI. This specifies the command
// name, arguments, and required/optional arguments and flags for the command.
var Cmd = models.Command{
	Name:      "logout",
	ShortHelp: "Clear the stored user information from your local machine",
	LongHelp: "When using the CLI, your username and password are **never** stored in any file on your filesystem. " +
		"However, in order to not type in your username and password each and every command, a session token is stored in the CLI's configuration file and used until it expires. " +
		"`logout` removes this session token from the configuration file. Here is a sample command\n\n" +
		"```\ncatalyze logout\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.Action = func() {
				err := CmdLogout(New(settings), auth.New(settings, prompts.New()))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
		}
	},
}

// ILogout
type ILogout interface {
	Clear() error
}

// SLogout is a concrete implementation of ILogout
type SLogout struct {
Exemple #4
0
}

var BackupSubCmd = models.Command{
	Name:      "backup",
	ShortHelp: "Create a new backup",
	LongHelp: "`db backup` creates a new backup for the given database service. " +
		"The backup is started and unless `-s` is specified, the CLI will poll every few seconds until it finishes. " +
		"Regardless of a successful backup or not, the logs for the backup will be printed to the console when the backup is finished. " +
		"If an error occurs and the logs are not printed, you can use the [db logs](#db-logs) command to print out historical backup job logs. Here is a sample command\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" db backup db01\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			databaseName := subCmd.StringArg("DATABASE_NAME", "", "The name of the database service to create a backup for (i.e. 'db01')")
			skipPoll := subCmd.BoolOpt("s skip-poll", false, "Whether or not to wait for the backup to finish")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdBackup(*databaseName, *skipPoll, New(settings, crypto.New(), jobs.New(settings)), services.New(settings), jobs.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "DATABASE_NAME [-s]"
		}
	},
}
Exemple #5
0
	LongHelp: "This command has been moved! Please use [worker deploy](#worker-deploy) instead. This alias will be removed in the next CLI update.\n\n" +
		"The `worker` commands allow you to manage your environment variables per service. " +
		"The `worker` command cannot be run directly, but has subcommands.",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.CommandLong(DeploySubCmd.Name, DeploySubCmd.ShortHelp, DeploySubCmd.LongHelp, DeploySubCmd.CmdFunc(settings))
			cmd.CommandLong(ListSubCmd.Name, ListSubCmd.ShortHelp, ListSubCmd.LongHelp, ListSubCmd.CmdFunc(settings))
			cmd.CommandLong(RmSubCmd.Name, RmSubCmd.ShortHelp, RmSubCmd.LongHelp, RmSubCmd.CmdFunc(settings))
			cmd.CommandLong(ScaleSubCmd.Name, ScaleSubCmd.ShortHelp, ScaleSubCmd.LongHelp, ScaleSubCmd.CmdFunc(settings))

			serviceName := cmd.StringArg("SERVICE_NAME", "", "The name of the service to use to start a worker. Defaults to the associated service.")
			target := cmd.StringArg("TARGET", "", "The name of the Procfile target to invoke as a worker")
			cmd.Action = func() {
				logrus.Warnln("This command has been moved! Please use \"catalyze worker deploy\" instead. This alias will be removed in the next CLI update.")
				logrus.Warnln("You can list all available worker subcommands by running \"catalyze worker --help\".")
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				if *target == "" {
					logrus.Fatal("TARGET is a required argument")
				}
				err := CmdWorker(*serviceName, settings.ServiceID, *target, New(settings), services.New(settings), jobs.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			cmd.Spec = "[SERVICE_NAME] [TARGET]"
		}
Exemple #6
0
		"If you do not see your logs, try adjusting the number of hours, minutes, or seconds of logs that are retrieved with the `--hours`, `--minutes`, and `--seconds` options respectively. " +
		"You can also follow the logs with the `-f` option. " +
		"When using `-f` all logs will be printed to the console within the given time frame as well as any new logs that are sent to the logging Dashboard for the duration of the command. " +
		"When using the `-f` option, hit ctrl-c to stop. Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" logs --hours=6 --minutes=30\n" +
		"catalyze -E \"<your_env_alias>\" logs -f\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			query := cmd.StringArg("QUERY", "*", "The query to send to your logging dashboard's elastic search (regex is supported)")
			follow := cmd.BoolOpt("f follow", false, "Tail/follow the logs (Equivalent to -t)")
			tail := cmd.BoolOpt("t tail", false, "Tail/follow the logs (Equivalent to -f)")
			hours := cmd.IntOpt("hours", 0, "The number of hours before now (in combination with minutes and seconds) to retrieve logs")
			mins := cmd.IntOpt("minutes", 0, "The number of minutes before now (in combination with hours and seconds) to retrieve logs")
			secs := cmd.IntOpt("seconds", 0, "The number of seconds before now (in combination with hours and minutes) to retrieve logs")
			cmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdLogs(*query, *follow || *tail, *hours, *mins, *secs, settings.EnvironmentID, settings, New(settings), prompts.New(), environments.New(settings), services.New(settings), sites.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			cmd.Spec = "[QUERY] [(-f | -t)] [--hours] [--minutes] [--seconds]"
		}
	},
}
Exemple #7
0
		}
	},
}

var AcceptSubCmd = models.Command{
	Name:      "accept",
	ShortHelp: "Accept an organization invite",
	LongHelp: "`invites accept` is an alternative form of accepting an invitation sent by email. " +
		"The invitation email you receive will have instructions as well as the invite code to use with this command. " +
		"Here is a sample command\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" invites accept 5a206aa8-04f4-4bc1-a017-ede7e6c7dbe2\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			inviteCode := subCmd.StringArg("INVITE_CODE", "", "The invite code that was sent in the invite email")
			subCmd.Action = func() {
				p := prompts.New()
				a := auth.New(settings, p)
				if _, err := a.Signin(); err != nil {
					logrus.Fatal(err.Error())
				}

				err := CmdAccept(*inviteCode, New(settings), a, p)
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "INVITE_CODE"
		}
	},
}
Exemple #8
0
// Cmd is the contract between the user and the CLI. This specifies the command
// name, arguments, and required/optional arguments and flags for the command.
var Cmd = models.Command{
	Name:      "services",
	ShortHelp: "Perform operations on an environment's services",
	LongHelp:  "The `services` command allows you to manage your services. The services command cannot be run directly but has sub commands.",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.CommandLong(ListSubCmd.Name, ListSubCmd.ShortHelp, ListSubCmd.LongHelp, ListSubCmd.CmdFunc(settings))
			cmd.CommandLong(StopSubCmd.Name, StopSubCmd.ShortHelp, StopSubCmd.LongHelp, StopSubCmd.CmdFunc(settings))
			cmd.CommandLong(RenameSubCmd.Name, RenameSubCmd.ShortHelp, RenameSubCmd.LongHelp, RenameSubCmd.CmdFunc(settings))
			cmd.Action = func() {
				logrus.Warnln("This command has been moved! Please use \"catalyze services list\" instead. This alias will be removed in the next CLI update.")
				logrus.Warnln("You can list all available services subcommands by running \"catalyze services --help\".")
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdServices(New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
		}
	},
}

var ListSubCmd = models.Command{