Add various env vars to CLI (#528)

* Add auth method ID env var

* Add env var for host catalogs
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-10-02 19:20:30 -04:00
1 parent a1765d5838
commit f8a2100603
9 files changed
+46 -94

No files matched your search

+7 -5
View File
@@ -64,11 +64,13 @@ type Command struct {
FlagRecoveryConfig string
flagOutputCurlString bool
FlagScopeId string
FlagId string
FlagName string
FlagDescription string
FlagVersion int
FlagScopeId string
FlagId string
FlagName string
FlagDescription string
FlagAuthMethodId string
FlagHostCatalogId string
FlagVersion int
client *api.Client
}
+2 -9
View File
@@ -25,7 +25,6 @@ type Command struct {
Func string
flagAuthMethodId string
flagPassword string
flagCurrentPassword string
flagNewPassword string
@@ -127,12 +126,6 @@ func (c *Command) Flags() *base.FlagSets {
for _, name := range flagsMap[c.Func] {
switch name {
case "auth-method-id":
f.StringVar(&base.StringVar{
Name: "auth-method-id",
Target: &c.flagAuthMethodId,
Usage: "The auth-method resource in which to create or update the account resource",
})
case "password":
f.StringVar(&base.StringVar{
Name: "password",
@@ -182,7 +175,7 @@ func (c *Command) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(flagsMap[c.Func], "auth-method-id") && c.flagAuthMethodId == "" {
if strutil.StrListContains(flagsMap[c.Func], "auth-method-id") && c.FlagAuthMethodId == "" {
c.UI.Error("Auth Method ID must be passed in via -auth-method-id")
return 1
}
@@ -274,7 +267,7 @@ func (c *Command) Run(args []string) int {
err = nil
}
case "list":
listResult, err = accountClient.List(c.Context, c.flagAuthMethodId, opts...)
listResult, err = accountClient.List(c.Context, c.FlagAuthMethodId, opts...)
case "set-password":
result, err = accountClient.SetPassword(c.Context, c.FlagId, c.flagPassword, version, opts...)
case "change-password":
+4 -16
View File
@@ -24,9 +24,8 @@ type PasswordCommand struct {
Func string
flagAuthMethodId string
flagLoginName string
flagPassword string
flagLoginName string
flagPassword string
}
func (c *PasswordCommand) Synopsis() string {
@@ -75,17 +74,6 @@ func (c *PasswordCommand) Flags() *base.FlagSets {
common.PopulateCommonFlags(c.Command, f, "password-type account", passwordFlagsMap[c.Func])
}
for _, name := range passwordFlagsMap[c.Func] {
switch name {
case "auth-method-id":
f.StringVar(&base.StringVar{
Name: "auth-method-id",
Target: &c.flagAuthMethodId,
Usage: "The auth-method resource in which to create or update the account resource",
})
}
}
f = set.NewFlagSet("Password Account Options")
for _, name := range passwordFlagsMap[c.Func] {
@@ -132,7 +120,7 @@ func (c *PasswordCommand) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(passwordFlagsMap[c.Func], "auth-method-id") && c.flagAuthMethodId == "" {
if strutil.StrListContains(passwordFlagsMap[c.Func], "auth-method-id") && c.FlagAuthMethodId == "" {
c.UI.Error("Auth Method ID must be passed in via -auth-method-id")
return 1
}
@@ -209,7 +197,7 @@ func (c *PasswordCommand) Run(args []string) int {
switch c.Func {
case "create":
result, err = accountClient.Create(c.Context, c.flagAuthMethodId, opts...)
result, err = accountClient.Create(c.Context, c.FlagAuthMethodId, opts...)
case "update":
result, err = accountClient.Update(c.Context, c.FlagId, version, opts...)
}
@@ -29,9 +29,8 @@ var envAuthMethodId = "BOUNDARY_AUTHENTICATE_AUTH_METHOD_ID"
type PasswordCommand struct {
*base.Command
flagLoginName string
flagPassword string
flagAuthMethodId string
flagLoginName string
flagPassword string
}
func (c *PasswordCommand) Synopsis() string {
@@ -69,9 +68,9 @@ func (c *PasswordCommand) Flags() *base.FlagSets {
f.StringVar(&base.StringVar{
Name: "auth-method-id",
Target: &c.flagAuthMethodId,
EnvVar: envAuthMethodId,
Usage: "Specifies the ID of the auth method against which to authenticate",
EnvVar: "BOUNDARY_AUTH_METHOD_ID",
Target: &c.FlagAuthMethodId,
Usage: "The auth-method resource to use for the operation",
})
return set
@@ -97,7 +96,7 @@ func (c *PasswordCommand) Run(args []string) int {
case c.flagLoginName == "":
c.UI.Error("Login name must be provided via -login-name")
return 1
case c.flagAuthMethodId == "":
case c.FlagAuthMethodId == "":
c.UI.Error("Auth method ID must be provided via -auth-method-id")
return 1
}
@@ -122,7 +121,7 @@ func (c *PasswordCommand) Run(args []string) int {
// note: Authenticate() calls SetToken() under the hood to set the
// auth bearer on the client so we do not need to do anything with the
// returned token after this call, so we ignore it
result, err := authmethods.NewClient(client).Authenticate(c.Context, c.flagAuthMethodId,
result, err := authmethods.NewClient(client).Authenticate(c.Context, c.FlagAuthMethodId,
map[string]interface{}{
"login_name": c.flagLoginName,
"password": c.flagPassword,
+2 -15
View File
@@ -21,8 +21,6 @@ type Command struct {
*base.Command
Func string
flagHostCatalogId string
}
func (c *Command) Synopsis() string {
@@ -94,17 +92,6 @@ func (c *Command) Flags() *base.FlagSets {
f := set.NewFlagSet("Command Options")
common.PopulateCommonFlags(c.Command, f, resource.Host.String(), flagsMap[c.Func])
for _, name := range flagsMap[c.Func] {
switch name {
case "host-catalog-id":
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to list host resources",
})
}
}
return set
}
@@ -133,7 +120,7 @@ func (c *Command) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(flagsMap[c.Func], "host-catalog-id") && c.flagHostCatalogId == "" {
if strutil.StrListContains(flagsMap[c.Func], "host-catalog-id") && c.FlagHostCatalogId == "" {
c.UI.Error("Host Catalog ID must be passed in via -host-catalog-id")
return 1
}
@@ -178,7 +165,7 @@ func (c *Command) Run(args []string) int {
err = nil
}
case "list":
listResult, err = hostClient.List(c.Context, c.flagHostCatalogId, opts...)
listResult, err = hostClient.List(c.Context, c.FlagHostCatalogId, opts...)
}
plural := "host"
+3 -15
View File
@@ -21,8 +21,7 @@ type StaticCommand struct {
Func string
flagHostCatalogId string
flagAddress string
flagAddress string
}
func (c *StaticCommand) Synopsis() string {
@@ -71,17 +70,6 @@ func (c *StaticCommand) Flags() *base.FlagSets {
common.PopulateCommonFlags(c.Command, f, "static-type host", staticFlagsMap[c.Func])
}
for _, name := range staticFlagsMap[c.Func] {
switch name {
case "host-catalog-id":
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to create or update the host resource",
})
}
}
f = set.NewFlagSet("Static Host Options")
for _, name := range staticFlagsMap[c.Func] {
@@ -122,7 +110,7 @@ func (c *StaticCommand) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(staticFlagsMap[c.Func], "host-catalog-id") && c.flagHostCatalogId == "" {
if strutil.StrListContains(staticFlagsMap[c.Func], "host-catalog-id") && c.FlagHostCatalogId == "" {
c.UI.Error("Host Catalog ID must be passed in via -host-catalog-id")
return 1
}
@@ -183,7 +171,7 @@ func (c *StaticCommand) Run(args []string) int {
switch c.Func {
case "create":
result, err = hostClient.Create(c.Context, c.flagHostCatalogId, opts...)
result, err = hostClient.Create(c.Context, c.FlagHostCatalogId, opts...)
case "update":
result, err = hostClient.Update(c.Context, c.FlagId, version, opts...)
}
+3 -10
View File
@@ -22,8 +22,7 @@ type Command struct {
Func string
flagHostCatalogId string
flagHosts []string
flagHosts []string
}
func (c *Command) Synopsis() string {
@@ -136,12 +135,6 @@ func (c *Command) Flags() *base.FlagSets {
for _, name := range flagsMap[c.Func] {
switch name {
case "host-catalog-id":
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to list host-set resources",
})
case "host":
f.StringSliceVar(&base.StringSliceVar{
Name: "host",
@@ -178,7 +171,7 @@ func (c *Command) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(flagsMap[c.Func], "host-catalog-id") && c.flagHostCatalogId == "" {
if strutil.StrListContains(flagsMap[c.Func], "host-catalog-id") && c.FlagHostCatalogId == "" {
c.UI.Error("Host Catalog ID must be passed in via -host-catalog-id")
return 1
}
@@ -258,7 +251,7 @@ func (c *Command) Run(args []string) int {
err = nil
}
case "list":
listResult, err = hostsetClient.List(c.Context, c.flagHostCatalogId, opts...)
listResult, err = hostsetClient.List(c.Context, c.FlagHostCatalogId, opts...)
case "add-hosts":
result, err = hostsetClient.AddHosts(c.Context, c.FlagId, version, hosts, opts...)
case "remove-hosts":
+2 -15
View File
@@ -20,8 +20,6 @@ type StaticCommand struct {
*base.Command
Func string
flagHostCatalogId string
}
func (c *StaticCommand) Synopsis() string {
@@ -67,17 +65,6 @@ func (c *StaticCommand) Flags() *base.FlagSets {
f := set.NewFlagSet("Command Options")
common.PopulateCommonFlags(c.Command, f, "static-type host-set", staticFlagsMap[c.Func])
for _, name := range staticFlagsMap[c.Func] {
switch name {
case "host-catalog-id":
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to create or update the host-set resource",
})
}
}
return set
}
@@ -105,7 +92,7 @@ func (c *StaticCommand) Run(args []string) int {
c.UI.Error("ID is required but not passed in via -id")
return 1
}
if strutil.StrListContains(staticFlagsMap[c.Func], "host-catalog-id") && c.flagHostCatalogId == "" {
if strutil.StrListContains(staticFlagsMap[c.Func], "host-catalog-id") && c.FlagHostCatalogId == "" {
c.UI.Error("Host Catalog ID must be passed in via -host-catalog-id")
return 1
}
@@ -154,7 +141,7 @@ func (c *StaticCommand) Run(args []string) int {
switch c.Func {
case "create":
result, err = hostsetClient.Create(c.Context, c.flagHostCatalogId, opts...)
result, err = hostsetClient.Create(c.Context, c.FlagHostCatalogId, opts...)
case "update":
result, err = hostsetClient.Update(c.Context, c.FlagId, version, opts...)
}
+16 -1
View File
@@ -14,9 +14,10 @@ func PopulateCommonFlags(c *base.Command, f *base.FlagSet, resourceType string,
f.StringVar(&base.StringVar{
Name: "scope-id",
Target: &c.FlagScopeId,
EnvVar: "BOUNDARY_SCOPE_ID",
Default: "global",
Completion: complete.PredictAnything,
Usage: `Scope in which to make the request.`,
Usage: `Scope in which to make the request`,
})
case "id":
f.StringVar(&base.StringVar{
@@ -42,6 +43,20 @@ func PopulateCommonFlags(c *base.Command, f *base.FlagSet, resourceType string,
Target: &c.FlagVersion,
Usage: fmt.Sprintf("The version of the %s against which to perform an update operation. If not specified, the command will perform a check-and-set automatically.", resourceType),
})
case "auth-method-id":
f.StringVar(&base.StringVar{
Name: "auth-method-id",
EnvVar: "BOUNDARY_AUTH_METHOD_ID",
Target: &c.FlagAuthMethodId,
Usage: "The auth-method resource to use for the operation",
})
case "host-catalog-id":
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
EnvVar: "BOUNDARY_HOST_CATALOG_ID",
Target: &c.FlagHostCatalogId,
Usage: "The host-catalog resource to use for the operation",
})
}
}
}