Skip to content

Commit

Permalink
CLI: add new -header option to be able to add headers to all cli requ…
Browse files Browse the repository at this point in the history
…ests #8754
  • Loading branch information
ylorenzati committed Sep 8, 2021
1 parent 71d1a29 commit b67ec8c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions command/base.go
Expand Up @@ -57,6 +57,8 @@ type BaseCommand struct {

flagMFA []string

flagHeader map[string]string

tokenHelper token.TokenHelper

client *api.Client
Expand Down Expand Up @@ -153,6 +155,13 @@ func (c *BaseCommand) Client() (*api.Client, error) {
client.SetPolicyOverride(c.flagPolicyOverride)
}

if c.flagHeader != nil {
for key, val := range c.flagHeader {
fmt.Printf("Key: %s, Value: %s\n", key, val)
client.AddHeader(key, val)
}
}

c.client = client

return client, nil
Expand Down Expand Up @@ -356,6 +365,14 @@ func (c *BaseCommand) flagSet(bit FlagSetBit) *FlagSets {
"command string and exit.",
})

f.StringMapVar(&StringMapVar{
Name: "header",
Target: &c.flagHeader,
Completion: complete.PredictAnything,
Usage: "Key-value pair provided as key=value to provide http header added to any request done by the CLI. " +
"This can be specified multiple times.",
})

}

if bit&(FlagSetOutputField|FlagSetOutputFormat) != 0 {
Expand Down

0 comments on commit b67ec8c

Please sign in to comment.