Merge "Define a standard for creating commands"
This commit is contained in:
@@ -20,23 +20,21 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
// NewConfigCommand creates a command object for the airshipctl "config" , and adds all child commands to it.
|
||||
// NewConfigCommand creates a command for interacting with the airshipctl configuration.
|
||||
func NewConfigCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
configRootCmd := &cobra.Command{
|
||||
Use: "config",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: "Modify airshipctl config files",
|
||||
Long: `Modify airshipctl config files using subcommands
|
||||
like "airshipctl config set-context my-context" `,
|
||||
Short: "Manage the airshipctl config file",
|
||||
}
|
||||
configRootCmd.AddCommand(NewCmdConfigSetCluster(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigGetCluster(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigSetContext(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigGetContext(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigInit(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigSetAuthInfo(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigGetAuthInfo(rootSettings))
|
||||
configRootCmd.AddCommand(NewCmdConfigUseContext(rootSettings))
|
||||
configRootCmd.AddCommand(NewSetClusterCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewGetClusterCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewSetContextCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewGetContextCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewInitCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewSetAuthInfoCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewGetAuthInfoCommand(rootSettings))
|
||||
configRootCmd.AddCommand(NewUseContextCommand(rootSettings))
|
||||
|
||||
return configRootCmd
|
||||
}
|
||||
|
||||
@@ -25,24 +25,29 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
getAuthInfoLong = `Display a specific user's information, or all defined users if no name is provided`
|
||||
const (
|
||||
getAuthInfoLong = `
|
||||
Display a specific user's credentials, or all defined user
|
||||
credentials if no name is provided.
|
||||
`
|
||||
|
||||
getAuthInfoExample = `# List all the users airshipctl knows about
|
||||
getAuthInfoExample = `
|
||||
# List all user credentials
|
||||
airshipctl config get-credentials
|
||||
|
||||
# Display a specific user information
|
||||
airshipctl config get-credentials e2e`
|
||||
# Display a specific user's credentials
|
||||
airshipctl config get-credentials exampleUser
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigGetAuthInfo returns a Command instance for 'config -AuthInfo' sub command
|
||||
// An AuthInfo refers to a particular user for a cluster
|
||||
func NewCmdConfigGetAuthInfo(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewGetAuthInfoCommand creates a command for viewing the user credentials
|
||||
// defined in the airshipctl config file.
|
||||
func NewGetAuthInfoCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.AuthInfoOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "get-credentials NAME",
|
||||
Short: "Gets a user entry from the airshipctl config",
|
||||
Long: getAuthInfoLong,
|
||||
Use: "get-credentials [NAME]",
|
||||
Short: "Get user credentials from the airshipctl config",
|
||||
Long: getAuthInfoLong[1:],
|
||||
Example: getAuthInfoExample,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -47,26 +47,19 @@ func TestGetAuthInfoCmd(t *testing.T) {
|
||||
}
|
||||
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "get-credentials",
|
||||
CmdLine: fmt.Sprintf("%s", fooAuthInfo),
|
||||
Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-all-credentials",
|
||||
CmdLine: fmt.Sprintf(""),
|
||||
Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-specific-credentials",
|
||||
CmdLine: fmt.Sprintf("%s", fooAuthInfo),
|
||||
Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
|
||||
CmdLine: fooAuthInfo,
|
||||
Cmd: cmd.NewGetAuthInfoCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-all-credentials",
|
||||
Cmd: cmd.NewGetAuthInfoCommand(settings),
|
||||
},
|
||||
|
||||
{
|
||||
Name: "missing",
|
||||
CmdLine: fmt.Sprintf("%s", missingAuthInfo),
|
||||
Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
|
||||
CmdLine: missingAuthInfo,
|
||||
Cmd: cmd.NewGetAuthInfoCommand(settings),
|
||||
Error: fmt.Errorf("user %s information was not "+
|
||||
"found in the configuration", missingAuthInfo),
|
||||
},
|
||||
@@ -82,7 +75,7 @@ func TestNoAuthInfosGetAuthInfoCmd(t *testing.T) {
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-credentials",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
|
||||
Cmd: cmd.NewGetAuthInfoCommand(settings),
|
||||
}
|
||||
testutil.RunTest(t, cmdTest)
|
||||
}
|
||||
|
||||
@@ -25,23 +25,32 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
getClusterLong = "Display a specific cluster or all defined clusters if no name is provided"
|
||||
const (
|
||||
getClusterLong = `
|
||||
Display a specific cluster or all defined clusters if no name is provided.
|
||||
|
||||
getClusterExample = fmt.Sprintf(`
|
||||
# List all the clusters airshipctl knows about
|
||||
Note that if a specific cluster's name is provided, the --cluster-type flag
|
||||
must also be provided.
|
||||
Valid values for the --cluster-type flag are [ephemeral|target].
|
||||
`
|
||||
|
||||
getClusterExample = `
|
||||
# List all clusters
|
||||
airshipctl config get-cluster
|
||||
|
||||
# Display a specific cluster
|
||||
airshipctl config get-cluster e2e --%v=ephemeral`, config.FlagClusterType)
|
||||
airshipctl config get-cluster --cluster-type=ephemeral exampleCluster
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigGetCluster returns a Command instance for 'config -Cluster' sub command
|
||||
func NewCmdConfigGetCluster(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewGetClusterCommand creates a command for viewing the cluster information
|
||||
// defined in the airshipctl config file.
|
||||
func NewGetClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.ClusterOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "get-cluster NAME",
|
||||
Short: getClusterLong,
|
||||
Use: "get-cluster [NAME]",
|
||||
Short: "Get cluster information from the airshipctl config",
|
||||
Long: getClusterLong[1:],
|
||||
Example: getClusterExample,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
airconfig := rootSettings.Config
|
||||
@@ -80,9 +89,9 @@ func addGetClusterFlags(o *config.ClusterOptions, cmd *cobra.Command) {
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(
|
||||
&o.ClusterType,
|
||||
config.FlagClusterType,
|
||||
"cluster-type",
|
||||
"",
|
||||
config.FlagClusterType+" for the cluster entry in airshipctl config")
|
||||
"type of the desired cluster")
|
||||
}
|
||||
|
||||
func validate(o *config.ClusterOptions) error {
|
||||
|
||||
@@ -29,8 +29,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ephemeralFlag = "--" + config.FlagClusterType + "=" + config.Ephemeral
|
||||
targetFlag = "--" + config.FlagClusterType + "=" + config.Target
|
||||
ephemeralFlag = "--cluster-type=ephemeral"
|
||||
targetFlag = "--cluster-type=target"
|
||||
|
||||
fooCluster = "clusterFoo"
|
||||
barCluster = "clusterBar"
|
||||
@@ -68,12 +68,12 @@ func TestGetClusterCmd(t *testing.T) {
|
||||
{
|
||||
Name: "get-ephemeral",
|
||||
CmdLine: fmt.Sprintf("%s %s", ephemeralFlag, fooCluster),
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-target",
|
||||
CmdLine: fmt.Sprintf("%s %s", targetFlag, fooCluster),
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
|
||||
// FIXME(howell): "airshipctl config get-cluster foo bar" will
|
||||
@@ -84,12 +84,12 @@ func TestGetClusterCmd(t *testing.T) {
|
||||
{
|
||||
Name: "get-multiple-ephemeral",
|
||||
CmdLine: fmt.Sprintf("%s %s %s", ephemeralFlag, fooCluster, barCluster),
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-multiple-target",
|
||||
CmdLine: fmt.Sprintf("%s %s %s", targetFlag, fooCluster, barCluster),
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
|
||||
// FIXME(howell): "airshipctl config get-cluster
|
||||
@@ -98,17 +98,17 @@ func TestGetClusterCmd(t *testing.T) {
|
||||
{
|
||||
Name: "get-all-ephemeral",
|
||||
CmdLine: ephemeralFlag,
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-all-target",
|
||||
CmdLine: targetFlag,
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "missing",
|
||||
CmdLine: fmt.Sprintf("%s %s", targetFlag, missingCluster),
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
Error: fmt.Errorf("cluster clustermissing information was not " +
|
||||
"found in the configuration"),
|
||||
},
|
||||
@@ -124,7 +124,7 @@ func TestNoClustersGetClusterCmd(t *testing.T) {
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-clusters",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewCmdConfigGetCluster(settings),
|
||||
Cmd: cmd.NewGetClusterCommand(settings),
|
||||
}
|
||||
testutil.RunTest(t, cmdTest)
|
||||
}
|
||||
|
||||
@@ -25,30 +25,31 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
getContextLong = "Display a specific context, the current-context or all defined contexts if no name is provided"
|
||||
const (
|
||||
getContextLong = `
|
||||
Display information about contexts such as associated manifests, users, and clusters.
|
||||
`
|
||||
|
||||
getContextExample = fmt.Sprintf(`# List all the contexts airshipctl knows about
|
||||
getContextExample = `
|
||||
# List all contexts
|
||||
airshipctl config get-context
|
||||
|
||||
# Display the current context
|
||||
airshipctl config get-context --%v
|
||||
airshipctl config get-context --current
|
||||
|
||||
# Display a specific Context
|
||||
airshipctl config get-context e2e`,
|
||||
config.FlagCurrentContext)
|
||||
# Display a specific context
|
||||
airshipctl config get-context exampleContext
|
||||
`
|
||||
)
|
||||
|
||||
// A Context refers to a particular cluster, however it does not specify which of the cluster types
|
||||
// it relates to. Getting explicit information about a particular context will depend
|
||||
// on the ClusterType flag.
|
||||
|
||||
// NewCmdConfigGetContext returns a Command instance for 'config -Context' sub command
|
||||
func NewCmdConfigGetContext(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewGetContextCommand creates a command for viewing cluster information
|
||||
// defined in the airshipctl config file.
|
||||
func NewGetContextCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.ContextOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "get-context NAME",
|
||||
Short: getContextLong,
|
||||
Use: "get-context [NAME]",
|
||||
Short: "Get context information from the airshipctl config",
|
||||
Long: getContextLong[1:],
|
||||
Example: getContextExample,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
airconfig := rootSettings.Config
|
||||
@@ -88,7 +89,7 @@ func addGetContextFlags(o *config.ContextOptions, cmd *cobra.Command) {
|
||||
|
||||
flags.BoolVar(
|
||||
&o.CurrentContext,
|
||||
config.FlagCurrentContext,
|
||||
"current",
|
||||
false,
|
||||
"retrieve the current context entry in airshipctl config")
|
||||
"get the current context")
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
currentContextFlag = "--" + config.FlagCurrentContext
|
||||
|
||||
fooContext = "ContextFoo"
|
||||
barContext = "ContextBar"
|
||||
bazContext = "ContextBaz"
|
||||
@@ -53,31 +51,31 @@ func TestGetContextCmd(t *testing.T) {
|
||||
{
|
||||
Name: "get-context",
|
||||
CmdLine: fmt.Sprintf("%s", fooContext),
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "get-all-contexts",
|
||||
CmdLine: fmt.Sprintf("%s %s", fooContext, barContext),
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
},
|
||||
// This is not implemented yet
|
||||
{
|
||||
Name: "get-multiple-contexts",
|
||||
CmdLine: fmt.Sprintf("%s %s", fooContext, barContext),
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
},
|
||||
|
||||
{
|
||||
Name: "missing",
|
||||
CmdLine: fmt.Sprintf("%s", missingContext),
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
Error: fmt.Errorf(`Context %s information was not
|
||||
found in the configuration.`, missingContext),
|
||||
},
|
||||
{
|
||||
Name: "get-current-context",
|
||||
CmdLine: fmt.Sprintf("%s", currentContextFlag),
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
CmdLine: "--current",
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -91,7 +89,7 @@ func TestNoContextsGetContextCmd(t *testing.T) {
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-contexts",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewCmdConfigGetContext(settings),
|
||||
Cmd: cmd.NewGetContextCommand(settings),
|
||||
}
|
||||
testutil.RunTest(t, cmdTest)
|
||||
}
|
||||
|
||||
@@ -22,19 +22,31 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
configInitLong = "Generate initial configuration files for airshipctl"
|
||||
const (
|
||||
initLong = `
|
||||
Generate an airshipctl config file and its associated kubeConfig file.
|
||||
These files will be written to the $HOME/.airship directory, and will contain
|
||||
default configurations.
|
||||
|
||||
NOTE: This will overwrite any existing config files in $HOME/.airship
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigInit returns a Command instance for 'config init' sub command
|
||||
func NewCmdConfigInit(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
configInitCmd := &cobra.Command{
|
||||
// NewInitCommand creates a command for generating default airshipctl config files.
|
||||
func NewInitCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// TODO(howell): It'd be nice to have a flag to tell
|
||||
// airshipctl where to store the new files.
|
||||
// TODO(howell): Currently, this command overwrites whatever the user
|
||||
// has in their airship directory. We should remove that functionality
|
||||
// as default and provide and optional --overwrite flag.
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: configInitLong,
|
||||
Short: "Generate initial configuration files for airshipctl",
|
||||
Long: initLong[1:],
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return rootSettings.Config.PersistConfig()
|
||||
},
|
||||
}
|
||||
|
||||
return configInitCmd
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestConfigInit(t *testing.T) {
|
||||
{
|
||||
Name: "config-init-help",
|
||||
CmdLine: "-h",
|
||||
Cmd: NewCmdConfigInit(nil),
|
||||
Cmd: NewInitCommand(nil),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -25,38 +25,43 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
setAuthInfoLong = fmt.Sprintf(`Sets a user entry in airshipctl config
|
||||
Specifying a name that already exists will merge new fields on top of existing values.`,
|
||||
)
|
||||
const (
|
||||
setAuthInfoLong = `
|
||||
Create or modify a user credential in the airshipctl config file.
|
||||
|
||||
setAuthInfoExample = fmt.Sprintf(`
|
||||
# Set only the "client-key" field on the "cluster-admin"
|
||||
# entry, without touching other values:
|
||||
airshipctl config set-credentials cluster-admin --%v=~/.kube/admin.key
|
||||
Note that specifying more than one authentication method is an error.
|
||||
`
|
||||
|
||||
# Set basic auth for the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --%v=admin --%v=uXFGweU9l35qcif
|
||||
setAuthInfoExample = `
|
||||
# Create a new user credential with basic auth
|
||||
airshipctl config set-credentials exampleUser \
|
||||
--username=exampleUser \
|
||||
--password=examplePassword
|
||||
|
||||
# Embed client certificate data in the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --%v=~/.kube/admin.crt --%v=true`,
|
||||
config.FlagUsername,
|
||||
config.FlagUsername,
|
||||
config.FlagPassword,
|
||||
config.FlagCertFile,
|
||||
config.FlagEmbedCerts,
|
||||
)
|
||||
# Change the client-key of a user named admin
|
||||
airshipctl config set-credentials admin \
|
||||
--client-key=$HOME/.kube/admin.key
|
||||
|
||||
# Change the username and password of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--username=admin \
|
||||
--password=uXFGweU9l35qcif
|
||||
|
||||
# Embed client certificate data of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--client-certificate=$HOME/.kube/admin.crt \
|
||||
--embed-certs
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigSetAuthInfo creates a command object for the "set-credentials" action, which
|
||||
// defines a new AuthInfo airship config.
|
||||
func NewCmdConfigSetAuthInfo(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewSetAuthInfoCommand creates a command for creating and modifying user
|
||||
// credentials in the airshipctl config file.
|
||||
func NewSetAuthInfoCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.AuthInfoOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "set-credentials NAME",
|
||||
Short: "Sets a user entry in the airshipctl config",
|
||||
Long: setAuthInfoLong,
|
||||
Short: "Manage user credentials",
|
||||
Long: setAuthInfoLong[1:],
|
||||
Example: setAuthInfoExample,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -83,37 +88,37 @@ func addSetAuthInfoFlags(o *config.AuthInfoOptions, cmd *cobra.Command) {
|
||||
|
||||
flags.StringVar(
|
||||
&o.ClientCertificate,
|
||||
config.FlagCertFile,
|
||||
"client-certificate",
|
||||
"",
|
||||
"Path to "+config.FlagCertFile+" file for the user entry in airshipctl")
|
||||
"path to a certificate")
|
||||
|
||||
flags.StringVar(
|
||||
&o.ClientKey,
|
||||
config.FlagKeyFile,
|
||||
"client-key",
|
||||
"",
|
||||
"Path to "+config.FlagKeyFile+" file for the user entry in airshipctl")
|
||||
"path to a key file")
|
||||
|
||||
flags.StringVar(
|
||||
&o.Token,
|
||||
config.FlagBearerToken,
|
||||
"token",
|
||||
"",
|
||||
config.FlagBearerToken+" for the user entry in airshipctl. Mutually exclusive with username and password flags.")
|
||||
"token to use for the credential; mutually exclusive with username and password flags.")
|
||||
|
||||
flags.StringVar(
|
||||
&o.Username,
|
||||
config.FlagUsername,
|
||||
"username",
|
||||
"",
|
||||
config.FlagUsername+" for the user entry in airshipctl. Mutually exclusive with token flag.")
|
||||
"username for the credential; mutually exclusive with token flag.")
|
||||
|
||||
flags.StringVar(
|
||||
&o.Password,
|
||||
config.FlagPassword,
|
||||
"password",
|
||||
"",
|
||||
config.FlagPassword+" for the user entry in airshipctl. Mutually exclusive with token flag.")
|
||||
"password for the credential; mutually exclusive with token flag.")
|
||||
|
||||
flags.BoolVar(
|
||||
&o.EmbedCertData,
|
||||
config.FlagEmbedCerts,
|
||||
"embed-certs",
|
||||
false,
|
||||
"Embed client cert/key for the user entry in airshipctl")
|
||||
"if set, embed the client certificate/key into the credential")
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@ func TestConfigSetAuthInfo(t *testing.T) {
|
||||
{
|
||||
Name: "config-cmd-set-authinfo-with-help",
|
||||
CmdLine: "--help",
|
||||
Cmd: cmd.NewCmdConfigSetAuthInfo(nil),
|
||||
Cmd: cmd.NewSetAuthInfoCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-authinfo-too-many-args",
|
||||
CmdLine: "arg1 arg2",
|
||||
Cmd: cmd.NewCmdConfigSetAuthInfo(nil),
|
||||
Cmd: cmd.NewSetAuthInfoCommand(nil),
|
||||
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 2),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-authinfo-too-few-args",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewCmdConfigSetAuthInfo(nil),
|
||||
Cmd: cmd.NewSetAuthInfoCommand(nil),
|
||||
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
|
||||
},
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func initInputConfig(t *testing.T) (given *config.Config, cleanup func(*testing.
|
||||
|
||||
func (test setAuthInfoTest) run(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{Config: test.inputConfig}
|
||||
test.cmdTest.Cmd = cmd.NewCmdConfigSetAuthInfo(settings)
|
||||
test.cmdTest.Cmd = cmd.NewSetAuthInfoCommand(settings)
|
||||
testutil.RunTest(t, test.cmdTest)
|
||||
|
||||
afterRunConf := settings.Config
|
||||
@@ -122,8 +122,8 @@ func TestSetAuthInfo(t *testing.T) {
|
||||
{
|
||||
testName: "set-auth-info",
|
||||
flags: []string{
|
||||
"--" + config.FlagUsername + "=" + testUsername,
|
||||
"--" + config.FlagPassword + "=" + testPassword,
|
||||
"--username=" + testUsername,
|
||||
"--password=" + testPassword,
|
||||
},
|
||||
userName: newUserName,
|
||||
userPassword: testPassword,
|
||||
@@ -132,7 +132,7 @@ func TestSetAuthInfo(t *testing.T) {
|
||||
{
|
||||
testName: "modify-auth-info",
|
||||
flags: []string{
|
||||
"--" + config.FlagPassword + "=" + testPassword + pwdDelta,
|
||||
"--password=" + testPassword + pwdDelta,
|
||||
},
|
||||
userName: existingUserName,
|
||||
userPassword: testPassword + pwdDelta,
|
||||
|
||||
@@ -26,42 +26,47 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/log"
|
||||
)
|
||||
|
||||
var (
|
||||
const (
|
||||
setClusterLong = `
|
||||
Sets a cluster entry in arshipctl config.
|
||||
Specifying a name that already exists will merge new fields on top of existing values for those fields.`
|
||||
Create or modify a cluster in the airshipctl config files.
|
||||
|
||||
setClusterExample = fmt.Sprintf(`
|
||||
# Set only the server field on the e2e cluster entry without touching other values.
|
||||
airshipctl config set-cluster e2e --%v=ephemeral --%v=https://1.2.3.4
|
||||
Since a cluster can be either "ephemeral" or "target", you must specify
|
||||
cluster-type when managing clusters.
|
||||
`
|
||||
|
||||
# Embed certificate authority data for the e2e cluster entry
|
||||
airshipctl config set-cluster e2e --%v=target --%v-authority=~/.airship/e2e/kubernetes.ca.crt
|
||||
setClusterExample = `
|
||||
# Set the server field on the ephemeral exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=ephemeral \
|
||||
--server=https://1.2.3.4
|
||||
|
||||
# Disable cert checking for the dev cluster entry
|
||||
airshipctl config set-cluster e2e --%v=target --%v=true
|
||||
# Embed certificate authority data for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--client-certificate-authority=$HOME/.airship/ca/kubernetes.ca.crt \
|
||||
--embed-certs
|
||||
|
||||
# Configure Client Certificate
|
||||
airshipctl config set-cluster e2e --%v=target --%v=true --%v=".airship/cert_file"`,
|
||||
config.FlagClusterType,
|
||||
config.FlagAPIServer,
|
||||
config.FlagClusterType,
|
||||
config.FlagCAFile,
|
||||
config.FlagClusterType,
|
||||
config.FlagInsecure,
|
||||
config.FlagClusterType,
|
||||
config.FlagEmbedCerts,
|
||||
config.FlagCertFile)
|
||||
# Disable certificate checking for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster
|
||||
--cluster-type=target \
|
||||
--insecure-skip-tls-verify
|
||||
|
||||
# Configure client certificate for the target exampleCluster
|
||||
airshipctl config set-cluster exampleCluster \
|
||||
--cluster-type=target \
|
||||
--embed-certs \
|
||||
--client-certificate=$HOME/.airship/cert_file
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigSetCluster creates a command object for the "set-cluster" action, which
|
||||
// defines a new cluster airshipctl config.
|
||||
func NewCmdConfigSetCluster(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewSetClusterCommand creates a command for creating and modifying clusters
|
||||
// in the airshipctl config file.
|
||||
func NewSetClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.ClusterOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "set-cluster NAME",
|
||||
Short: "Sets a cluster entry in the airshipctl config",
|
||||
Long: setClusterLong,
|
||||
Short: "Manage clusters",
|
||||
Long: setClusterLong[1:],
|
||||
Example: setClusterExample,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -90,36 +95,36 @@ func addSetClusterFlags(o *config.ClusterOptions, cmd *cobra.Command) {
|
||||
|
||||
flags.StringVar(
|
||||
&o.Server,
|
||||
config.FlagAPIServer,
|
||||
"server",
|
||||
"",
|
||||
config.FlagAPIServer+" for the cluster entry in airshipctl config")
|
||||
"server to use for the cluster")
|
||||
|
||||
flags.StringVar(
|
||||
&o.ClusterType,
|
||||
config.FlagClusterType,
|
||||
"cluster-type",
|
||||
"",
|
||||
config.FlagClusterType+" for the cluster entry in airshipctl config")
|
||||
"the type of the cluster to add or modify")
|
||||
|
||||
err := cmd.MarkFlagRequired(config.FlagClusterType)
|
||||
err := cmd.MarkFlagRequired("cluster-type")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flags.BoolVar(
|
||||
&o.InsecureSkipTLSVerify,
|
||||
config.FlagInsecure,
|
||||
"insecure-skip-tls-verify",
|
||||
true,
|
||||
config.FlagInsecure+" for the cluster entry in airshipctl config")
|
||||
"if set, disable certificate checking")
|
||||
|
||||
flags.StringVar(
|
||||
&o.CertificateAuthority,
|
||||
config.FlagCAFile,
|
||||
"certificate-authority",
|
||||
"",
|
||||
"Path to "+config.FlagCAFile+" file for the cluster entry in airshipctl config")
|
||||
"path to a certificate authority")
|
||||
|
||||
flags.BoolVar(
|
||||
&o.EmbedCAData,
|
||||
config.FlagEmbedCerts,
|
||||
"embed-certs",
|
||||
false,
|
||||
config.FlagEmbedCerts+" for the cluster entry in airshipctl config")
|
||||
"if set, embed the client certificate/key into the cluster")
|
||||
}
|
||||
|
||||
@@ -73,10 +73,9 @@ func TestSetClusterWithCAFile(t *testing.T) {
|
||||
givenConfig: given,
|
||||
args: []string{tname},
|
||||
flags: []string{
|
||||
"--" + config.FlagClusterType + "=" + config.Ephemeral,
|
||||
"--" + config.FlagEmbedCerts + "=false",
|
||||
"--" + config.FlagCAFile + "=" + certFile,
|
||||
"--" + config.FlagInsecure + "=false",
|
||||
"--cluster-type=ephemeral",
|
||||
"--certificate-authority=" + certFile,
|
||||
"--insecure-skip-tls-verify=false",
|
||||
},
|
||||
expectedOutput: fmt.Sprintf("Cluster %q of type %q created.\n", testCluster, config.Ephemeral),
|
||||
expectedConfig: expected,
|
||||
@@ -113,10 +112,10 @@ func TestSetClusterWithCAFileData(t *testing.T) {
|
||||
givenConfig: given,
|
||||
args: []string{tname},
|
||||
flags: []string{
|
||||
"--" + config.FlagClusterType + "=" + config.Ephemeral,
|
||||
"--" + config.FlagEmbedCerts + "=true",
|
||||
"--" + config.FlagCAFile + "=" + certFile,
|
||||
"--" + config.FlagInsecure + "=false",
|
||||
"--cluster-type=ephemeral",
|
||||
"--embed-certs",
|
||||
"--certificate-authority=" + certFile,
|
||||
"--insecure-skip-tls-verify=false",
|
||||
},
|
||||
expectedOutput: fmt.Sprintf("Cluster %q of type %q created.\n", tname, config.Ephemeral),
|
||||
expectedConfig: expected,
|
||||
@@ -149,9 +148,8 @@ func TestSetCluster(t *testing.T) {
|
||||
givenConfig: given,
|
||||
args: []string{tname},
|
||||
flags: []string{
|
||||
"--" + config.FlagClusterType + "=" + config.Ephemeral,
|
||||
"--" + config.FlagAPIServer + "=https://192.168.0.11",
|
||||
"--" + config.FlagInsecure + "=false",
|
||||
"--cluster-type=ephemeral",
|
||||
"--server=https://192.168.0.11",
|
||||
},
|
||||
expectedOutput: fmt.Sprintf("Cluster %q of type %q created.\n", tname, config.Ephemeral),
|
||||
expectedConfig: expected,
|
||||
@@ -191,8 +189,8 @@ func TestModifyCluster(t *testing.T) {
|
||||
givenConfig: given,
|
||||
args: []string{tname},
|
||||
flags: []string{
|
||||
"--" + config.FlagClusterType + "=" + config.Ephemeral,
|
||||
"--" + config.FlagAPIServer + "=https://192.168.0.99",
|
||||
"--cluster-type=ephemeral",
|
||||
"--server=https://192.168.0.99",
|
||||
},
|
||||
expectedOutput: fmt.Sprintf("Cluster %q of type %q modified.\n", tname, tctype),
|
||||
expectedConfig: expected,
|
||||
@@ -204,7 +202,7 @@ func (test setClusterTest) run(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{Config: test.givenConfig}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
cmd := cmd.NewCmdConfigSetCluster(settings)
|
||||
cmd := cmd.NewSetClusterCommand(settings)
|
||||
cmd.SetOut(buf)
|
||||
cmd.SetArgs(test.args)
|
||||
err := cmd.Flags().Parse(test.flags)
|
||||
@@ -218,7 +216,7 @@ func (test setClusterTest) run(t *testing.T) {
|
||||
// Loads the Config File that was updated
|
||||
afterRunConf := settings.Config
|
||||
// Get ClusterType
|
||||
tctypeFlag := cmd.Flag(config.FlagClusterType)
|
||||
tctypeFlag := cmd.Flag("cluster-type")
|
||||
require.NotNil(t, tctypeFlag)
|
||||
tctype := tctypeFlag.Value.String()
|
||||
|
||||
|
||||
@@ -25,44 +25,40 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
const (
|
||||
setContextLong = `
|
||||
Sets a context entry in arshipctl config.
|
||||
Specifying a name that already exists will merge new fields on top of existing values for those fields.`
|
||||
Create or modify a context in the airshipctl config files.
|
||||
`
|
||||
|
||||
setContextExample = fmt.Sprintf(`
|
||||
# Create a completely new e2e context entry
|
||||
airshipctl config set-context e2e --%v=kube-system --%v=manifest --%v=auth-info --%v=%v
|
||||
setContextExample = `
|
||||
# Create a new context named "exampleContext"
|
||||
airshipctl config set-context exampleContext \
|
||||
--namespace=kube-system \
|
||||
--manifest=exampleManifest \
|
||||
--user=exampleUser
|
||||
--cluster-type=target
|
||||
|
||||
# Update the current-context to e2e
|
||||
airshipctl config set-context e2e
|
||||
|
||||
# Update attributes of the current-context
|
||||
airshipctl config set-context --%s --%v=manifest`,
|
||||
config.FlagNamespace,
|
||||
config.FlagManifest,
|
||||
config.FlagAuthInfoName,
|
||||
config.FlagClusterType,
|
||||
config.Target,
|
||||
config.FlagCurrent,
|
||||
config.FlagManifest)
|
||||
# Update the manifest of the current-context
|
||||
airshipctl config set-context \
|
||||
--current \
|
||||
--manifest=exampleManifest
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigSetContext creates a command object for the "set-context" action, which
|
||||
// creates and modifies contexts in the airshipctl config
|
||||
func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewSetContextCommand creates a command for creating and modifying contexts
|
||||
// in the airshipctl config
|
||||
func NewSetContextCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
o := &config.ContextOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "set-context NAME",
|
||||
Short: "Switch to a new context or update context values in the airshipctl config",
|
||||
Long: setContextLong,
|
||||
Short: "Manage contexts",
|
||||
Long: setContextLong[1:],
|
||||
Example: setContextExample,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
nFlags := cmd.Flags().NFlag()
|
||||
if len(args) == 1 {
|
||||
//context name is made optional with --current flag added
|
||||
// context name is made optional with --current flag added
|
||||
o.Name = args[0]
|
||||
}
|
||||
if o.Name != "" && nFlags == 0 {
|
||||
@@ -93,37 +89,37 @@ func addSetContextFlags(o *config.ContextOptions, cmd *cobra.Command) {
|
||||
|
||||
flags.StringVar(
|
||||
&o.Cluster,
|
||||
config.FlagClusterName,
|
||||
"cluster",
|
||||
"",
|
||||
"sets the "+config.FlagClusterName+" for the specified context in the airshipctl config")
|
||||
"set the cluster for the specified context")
|
||||
|
||||
flags.StringVar(
|
||||
&o.AuthInfo,
|
||||
config.FlagAuthInfoName,
|
||||
"user",
|
||||
"",
|
||||
"sets the "+config.FlagAuthInfoName+" for the specified context in the airshipctl config")
|
||||
"set the user for the specified context")
|
||||
|
||||
flags.StringVar(
|
||||
&o.Manifest,
|
||||
config.FlagManifest,
|
||||
"manifest",
|
||||
"",
|
||||
"sets the "+config.FlagManifest+" for the specified context in the airshipctl config")
|
||||
"set the manifest for the specified context")
|
||||
|
||||
flags.StringVar(
|
||||
&o.Namespace,
|
||||
config.FlagNamespace,
|
||||
"namespace",
|
||||
"",
|
||||
"sets the "+config.FlagNamespace+" for the specified context in the airshipctl config")
|
||||
"set the namespace for the specified context")
|
||||
|
||||
flags.StringVar(
|
||||
&o.ClusterType,
|
||||
config.FlagClusterType,
|
||||
"cluster-type",
|
||||
"",
|
||||
"sets the "+config.FlagClusterType+" for the specified context in the airshipctl config")
|
||||
"set the cluster-type for the specified context")
|
||||
|
||||
flags.BoolVar(
|
||||
&o.Current,
|
||||
config.FlagCurrent,
|
||||
"current",
|
||||
false,
|
||||
"use current context from airshipctl config")
|
||||
"update the current context")
|
||||
}
|
||||
|
||||
@@ -49,17 +49,17 @@ func TestConfigSetContext(t *testing.T) {
|
||||
{
|
||||
Name: "config-cmd-set-context-with-help",
|
||||
CmdLine: "--help",
|
||||
Cmd: cmd.NewCmdConfigSetContext(nil),
|
||||
Cmd: cmd.NewSetContextCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-context-no-flags",
|
||||
CmdLine: "context",
|
||||
Cmd: cmd.NewCmdConfigSetContext(nil),
|
||||
Cmd: cmd.NewSetContextCommand(nil),
|
||||
},
|
||||
{
|
||||
Name: "config-cmd-set-context-too-many-args",
|
||||
CmdLine: "arg1 arg2",
|
||||
Cmd: cmd.NewCmdConfigSetContext(nil),
|
||||
Cmd: cmd.NewSetContextCommand(nil),
|
||||
Error: fmt.Errorf("accepts at most %d arg(s), received %d", 1, 2),
|
||||
},
|
||||
}
|
||||
@@ -84,10 +84,10 @@ func TestSetContext(t *testing.T) {
|
||||
testName: "set-context",
|
||||
contextName: "dummycontext",
|
||||
flags: []string{
|
||||
"--" + config.FlagClusterType + "=" + config.Target,
|
||||
"--" + config.FlagAuthInfoName + "=" + testUser,
|
||||
"--" + config.FlagManifest + "=" + defaultManifest,
|
||||
"--" + config.FlagNamespace + "=" + defaultNamespace,
|
||||
"--cluster-type=target",
|
||||
"--user=" + testUser,
|
||||
"--manifest=" + defaultManifest,
|
||||
"--namespace=" + defaultNamespace,
|
||||
},
|
||||
givenConfig: given,
|
||||
manifest: defaultManifest,
|
||||
@@ -102,7 +102,7 @@ func TestSetContext(t *testing.T) {
|
||||
testName: "modify-context",
|
||||
contextName: "def_target",
|
||||
flags: []string{
|
||||
"--" + config.FlagManifest + "=" + testManifest,
|
||||
"--manifest=" + testManifest,
|
||||
},
|
||||
givenConfig: given,
|
||||
manifest: testManifest,
|
||||
@@ -129,7 +129,7 @@ func (test setContextTest) run(t *testing.T) {
|
||||
// Get the Environment
|
||||
settings := &environment.AirshipCTLSettings{Config: test.givenConfig}
|
||||
|
||||
test.cmdTest.Cmd = cmd.NewCmdConfigSetContext(settings)
|
||||
test.cmdTest.Cmd = cmd.NewSetContextCommand(settings)
|
||||
testutil.RunTest(t, test.cmdTest)
|
||||
|
||||
afterRunConf := settings.Config
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
Modify airshipctl config files using subcommands
|
||||
like "airshipctl config set-context my-context"
|
||||
Manage the airshipctl config file
|
||||
|
||||
Usage:
|
||||
config [command]
|
||||
|
||||
Available Commands:
|
||||
get-cluster Display a specific cluster or all defined clusters if no name is provided
|
||||
get-context Display a specific context, the current-context or all defined contexts if no name is provided
|
||||
get-credentials Gets a user entry from the airshipctl config
|
||||
get-cluster Get cluster information from the airshipctl config
|
||||
get-context Get context information from the airshipctl config
|
||||
get-credentials Get user credentials from the airshipctl config
|
||||
help Help about any command
|
||||
init Generate initial configuration files for airshipctl
|
||||
set-cluster Sets a cluster entry in the airshipctl config
|
||||
set-context Switch to a new context or update context values in the airshipctl config
|
||||
set-credentials Sets a user entry in the airshipctl config
|
||||
use-context Switch to a different airshipctl context.
|
||||
set-cluster Manage clusters
|
||||
set-context Manage contexts
|
||||
set-credentials Manage user credentials
|
||||
use-context Switch to a different context
|
||||
|
||||
Flags:
|
||||
-h, --help help for config
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
Generate initial configuration files for airshipctl
|
||||
Generate an airshipctl config file and its associated kubeConfig file.
|
||||
These files will be written to the $HOME/.airship directory, and will contain
|
||||
default configurations.
|
||||
|
||||
NOTE: This will overwrite any existing config files in $HOME/.airship
|
||||
|
||||
Usage:
|
||||
init [flags]
|
||||
|
||||
@@ -4,22 +4,32 @@ Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
# Set only the "client-key" field on the "cluster-admin"
|
||||
# entry, without touching other values:
|
||||
airshipctl config set-credentials cluster-admin --username=~/.kube/admin.key
|
||||
# Create a new user credential with basic auth
|
||||
airshipctl config set-credentials exampleUser \
|
||||
--username=exampleUser \
|
||||
--password=examplePassword
|
||||
|
||||
# Set basic auth for the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
|
||||
# Change the client-key of a user named admin
|
||||
airshipctl config set-credentials admin \
|
||||
--client-key=$HOME/.kube/admin.key
|
||||
|
||||
# Change the username and password of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--username=admin \
|
||||
--password=uXFGweU9l35qcif
|
||||
|
||||
# Embed client certificate data of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--client-certificate=$HOME/.kube/admin.crt \
|
||||
--embed-certs
|
||||
|
||||
# Embed client certificate data in the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
|
||||
|
||||
Flags:
|
||||
--client-certificate string Path to client-certificate file for the user entry in airshipctl
|
||||
--client-key string Path to client-key file for the user entry in airshipctl
|
||||
--embed-certs Embed client cert/key for the user entry in airshipctl
|
||||
--client-certificate string path to a certificate
|
||||
--client-key string path to a key file
|
||||
--embed-certs if set, embed the client certificate/key into the credential
|
||||
-h, --help help for set-credentials
|
||||
--password string password for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--token string token for the user entry in airshipctl. Mutually exclusive with username and password flags.
|
||||
--username string username for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--password string password for the credential; mutually exclusive with token flag.
|
||||
--token string token to use for the credential; mutually exclusive with username and password flags.
|
||||
--username string username for the credential; mutually exclusive with token flag.
|
||||
|
||||
|
||||
@@ -4,22 +4,32 @@ Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
# Set only the "client-key" field on the "cluster-admin"
|
||||
# entry, without touching other values:
|
||||
airshipctl config set-credentials cluster-admin --username=~/.kube/admin.key
|
||||
# Create a new user credential with basic auth
|
||||
airshipctl config set-credentials exampleUser \
|
||||
--username=exampleUser \
|
||||
--password=examplePassword
|
||||
|
||||
# Set basic auth for the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
|
||||
# Change the client-key of a user named admin
|
||||
airshipctl config set-credentials admin \
|
||||
--client-key=$HOME/.kube/admin.key
|
||||
|
||||
# Change the username and password of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--username=admin \
|
||||
--password=uXFGweU9l35qcif
|
||||
|
||||
# Embed client certificate data of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--client-certificate=$HOME/.kube/admin.crt \
|
||||
--embed-certs
|
||||
|
||||
# Embed client certificate data in the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
|
||||
|
||||
Flags:
|
||||
--client-certificate string Path to client-certificate file for the user entry in airshipctl
|
||||
--client-key string Path to client-key file for the user entry in airshipctl
|
||||
--embed-certs Embed client cert/key for the user entry in airshipctl
|
||||
--client-certificate string path to a certificate
|
||||
--client-key string path to a key file
|
||||
--embed-certs if set, embed the client certificate/key into the credential
|
||||
-h, --help help for set-credentials
|
||||
--password string password for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--token string token for the user entry in airshipctl. Mutually exclusive with username and password flags.
|
||||
--username string username for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--password string password for the credential; mutually exclusive with token flag.
|
||||
--token string token to use for the credential; mutually exclusive with username and password flags.
|
||||
--username string username for the credential; mutually exclusive with token flag.
|
||||
|
||||
|
||||
@@ -1,26 +1,37 @@
|
||||
Sets a user entry in airshipctl config
|
||||
Specifying a name that already exists will merge new fields on top of existing values.
|
||||
Create or modify a user credential in the airshipctl config file.
|
||||
|
||||
Note that specifying more than one authentication method is an error.
|
||||
|
||||
Usage:
|
||||
set-credentials NAME [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# Set only the "client-key" field on the "cluster-admin"
|
||||
# entry, without touching other values:
|
||||
airshipctl config set-credentials cluster-admin --username=~/.kube/admin.key
|
||||
# Create a new user credential with basic auth
|
||||
airshipctl config set-credentials exampleUser \
|
||||
--username=exampleUser \
|
||||
--password=examplePassword
|
||||
|
||||
# Set basic auth for the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
|
||||
# Change the client-key of a user named admin
|
||||
airshipctl config set-credentials admin \
|
||||
--client-key=$HOME/.kube/admin.key
|
||||
|
||||
# Change the username and password of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--username=admin \
|
||||
--password=uXFGweU9l35qcif
|
||||
|
||||
# Embed client certificate data of the admin user
|
||||
airshipctl config set-credentials admin \
|
||||
--client-certificate=$HOME/.kube/admin.crt \
|
||||
--embed-certs
|
||||
|
||||
# Embed client certificate data in the "cluster-admin" entry
|
||||
airshipctl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
|
||||
|
||||
Flags:
|
||||
--client-certificate string Path to client-certificate file for the user entry in airshipctl
|
||||
--client-key string Path to client-key file for the user entry in airshipctl
|
||||
--embed-certs Embed client cert/key for the user entry in airshipctl
|
||||
--client-certificate string path to a certificate
|
||||
--client-key string path to a key file
|
||||
--embed-certs if set, embed the client certificate/key into the credential
|
||||
-h, --help help for set-credentials
|
||||
--password string password for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--token string token for the user entry in airshipctl. Mutually exclusive with username and password flags.
|
||||
--username string username for the user entry in airshipctl. Mutually exclusive with token flag.
|
||||
--password string password for the credential; mutually exclusive with token flag.
|
||||
--token string token to use for the credential; mutually exclusive with username and password flags.
|
||||
--username string username for the credential; mutually exclusive with token flag.
|
||||
|
||||
@@ -4,21 +4,25 @@ Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
# Create a completely new e2e context entry
|
||||
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
|
||||
# Create a new context named "exampleContext"
|
||||
airshipctl config set-context exampleContext \
|
||||
--namespace=kube-system \
|
||||
--manifest=exampleManifest \
|
||||
--user=exampleUser
|
||||
--cluster-type=target
|
||||
|
||||
# Update the current-context to e2e
|
||||
airshipctl config set-context e2e
|
||||
# Update the manifest of the current-context
|
||||
airshipctl config set-context \
|
||||
--current \
|
||||
--manifest=exampleManifest
|
||||
|
||||
# Update attributes of the current-context
|
||||
airshipctl config set-context --current --manifest=manifest
|
||||
|
||||
Flags:
|
||||
--cluster string sets the cluster for the specified context in the airshipctl config
|
||||
--cluster-type string sets the cluster-type for the specified context in the airshipctl config
|
||||
--current use current context from airshipctl config
|
||||
--cluster string set the cluster for the specified context
|
||||
--cluster-type string set the cluster-type for the specified context
|
||||
--current update the current context
|
||||
-h, --help help for set-context
|
||||
--manifest string sets the manifest for the specified context in the airshipctl config
|
||||
--namespace string sets the namespace for the specified context in the airshipctl config
|
||||
--user string sets the user for the specified context in the airshipctl config
|
||||
--manifest string set the manifest for the specified context
|
||||
--namespace string set the namespace for the specified context
|
||||
--user string set the user for the specified context
|
||||
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
|
||||
Sets a context entry in arshipctl config.
|
||||
Specifying a name that already exists will merge new fields on top of existing values for those fields.
|
||||
Create or modify a context in the airshipctl config files.
|
||||
|
||||
Usage:
|
||||
set-context NAME [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# Create a completely new e2e context entry
|
||||
airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target
|
||||
# Create a new context named "exampleContext"
|
||||
airshipctl config set-context exampleContext \
|
||||
--namespace=kube-system \
|
||||
--manifest=exampleManifest \
|
||||
--user=exampleUser
|
||||
--cluster-type=target
|
||||
|
||||
# Update the current-context to e2e
|
||||
airshipctl config set-context e2e
|
||||
# Update the manifest of the current-context
|
||||
airshipctl config set-context \
|
||||
--current \
|
||||
--manifest=exampleManifest
|
||||
|
||||
# Update attributes of the current-context
|
||||
airshipctl config set-context --current --manifest=manifest
|
||||
|
||||
Flags:
|
||||
--cluster string sets the cluster for the specified context in the airshipctl config
|
||||
--cluster-type string sets the cluster-type for the specified context in the airshipctl config
|
||||
--current use current context from airshipctl config
|
||||
--cluster string set the cluster for the specified context
|
||||
--cluster-type string set the cluster-type for the specified context
|
||||
--current update the current context
|
||||
-h, --help help for set-context
|
||||
--manifest string sets the manifest for the specified context in the airshipctl config
|
||||
--namespace string sets the namespace for the specified context in the airshipctl config
|
||||
--user string sets the user for the specified context in the airshipctl config
|
||||
--manifest string set the manifest for the specified context
|
||||
--namespace string set the namespace for the specified context
|
||||
--user string set the user for the specified context
|
||||
|
||||
@@ -4,8 +4,9 @@ Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
# Switch to a context named "e2e"
|
||||
airshipctl config use-context e2e
|
||||
# Switch to a context named "exampleContext"
|
||||
airshipctl config use-context exampleContext
|
||||
|
||||
|
||||
Flags:
|
||||
-h, --help help for use-context
|
||||
|
||||
@@ -4,8 +4,9 @@ Usage:
|
||||
|
||||
Examples:
|
||||
|
||||
# Switch to a context named "e2e"
|
||||
airshipctl config use-context e2e
|
||||
# Switch to a context named "exampleContext"
|
||||
airshipctl config use-context exampleContext
|
||||
|
||||
|
||||
Flags:
|
||||
-h, --help help for use-context
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
LocationOfOrigin: ""
|
||||
client-certificate: dummy_certificate
|
||||
client-key: dummy_key
|
||||
password: dummy_password
|
||||
token: dummy_token
|
||||
username: dummy_user
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
Error: Missing configuration: User credentials with name 'authinfoMissing'
|
||||
Usage:
|
||||
get-credentials NAME [flags]
|
||||
get-credentials [NAME] [flags]
|
||||
|
||||
Examples:
|
||||
# List all the users airshipctl knows about
|
||||
|
||||
# List all user credentials
|
||||
airshipctl config get-credentials
|
||||
|
||||
# Display a specific user information
|
||||
airshipctl config get-credentials e2e
|
||||
# Display a specific user's credentials
|
||||
airshipctl config get-credentials exampleUser
|
||||
|
||||
|
||||
Flags:
|
||||
-h, --help help for get-credentials
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
Error: Missing configuration: Cluster with name 'clusterMissing' of type 'target'
|
||||
Usage:
|
||||
get-cluster NAME [flags]
|
||||
get-cluster [NAME] [flags]
|
||||
|
||||
Examples:
|
||||
|
||||
# List all the clusters airshipctl knows about
|
||||
# List all clusters
|
||||
airshipctl config get-cluster
|
||||
|
||||
# Display a specific cluster
|
||||
airshipctl config get-cluster e2e --cluster-type=ephemeral
|
||||
airshipctl config get-cluster --cluster-type=ephemeral exampleCluster
|
||||
|
||||
|
||||
Flags:
|
||||
--cluster-type string cluster-type for the cluster entry in airshipctl config
|
||||
--cluster-type string type of the desired cluster
|
||||
-h, --help help for get-cluster
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
Error: Missing configuration: Context with name 'contextMissing'
|
||||
Usage:
|
||||
get-context NAME [flags]
|
||||
get-context [NAME] [flags]
|
||||
|
||||
Examples:
|
||||
# List all the contexts airshipctl knows about
|
||||
|
||||
# List all contexts
|
||||
airshipctl config get-context
|
||||
|
||||
# Display the current context
|
||||
airshipctl config get-context --current-context
|
||||
airshipctl config get-context --current
|
||||
|
||||
# Display a specific context
|
||||
airshipctl config get-context exampleContext
|
||||
|
||||
# Display a specific Context
|
||||
airshipctl config get-context e2e
|
||||
|
||||
Flags:
|
||||
--current-context retrieve the current context entry in airshipctl config
|
||||
-h, --help help for get-context
|
||||
--current get the current context
|
||||
-h, --help help for get-context
|
||||
|
||||
|
||||
@@ -25,21 +25,23 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/environment"
|
||||
)
|
||||
|
||||
var (
|
||||
useContextLong = "Switch to a new context defined in the airshipctl config file."
|
||||
const (
|
||||
useContextLong = `
|
||||
Switch to a different context defined in the airshipctl config file.
|
||||
`
|
||||
|
||||
useContextExample = `
|
||||
# Switch to a context named "e2e"
|
||||
airshipctl config use-context e2e`
|
||||
# Switch to a context named "exampleContext"
|
||||
airshipctl config use-context exampleContext
|
||||
`
|
||||
)
|
||||
|
||||
// NewCmdConfigUseContext creates a command object for the "use-context" action, which
|
||||
// switches to a defined airshipctl context.
|
||||
func NewCmdConfigUseContext(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
// NewUseContextCommand creates a command for switching to a defined airshipctl context.
|
||||
func NewUseContextCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "use-context NAME",
|
||||
Short: "Switch to a different airshipctl context.",
|
||||
Long: useContextLong,
|
||||
Short: "Switch to a different context",
|
||||
Long: useContextLong[1:],
|
||||
Example: useContextExample,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -31,18 +31,18 @@ func TestConfigUseContext(t *testing.T) {
|
||||
{
|
||||
Name: "config-use-context",
|
||||
CmdLine: "dummy_context",
|
||||
Cmd: cmd.NewCmdConfigUseContext(settings),
|
||||
Cmd: cmd.NewUseContextCommand(settings),
|
||||
},
|
||||
{
|
||||
Name: "config-use-context-no-args",
|
||||
CmdLine: "",
|
||||
Cmd: cmd.NewCmdConfigUseContext(settings),
|
||||
Cmd: cmd.NewUseContextCommand(settings),
|
||||
Error: errors.New("accepts 1 arg(s), received 0"),
|
||||
},
|
||||
{
|
||||
Name: "config-use-context-does-not-exist",
|
||||
CmdLine: "foo",
|
||||
Cmd: cmd.NewCmdConfigUseContext(settings),
|
||||
Cmd: cmd.NewUseContextCommand(settings),
|
||||
Error: errors.New("missing configuration: context with name 'foo'"),
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user