diff --git a/app/vmauth/auth_config.go b/app/vmauth/auth_config.go index 7d1e1db8a..cbe024dd1 100644 --- a/app/vmauth/auth_config.go +++ b/app/vmauth/auth_config.go @@ -163,13 +163,36 @@ type URLMap struct { // Regex represents a regex type Regex struct { + re *regexp.Regexp + sOriginal string - re *regexp.Regexp } +// QueryArg represents HTTP query arg type QueryArg struct { Name string `yaml:"name"` Value string `yaml:"value,omitempty"` + + sOriginal string +} + +// UnmarshalYAML unmarshals up from yaml. +func (qa *QueryArg) UnmarshalYAML(f func(interface{}) error) error { + if err := f(&qa.sOriginal); err != nil { + return err + } + + n := strings.IndexByte(qa.sOriginal, '=') + if n >= 0 { + qa.Name = qa.sOriginal[:n] + qa.Value = qa.sOriginal[n+1:] + } + return nil +} + +// MarshalYAML marshals up to yaml. +func (qa *QueryArg) MarshalYAML() (interface{}, error) { + return qa.sOriginal, nil } // URLPrefix represents passed `url_prefix` diff --git a/app/vmauth/auth_config_test.go b/app/vmauth/auth_config_test.go index 7586b6315..6e22e6ed9 100644 --- a/app/vmauth/auth_config_test.go +++ b/app/vmauth/auth_config_test.go @@ -218,15 +218,6 @@ users: - src_query_args: abc url_prefix: http://foobar `) - f(` -users: -- username: a - url_map: - - src_query_args: - - name: foo - incorrect_value: bar - url_prefix: http://foobar -`) // Invalid headers in url_map (missing ':') f(` @@ -350,8 +341,7 @@ users: - src_paths: ["/api/v1/write"] src_hosts: ["foo\\.bar", "baz:1234"] src_query_args: - - name: foo - value: bar + - 'foo=bar' url_prefix: ["http://vminsert1/insert/0/prometheus","http://vminsert2/insert/0/prometheus"] headers: - "foo: bar" diff --git a/docs/vmauth.md b/docs/vmauth.md index f1b0a3992..43a62e94f 100644 --- a/docs/vmauth.md +++ b/docs/vmauth.md @@ -125,12 +125,10 @@ while routing requests with `db=bar` query arg to `http://app2-backend`: unauthorized_user: url_map: - src_query_args: - - name: db - value: foo + - "db=foo" url_prefix: "http://app1-backend/" - src_query_args: - - name: db - value: bar + - "db=bar" url_prefix: "http://app2-backend/" ```