TUN-4116: Ingore credentials-file setting in configuration file during tunnel create and delete opeations.

This change has two parts:
1. Update to newer version of the urfave/cli fork that correctly sets flag value along the context hierarchy while respecting config file overide behavior of the most specific instance of the flag.
2. Redefine --credentials-file flag so that create and delete subcommand don't use value from the config file.
This commit is contained in:
Igor Postelnik
2021-03-23 21:52:14 -05:00
parent 12447677cf
commit 9018ee5d5e
20 changed files with 2498 additions and 180 deletions

View File

@@ -22,10 +22,39 @@ type FlagInputSourceExtension interface {
// to an alternate input source.
func ApplyInputSourceValues(context *cli.Context, inputSourceContext InputSourceContext, flags []cli.Flag) error {
for _, f := range flags {
inputSourceExtendedFlag, isType := f.(FlagInputSourceExtension)
if isType {
err := inputSourceExtendedFlag.ApplyInputSourceValue(context, inputSourceContext)
if err != nil {
if err := applyFlagValue(f, context, inputSourceContext); err != nil {
return err
}
}
return nil
}
// ApplyInputSource sets flags from `inputSource` across cli.Context hierarchy.
// If a flag is defined at multiple levels, this method will try to update only the most specific context
// that uses the flag. If the most specific version of the flag doesn't support loading values from an input source
// the method will not check definitions from less-specific contexts.
func ApplyInputSource(c *cli.Context, inputSource InputSourceContext) error {
visited := make(map[string]bool)
for _, context := range c.Lineage() {
if context.Command == nil {
// we've reached the placeholder root context not associated with the app
break
}
flags := context.Command.Flags
if context.Command.Name == "" {
// commands that define child subcommands are executed as if they were an app
flags = context.App.Flags
}
applyingFlags:
for _, f := range flags {
for _, name := range f.Names() {
if visited[name] {
continue applyingFlags
}
visited[name] = true
}
if err := applyFlagValue(f, context, inputSource); err != nil {
return err
}
}
@@ -34,6 +63,17 @@ func ApplyInputSourceValues(context *cli.Context, inputSourceContext InputSource
return nil
}
func applyFlagValue(flag cli.Flag, context *cli.Context, inputSource InputSourceContext) error {
inputSourceExtendedFlag, isType := flag.(FlagInputSourceExtension)
if isType {
err := inputSourceExtendedFlag.ApplyInputSourceValue(context, inputSource)
if err != nil {
return err
}
}
return nil
}
// InitInputSource is used to to setup an InputSourceContext on a cli.Command Before method. It will create a new
// input source based on the func provided. If there is no error it will then apply the new input source to any flags
// that are supported by the input source