cmd/certificates: ensure we can bind config values (#2779)

This commit is contained in:
Egon Elbre 2019-08-14 17:26:45 +03:00 committed by GitHub
parent 3a82b63974
commit fec10ccbd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -15,7 +15,8 @@ import (
"storj.io/storj/pkg/server"
)
type batchCfg struct {
// BatchCfg defines configuration for batching
type BatchCfg struct {
EmailsPath string `help:"optional path to a list of emails, delimited by <delimiter>, for batch processing"`
Delimiter string `help:"delimiter to split emails loaded from <emails-path> on (e.g. comma, new-line)" default:"\n"`
}
@ -33,7 +34,7 @@ var (
}
config struct {
batchCfg
BatchCfg
CA identity.CASetupConfig
Identity identity.SetupConfig
Server struct { // workaround server.Config change

View File

@ -138,7 +138,16 @@ func bindConfig(flags FlagSet, prefix string, val reflect.Value, vars map[string
continue
}
fieldaddr := fieldval.Addr().Interface()
if !fieldval.CanAddr() {
panic(fmt.Sprintf("cannot addr field %s in %s", field.Name, typ))
}
fieldref := fieldval.Addr()
if !fieldref.CanInterface() {
panic(fmt.Sprintf("cannot get interface of field %s in %s", field.Name, typ))
}
fieldaddr := fieldref.Interface()
if fieldvalue, ok := fieldaddr.(pflag.Value); ok {
help := field.Tag.Get("help")
var def string