vars

package
v0.0.0-...-493bf59 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = models.Command{
	Name:      "vars",
	ShortHelp: "Interaction with environment variables for an environment",
	LongHelp:  "The <code>vars</code> command allows you to manage environment variables for your code services. The vars command can not be run directly but has subcommands.",
	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: "<code>vars list</code> prints out all known environment variables for the given code service. " +
		"You can print out environment variables in JSON or YAML format through the <code>--json</code> or <code>--yaml</code> flags. " +
		"Here are some sample commands\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" vars list code-1\n" +
		"datica -E \"<your_env_name>\" vars list code-1 --json\n</pre>",
	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.")
			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(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, 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: "<code>vars set</code> 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 <code>-v</code> option multiple times. " +
		"Once new environment variables are added or values updated, a redeploy is required for the given code service to have access to the new values. " +
		"The environment variables must be of the form <code><key>=<value></code>. Here is a sample command\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" vars set code-1 -v AWS_ACCESS_KEY_ID=1234 -v AWS_SECRET_ACCESS_KEY=5678\n</pre>",
	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.")
			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,
			})
			fileName := subCmd.StringOpt("f file", "", "The path to a file to import environment variables from. This file can be in JSON, YAML, or KEY=VALUE format")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdSet(*serviceName, *variables, *fileName, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "SERVICE_NAME (-v... | -f)"
		}
	},
}
View Source
var UnsetSubCmd = models.Command{
	Name:      "unset",
	ShortHelp: "Unset (delete) an existing environment variable",
	LongHelp: "<code>vars unset</code> removes environment variables from the given code service. " +
		"Only the environment variable name is required to unset. " +
		"Once environment variables are unset, a redeploy is required for the given code service to realize the variable was removed. " +
		"You can unset any number of environment variables in one command. " +
		"Here is a sample command\n\n" +
		"<pre>\ndatica -E \"<your_env_name>\" vars unset code-1 AWS_ACCESS_KEY_ID AWS_SECRET_ACCES_KEY_ID\n</pre>",
	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.")
			variables := subCmd.Strings(cli.StringsArg{
				Name:      "VARIABLE",
				Value:     []string{},
				Desc:      "The names of environment variables to unset",
				HideValue: true,
			})
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdUnset(*serviceName, *variables, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "SERVICE_NAME VARIABLE..."
		}
	},
}

Functions

func CmdList

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

func CmdSet

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

func CmdUnset

func CmdUnset(svcName string, variables []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 `datica 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 `datica 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