Skip to content

Commit

Permalink
Merge pull request #375 from aerospike/v7.6.0
Browse files Browse the repository at this point in the history
add []string support in config defaults
  • Loading branch information
robertglonek authored Jul 29, 2024
2 parents e69b2ba + aa6a3f2 commit bfb5159
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
18 changes: 9 additions & 9 deletions src/cmdAgiExec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (c *agiExecCmd) Execute(args []string) error {
}

type agiExecSimulateCmd struct {
Path string `long:"path" description:"path to a json file to use for notification" default:"notify.sim.json"`
Make bool `long:"make" description:"set to make the notification file using resource manager code instead of sending it"`
AGIName string `long:"agi-name" description:"set agiName when making the notificaiton json" default:"agi"`
Help helpCmd `command:"help" subcommands-optional:"true" description:"Print help"`
notify notifier.HTTPSNotify
Path string `long:"path" description:"path to a json file to use for notification" default:"notify.sim.json"`
Make bool `long:"make" description:"set to make the notification file using resource manager code instead of sending it"`
AGIName string `long:"agi-name" description:"set agiName when making the notificaiton json" default:"agi"`
Help helpCmd `command:"help" subcommands-optional:"true" description:"Print help"`
notify notifier.HTTPSNotify `no-default:"true"`
deployJson string
}

Expand Down Expand Up @@ -287,10 +287,10 @@ func (c *agiExecGrafanaFixCmd) Execute(args []string) error {
}

type agiExecIngestCmd struct {
AGIName string `long:"agi-name"`
Async bool `long:"async" description:"if set, will asynchonously process logs and collectinfo"`
YamlFile string `short:"y" long:"yaml" description:"Yaml config file"`
notify notifier.HTTPSNotify
AGIName string `long:"agi-name"`
Async bool `long:"async" description:"if set, will asynchonously process logs and collectinfo"`
YamlFile string `short:"y" long:"yaml" description:"Yaml config file"`
notify notifier.HTTPSNotify `no-default:"true"`
notifyJSON bool
deployJson string
Help helpCmd `command:"help" subcommands-optional:"true" description:"Print help"`
Expand Down
24 changes: 12 additions & 12 deletions src/cmdAgiExecProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ type agiExecProxyCmd struct {
Help helpCmd `command:"help" subcommands-optional:"true" description:"Print help"`
isBasicAuth bool
isTokenAuth bool
lastActivity *activity
grafanaUrl *url.URL
grafanaProxy *httputil.ReverseProxy
ttydUrl *url.URL
ttydProxy *httputil.ReverseProxy
fbUrl *url.URL
fbProxy *httputil.ReverseProxy
gottyConns *counter
srv *http.Server
tokens *tokens
notify notifier.HTTPSNotify
lastActivity *activity `no-default:"true"`
grafanaUrl *url.URL `no-default:"true"`
grafanaProxy *httputil.ReverseProxy `no-default:"true"`
ttydUrl *url.URL `no-default:"true"`
ttydProxy *httputil.ReverseProxy `no-default:"true"`
fbUrl *url.URL `no-default:"true"`
fbProxy *httputil.ReverseProxy `no-default:"true"`
gottyConns *counter `no-default:"true"`
srv *http.Server `no-default:"true"`
tokens *tokens `no-default:"true"`
notify notifier.HTTPSNotify `no-default:"true"`
shuttingDown bool
shuttingDownMutex *sync.Mutex
shuttingDownMutex *sync.Mutex `no-default:"true"`
slacks3source string
slacksftpsource string
slackcustomsource string
Expand Down
16 changes: 16 additions & 0 deletions src/cmdConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (c *configDefaultsCmd) Execute(args []string) error {
value = "0"
}
}
case reflect.Slice:
default:
fmt.Printf("ERROR: Key is not a parameter (%s)\n", keyField.Type().Kind())
beepExit(1)
Expand Down Expand Up @@ -295,6 +296,12 @@ func (c *configDefaultsCmd) Execute(args []string) error {
}
keyField.SetInt(int64(v))
}
case reflect.Slice:
if keyField.Type().String() != "[]string" {
fmt.Println("Only string slices are supported; invalid key")
beepExit(1)
}
keyField.Set(reflect.ValueOf([]string{value}))
case reflect.String:
keyField.SetString(value)
case reflect.Bool:
Expand Down Expand Up @@ -423,6 +430,9 @@ func (c *configDefaultsCmd) getValuesNext(keyField reflect.Value, start string,
for i := 0; i < keyField.NumField(); i++ {
fieldName := keyField.Type().Field(i).Name
fieldTag := keyField.Type().Field(i).Tag
if fieldTag.Get("no-default") == "true" {
continue
}
if len(fieldName) > 0 && fieldName[0] >= 97 && fieldName[0] <= 122 {
if keyField.Field(i).Type().Kind() != reflect.Struct {
continue
Expand All @@ -441,6 +451,12 @@ func (c *configDefaultsCmd) getValuesNext(keyField reflect.Value, start string,
c.getValuesNext(keyField.Field(i), fieldName, ret, fieldTag, onlyChanged)
}
case reflect.Slice:
if keyField.Type().String() == "[]string" {
val := keyField.Interface().([]string)
if !onlyChanged || (tagDefault != "" && (len(val) != 1 || val[0] != tagDefault)) {
ret <- configValueCmd{start, fmt.Sprintf("%v", val)}
}
}
case reflect.Ptr:
if !keyField.IsNil() {
c.getValuesNext(reflect.Indirect(keyField), start, ret, tags, onlyChanged)
Expand Down

0 comments on commit bfb5159

Please sign in to comment.