feat: static json credentials (#2423)
This commit is contained in:
1 parent
8c53d931aa
commit
546c5dc5be
42 files changed
+3207
-165
No files matched your search
@@ -73,6 +73,10 @@ type cmdInfo struct {
|
||||
// -secret, -string-secret, etc.
|
||||
HasGenericSecrets bool
|
||||
|
||||
// HasJsonObject controls whether to generate flags for -object,
|
||||
// -kv, -string-kv, -bool-kv, -num-kv.
|
||||
HasJsonObject bool
|
||||
|
||||
// IsPluginType controls whether standard plugin flags are generated
|
||||
IsPluginType bool
|
||||
|
||||
@@ -279,6 +283,22 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
NeedsSubtypeInCreate: true,
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
},
|
||||
{
|
||||
ResourceType: resource.Credential.String(),
|
||||
Pkg: "credentials",
|
||||
StdActions: []string{"create", "update"},
|
||||
SubActionPrefix: "json",
|
||||
SkipNormalHelp: true,
|
||||
HasExtraHelpFunc: true,
|
||||
HasId: true,
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
Container: "CredentialStore",
|
||||
VersionedActions: []string{"update"},
|
||||
NeedsSubtypeInCreate: true,
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
HasJsonObject: true,
|
||||
},
|
||||
},
|
||||
"groups": {
|
||||
{
|
||||
|
||||
@@ -171,15 +171,16 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Help() string {
|
||||
var flags{{ camelCase .SubActionPrefix }}Map = map[string][]string{
|
||||
{{ with $attrFlags := ", \"attributes\", \"attr\", \"string-attr\", \"bool-attr\", \"num-attr\"" }}
|
||||
{{ with $secretFlags := ", \"secrets\", \"secret\", \"string-secret\", \"bool-secret\", \"num-secret\"" }}
|
||||
{{ with $objectFlags := ", \"object\", \"kv\", \"string-kv\", \"bool-kv\", \"num-kv\"" }}
|
||||
{{ range $i, $action := $input.StdActions }}
|
||||
{{ if eq $action "create" }}
|
||||
"create": { "{{ kebabCase $input.Container }}-id", "name", "description" {{ if $input.IsPluginType }} , "plugin-id", "plugin-name" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} },
|
||||
"create": { "{{ kebabCase $input.Container }}-id", "name", "description" {{ if $input.IsPluginType }} , "plugin-id", "plugin-name" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} {{ if $input.HasJsonObject }} {{ $objectFlags }} {{ end }} },
|
||||
{{ end }}
|
||||
{{ if eq $action "read" }}
|
||||
"read": {"id"},
|
||||
{{ end }}
|
||||
{{ if eq $action "update" }}
|
||||
"update": {"id", "name", "description" {{ if hasAction $input.VersionedActions "update" }}, "version" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} },
|
||||
"update": {"id", "name", "description" {{ if hasAction $input.VersionedActions "update" }}, "version" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} {{ if $input.HasJsonObject }} {{ $objectFlags }} {{ end }} },
|
||||
{{ end }}
|
||||
{{ if eq $action "delete" }}
|
||||
"delete": {"id"},
|
||||
@@ -190,6 +191,7 @@ var flags{{ camelCase .SubActionPrefix }}Map = map[string][]string{
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
func (c *{{ camelCase .SubActionPrefix }}Command) Flags() *base.FlagSets {
|
||||
@@ -211,6 +213,11 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Flags() *base.FlagSets {
|
||||
common.PopulateSecretFlags(c.Command, f, flags{{ camelCase .SubActionPrefix }}Map, c.Func)
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasJsonObject }}
|
||||
f = set.NewFlagSet("Object Options")
|
||||
common.PopulateObjectFlags(c.Command, f, flags{{ camelCase .SubActionPrefix }}Map, c.Func)
|
||||
{{ end }}
|
||||
|
||||
extra{{ camelCase .SubActionPrefix }}FlagsFunc(c, set, f)
|
||||
|
||||
return set
|
||||
@@ -259,6 +266,27 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasGenericAttributes }}
|
||||
if c.FlagAttributes != "" && len(c.FlagAttrs) > 0 {
|
||||
c.PrintCliError(errors.New("-attributes flag cannot be used along with the following flags: attr, bool-attr, num-attr, string-attr"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasGenericSecrets }}
|
||||
if c.FlagSecrets != "" && len(c.FlagScrts) > 0 {
|
||||
c.PrintCliError(errors.New("-secrets flag cannot be used along with the following flags: secret, bool-secret, num-secret, string-secret"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasJsonObject }}
|
||||
if c.FlagObject != "" && len(c.FlagKv) > 0 {
|
||||
c.PrintCliError(errors.New("-object flag cannot be used along with the following flags: kv, bool-kv, num-kv, string-kv"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
var opts []{{ .Pkg }}.Option
|
||||
|
||||
if strutil.StrListContains(flags{{ camelCase .SubActionPrefix }}Map[c.Func], "{{ kebabCase .Container }}-id") {
|
||||
@@ -395,6 +423,21 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasJsonObject }}
|
||||
if err := common.HandleAttributeFlags(
|
||||
c.Command,
|
||||
"kv",
|
||||
c.FlagObject,
|
||||
c.FlagKv,
|
||||
func() {},
|
||||
func(in map[string]interface{}) {
|
||||
opts = append(opts, {{ .Pkg }}.WithJsonCredentialObject(in))
|
||||
}); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error evaluating kv flags to: %s", err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
if ok := extra{{ camelCase .SubActionPrefix }}FlagsHandlingFunc(c, f, &opts, ); !ok {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user