[amtool] use kingpin.v2#1330
Conversation
cli/config_resolver.go
Outdated
| ) | ||
|
|
||
| resolver := configResolver{} | ||
| // loadConfig loads flags from YAML files and injects them as environment variables. |
There was a problem hiding this comment.
Could any of these be secrets? The environment is not a safe place for secrets.
There was a problem hiding this comment.
I see your concern. Right now amtool doesn't expose any secret flags or arguments. Which isn't saying it won't.
There was a problem hiding this comment.
An idea would be to store this in a public map at init time and use it to populate defaults for flags.. but maybe it is too convoluted
There was a problem hiding this comment.
The alertmanager.url can potentially contain basic auth credentials.
Any ideas on how else to implement this? @thetincho's map idea might work. Parse the file and populate a struct/map, and set those as the default values for their appropriate flags?
There was a problem hiding this comment.
I've just tried and it doesn't work because of alertmanager.url (at least) which is a required flag . As stated in the kingpin documentation: You can not provide a Default() value to a Required() flag.
I've tried the suggestion from alecthomas/kingpin#208 (comment) but it doesn't work either because some flags are only valid for some commands and you can't have a flag present both in the configuration file and in the program's arguments (unless the flag can be repeated).
There was a problem hiding this comment.
Could we move it from being a Required flag, provide the value in the config file, and validate after the fact ourselves?
EDIT:
The flag will still attempt to create a URL var, so maybe it'll be as simple as doing a nil check and erroring
There was a problem hiding this comment.
@stuartnelson3 good idea, it seems to work...
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
055562e to
bd0f8de
Compare
|
Thanks for this! I have no comments on the PR, except my small suggestion. |
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
|
This has the fantastic side-effect of allowing |
stuartnelson3
left a comment
There was a problem hiding this comment.
a question and a small request, but looks awesome!
cli/root.go
Outdated
| continue | ||
| } | ||
| name := f.Model().Name | ||
| if name == "help" || name == "help-long" || name == "help(man" { |
cli/config/config.go
Outdated
| return nil, err | ||
| } | ||
| for k, v := range m { | ||
| if new, ok := legacyFlags[k]; ok { |
There was a problem hiding this comment.
it appears to be compiling here, but new is a keyword in golang and should be renamed
There was a problem hiding this comment.
Thanks for the catch-up!
|
Thanks @stuartnelson3, from my testing, the precedence between command line flags and configuration files works as expected but I plan to increase the coverage in the unit tests. There's still a question around short vs. long help messages though. |
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
ec630f5 to
1cee75f
Compare
I would prefer to keep the longer help message. The documentation isn't too long, and it covers the use cases. We would have to figure out where to add the long help information on prometheus.io if we were to get rid of it. |
This is my feeling too: having it buried under |
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
| var ( | ||
| longHelpText = map[string]string{} | ||
| app = kingpin.New("amtool", "Alertmanager CLI").DefaultEnvars() | ||
| app = kingpin.New("amtool", helpRoot).DefaultEnvars() |
There was a problem hiding this comment.
I think DefaultEnvars() can be removed, right?
There was a problem hiding this comment.
It could be deleted although the current code already has DefaultEnvars() which is why I didn't change it.
There was a problem hiding this comment.
k. I doubt anyone is relying on it, but I suppose if someone is we can leave it for now.
* Use default values to store values from config * fix typo and reserved keywork * move to long help texts * add one more unit test for resolver * update comments Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This is an attempt to fix #1328. To workaround the lack of configuration file support in kingpin v2, it injects environment variables after reading the flags from the YAML files. This isn't pretty but at least seems to work (this would need more testing obviously).
As noted in #976, there's no way to have longer help descriptions when using the
--help-longflag. I've tried several approaches but failed. I don't think it is even possible. So switching to v2 would mean to get rid of either the short helps or the long helps.Waiting for @stuartnelson3 & @thetincho's comments...