diff --git a/changelog/12508.txt b/changelog/12508.txt new file mode 100644 index 0000000000000..52c9e7c8397e1 --- /dev/null +++ b/changelog/12508.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: add new http option : -header which enable sending arbitrary headers with the cli +``` diff --git a/command/base.go b/command/base.go index 840d44e62e640..dbe7bb38b44d0 100644 --- a/command/base.go +++ b/command/base.go @@ -57,6 +57,8 @@ type BaseCommand struct { flagMFA []string + flagHeader map[string]string + tokenHelper token.TokenHelper client *api.Client @@ -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 @@ -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 {