feat: Add --extra-http-header flag (#372)
This commit is contained in:
@ -21,6 +21,7 @@ const (
|
|||||||
hostFlagName = "host"
|
hostFlagName = "host"
|
||||||
skipVerifyFlagName = "skip-verify"
|
skipVerifyFlagName = "skip-verify"
|
||||||
traceIdFlagName = "trace-debug-id"
|
traceIdFlagName = "trace-debug-id"
|
||||||
|
extraHttpHeaderFlagName = "extra-http-header"
|
||||||
configPathFlagName = "configs-path"
|
configPathFlagName = "configs-path"
|
||||||
configNameFlagName = "active-config"
|
configNameFlagName = "active-config"
|
||||||
httpDebugFlagName = "http-debug"
|
httpDebugFlagName = "http-debug"
|
||||||
@ -91,7 +92,19 @@ func newApiClient(ctx *cli.Context, configSvc config.Service, injectToken bool)
|
|||||||
configParams.TraceId = api.PtrString(ctx.String(traceIdFlagName))
|
configParams.TraceId = api.PtrString(ctx.String(traceIdFlagName))
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.NewAPIClient(api.NewAPIConfig(configParams)), nil
|
apiConfig := api.NewAPIConfig(configParams)
|
||||||
|
|
||||||
|
if ctx.IsSet(extraHttpHeaderFlagName) {
|
||||||
|
for _, h := range ctx.StringSlice(extraHttpHeaderFlagName) {
|
||||||
|
k, v, ok := stringsCut(h, ":")
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf(`header flag syntax "key:value", missing value in %q`, h)
|
||||||
|
}
|
||||||
|
apiConfig.AddDefaultHeader(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.NewAPIClient(apiConfig), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func withContext() cli.BeforeFunc {
|
func withContext() cli.BeforeFunc {
|
||||||
@ -170,6 +183,10 @@ type CommonStringFlag struct {
|
|||||||
cli.StringFlag
|
cli.StringFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommonStringSliceFlag struct {
|
||||||
|
cli.StringSliceFlag
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: urfave/cli has dedicated support for global flags, but it only parses those flags
|
// NOTE: urfave/cli has dedicated support for global flags, but it only parses those flags
|
||||||
// if they're specified before any command names. This is incompatible with the old influx
|
// if they're specified before any command names. This is incompatible with the old influx
|
||||||
// CLI, which repeatedly registered common flags on every "leaf" command, forcing the flags
|
// CLI, which repeatedly registered common flags on every "leaf" command, forcing the flags
|
||||||
@ -212,6 +229,11 @@ func coreFlags() []cli.Flag {
|
|||||||
Hidden: true,
|
Hidden: true,
|
||||||
EnvVar: "INFLUX_TRACE_DEBUG_ID",
|
EnvVar: "INFLUX_TRACE_DEBUG_ID",
|
||||||
}},
|
}},
|
||||||
|
&CommonStringSliceFlag{cli.StringSliceFlag{
|
||||||
|
Name: extraHttpHeaderFlagName,
|
||||||
|
Hidden: true,
|
||||||
|
EnvVar: "INFLUX_EXTRA_HTTP_HEADER",
|
||||||
|
}},
|
||||||
&CommonBoolFlag{cli.BoolFlag{
|
&CommonBoolFlag{cli.BoolFlag{
|
||||||
Name: httpDebugFlagName,
|
Name: httpDebugFlagName,
|
||||||
}},
|
}},
|
||||||
|
9
cmd/influx/util.go
Normal file
9
cmd/influx/util.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//go:build go1.18
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func stringsCut(s, sep string) (before, after string, found bool) {
|
||||||
|
return strings.Cut(s, sep)
|
||||||
|
}
|
16
cmd/influx/util_go117.go
Normal file
16
cmd/influx/util_go117.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//go:build !go1.18
|
||||||
|
|
||||||
|
// remove this backward compat shim once we either:
|
||||||
|
// a) upgrade cross-builder docker image in https://github.com/influxdata/edge/
|
||||||
|
// b) switch the CI system for this repo away from using cross-builder docker image.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func stringsCut(s, sep string) (before, after string, found bool) {
|
||||||
|
if i := strings.Index(s, sep); i >= 0 {
|
||||||
|
return s[:i], s[i+len(sep):], true
|
||||||
|
}
|
||||||
|
return s, "", false
|
||||||
|
}
|
Reference in New Issue
Block a user