app/vmauth: simplify configuration for src_query_args

Use the shorter form:

src_query_args:
- arg1=value1
- arg2=value2

instead of

src_query_args:
- name: arg1
  value: value2
- name: arg2
  value: value2

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5878
This commit is contained in:
Aliaksandr Valialkin 2024-03-06 21:19:43 +02:00
parent 97dd7e26ad
commit 8efe12d66e
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 27 additions and 16 deletions

View file

@ -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`

View file

@ -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"

View file

@ -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/"
```