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 e09eb9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog/12508.txt
@@ -0,0 +1,3 @@
```release-note:improvement
cli: add new http option : -header which enable sending arbitrary headers with the cli
```
16 changes: 16 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,12 @@ func (c *BaseCommand) Client() (*api.Client, error) {
client.SetPolicyOverride(c.flagPolicyOverride)
}

if c.flagHeader != nil {
for key, val := range c.flagHeader {
client.AddHeader(key, val)
}
}

c.client = client

return client, nil
Expand Down Expand Up @@ -356,6 +364,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 e09eb9f

Please sign in to comment.