mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +00:00
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:
parent
97dd7e26ad
commit
8efe12d66e
3 changed files with 27 additions and 16 deletions
|
@ -163,13 +163,36 @@ type URLMap struct {
|
||||||
|
|
||||||
// Regex represents a regex
|
// Regex represents a regex
|
||||||
type Regex struct {
|
type Regex struct {
|
||||||
|
re *regexp.Regexp
|
||||||
|
|
||||||
sOriginal string
|
sOriginal string
|
||||||
re *regexp.Regexp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryArg represents HTTP query arg
|
||||||
type QueryArg struct {
|
type QueryArg struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Value string `yaml:"value,omitempty"`
|
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`
|
// URLPrefix represents passed `url_prefix`
|
||||||
|
|
|
@ -218,15 +218,6 @@ users:
|
||||||
- src_query_args: abc
|
- src_query_args: abc
|
||||||
url_prefix: http://foobar
|
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 ':')
|
// Invalid headers in url_map (missing ':')
|
||||||
f(`
|
f(`
|
||||||
|
@ -350,8 +341,7 @@ users:
|
||||||
- src_paths: ["/api/v1/write"]
|
- src_paths: ["/api/v1/write"]
|
||||||
src_hosts: ["foo\\.bar", "baz:1234"]
|
src_hosts: ["foo\\.bar", "baz:1234"]
|
||||||
src_query_args:
|
src_query_args:
|
||||||
- name: foo
|
- 'foo=bar'
|
||||||
value: bar
|
|
||||||
url_prefix: ["http://vminsert1/insert/0/prometheus","http://vminsert2/insert/0/prometheus"]
|
url_prefix: ["http://vminsert1/insert/0/prometheus","http://vminsert2/insert/0/prometheus"]
|
||||||
headers:
|
headers:
|
||||||
- "foo: bar"
|
- "foo: bar"
|
||||||
|
|
|
@ -125,12 +125,10 @@ while routing requests with `db=bar` query arg to `http://app2-backend`:
|
||||||
unauthorized_user:
|
unauthorized_user:
|
||||||
url_map:
|
url_map:
|
||||||
- src_query_args:
|
- src_query_args:
|
||||||
- name: db
|
- "db=foo"
|
||||||
value: foo
|
|
||||||
url_prefix: "http://app1-backend/"
|
url_prefix: "http://app1-backend/"
|
||||||
- src_query_args:
|
- src_query_args:
|
||||||
- name: db
|
- "db=bar"
|
||||||
value: bar
|
|
||||||
url_prefix: "http://app2-backend/"
|
url_prefix: "http://app2-backend/"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue