vars

package
v2.0.0-snapshot...-58e3a78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = models.Command{
	Name:      "vars",
	ShortHelp: "Interaction with environment variables for the associated environment",
	LongHelp:  "The `vars` command allows you to manage environment variables for your code services. The vars command can not 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(SetSubCmd.Name, SetSubCmd.ShortHelp, SetSubCmd.LongHelp, SetSubCmd.CmdFunc(settings))
			cmd.CommandLong(UnsetSubCmd.Name, UnsetSubCmd.ShortHelp, UnsetSubCmd.LongHelp, UnsetSubCmd.CmdFunc(settings))
		}
	},
}

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.

View Source
var ListSubCmd = models.Command{
	Name:      "list",
	ShortHelp: "List all environment variables",
	LongHelp: "`vars list` prints out all known environment variables for the given code service. " +
		"You can print out environment variables in JSON or YAML format through the `--json` or `--yaml` flags. " +
		"Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" vars list code-1\n" +
		"catalyze -E \"<your_env_alias>\" vars list code-1 --json\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service containing the environment variables. Defaults to the associated service.")
			json := subCmd.BoolOpt("json", false, "Output environment variables in JSON format")
			yaml := subCmd.BoolOpt("yaml", false, "Output environment variables in YAML format")
			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())
				}
				var formatter Formatter
				if *json {
					formatter = &JSONFormatter{}
				} else if *yaml {
					formatter = &YAMLFormatter{}
				} else {
					formatter = &PlainFormatter{}
				}
				err := CmdList(*serviceName, settings.ServiceID, formatter, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [--json | --yaml]"
		}
	},
}
View Source
var SetSubCmd = models.Command{
	Name:      "set",
	ShortHelp: "Set one or more new environment variables or update the values of existing ones",
	LongHelp: "`vars set` allows you to add new environment variables or update the value of an existing environment variable on the given code service. " +
		"You can set/update 1 or more environment variables at a time with this command by repeating the `-v` option multiple times. " +
		"Once new environment variables are added or values updated, a [redeploy](#redeploy) is required for the given code service to have access to the new values. " +
		"The environment variables must be of the form `<key>=<value>`. Here is a sample command\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" vars set code-1 -v AWS_ACCESS_KEY_ID=1234 -v AWS_SECRET_ACCESS_KEY=5678\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service on which the environment variables will be set. Defaults to the associated service.")
			variables := subCmd.Strings(cli.StringsOpt{
				Name:      "v variable",
				Value:     []string{},
				Desc:      "The env variable to set or update in the form \"<key>=<value>\"",
				HideValue: true,
			})
			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 := CmdSet(*serviceName, settings.ServiceID, *variables, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] -v..."
		}
	},
}
View Source
var UnsetSubCmd = models.Command{
	Name:      "unset",
	ShortHelp: "Unset (delete) an existing environment variable",
	LongHelp: "`vars unset` removes an environment variables from the given code service. " +
		"Only the environment variable name is required to unset. " +
		"Once environment variables are unset, a [redeploy](#redeploy) is required for the given code service to realize the variable was removed. " +
		"Here is a sample command\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" vars unset code-1 AWS_ACCESS_KEY_ID\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service on which the environment variables will be unset. Defaults to the associated service.")
			variable := subCmd.StringArg("VARIABLE", "", "The name of the environment variable to unset")
			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 := CmdUnset(*serviceName, settings.ServiceID, *variable, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] VARIABLE"
		}
	},
}

Functions

func CmdList

func CmdList(svcName, defaultSvcID string, formatter Formatter, iv IVars, is services.IServices) error

func CmdSet

func CmdSet(svcName, defaultSvcID string, variables []string, iv IVars, is services.IServices) error

func CmdUnset

func CmdUnset(svcName, defaultSvcID, key string, iv IVars, is services.IServices) error

Types

type Formatter

type Formatter interface {
	Output(envVars map[string]string) error
}

type IVars

type IVars interface {
	List(svcID string) (map[string]string, error)
	Set(svcID string, envVarsMap map[string]string) error
	Unset(svcID, key string) error
}

IVars

func New

func New(settings *models.Settings) IVars

New generates a new instance of IVars

type JSONFormatter

type JSONFormatter struct{}

func (*JSONFormatter) Output

func (j *JSONFormatter) Output(envVars map[string]string) error

type PlainFormatter

type PlainFormatter struct{}

func (*PlainFormatter) Output

func (p *PlainFormatter) Output(envVars map[string]string) error

type SVars

type SVars struct {
	Settings *models.Settings
}

SVars is a concrete implementation of IVars

func (*SVars) List

func (v *SVars) List(svcID string) (map[string]string, error)

List lists all environment variables.

func (*SVars) Set

func (v *SVars) Set(svcID string, envVarsMap map[string]string) error

Set adds a new environment variables or updates the value of an existing environment variables. Any changes to environment variables will not take effect until the service is redeployed by pushing new code or via `catalyze redeploy`.

func (*SVars) Unset

func (v *SVars) Unset(svcID, variable string) error

Unset deletes an environment variable. Any changes to environment variables will not take effect until the service is redeployed by pushing new code or via `catalyze redeploy`.

type YAMLFormatter

type YAMLFormatter struct{}

func (*YAMLFormatter) Output

func (y *YAMLFormatter) Output(envVars map[string]string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL