mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmauth: consistency renaming: UserInfo.URLMap -> UserInfo.URLMaps
This is based on https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3486
This commit is contained in:
parent
558165521b
commit
36941d6d75
4 changed files with 9 additions and 9 deletions
|
@ -37,7 +37,7 @@ type UserInfo struct {
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `yaml:"username,omitempty"`
|
||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
URLPrefix *URLPrefix `yaml:"url_prefix,omitempty"`
|
URLPrefix *URLPrefix `yaml:"url_prefix,omitempty"`
|
||||||
URLMap []URLMap `yaml:"url_map,omitempty"`
|
URLMaps []URLMap `yaml:"url_map,omitempty"`
|
||||||
Headers []Header `yaml:"headers,omitempty"`
|
Headers []Header `yaml:"headers,omitempty"`
|
||||||
|
|
||||||
requests *metrics.Counter
|
requests *metrics.Counter
|
||||||
|
@ -284,7 +284,7 @@ func parseAuthConfig(data []byte) (map[string]*UserInfo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, e := range ui.URLMap {
|
for _, e := range ui.URLMaps {
|
||||||
if len(e.SrcPaths) == 0 {
|
if len(e.SrcPaths) == 0 {
|
||||||
return nil, fmt.Errorf("missing `src_paths` in `url_map`")
|
return nil, fmt.Errorf("missing `src_paths` in `url_map`")
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ func parseAuthConfig(data []byte) (map[string]*UserInfo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(ui.URLMap) == 0 && ui.URLPrefix == nil {
|
if len(ui.URLMaps) == 0 && ui.URLPrefix == nil {
|
||||||
return nil, fmt.Errorf("missing `url_prefix`")
|
return nil, fmt.Errorf("missing `url_prefix`")
|
||||||
}
|
}
|
||||||
if ui.BearerToken != "" {
|
if ui.BearerToken != "" {
|
||||||
|
|
|
@ -278,7 +278,7 @@ users:
|
||||||
`, map[string]*UserInfo{
|
`, map[string]*UserInfo{
|
||||||
getAuthToken("foo", "", ""): {
|
getAuthToken("foo", "", ""): {
|
||||||
BearerToken: "foo",
|
BearerToken: "foo",
|
||||||
URLMap: []URLMap{
|
URLMaps: []URLMap{
|
||||||
{
|
{
|
||||||
SrcPaths: getSrcPaths([]string{"/api/v1/query", "/api/v1/query_range", "/api/v1/label/[^./]+/.+"}),
|
SrcPaths: getSrcPaths([]string{"/api/v1/query", "/api/v1/query_range", "/api/v1/label/[^./]+/.+"}),
|
||||||
URLPrefix: mustParseURL("http://vmselect/select/0/prometheus"),
|
URLPrefix: mustParseURL("http://vmselect/select/0/prometheus"),
|
||||||
|
@ -304,7 +304,7 @@ users:
|
||||||
},
|
},
|
||||||
getAuthToken("", "foo", ""): {
|
getAuthToken("", "foo", ""): {
|
||||||
BearerToken: "foo",
|
BearerToken: "foo",
|
||||||
URLMap: []URLMap{
|
URLMaps: []URLMap{
|
||||||
{
|
{
|
||||||
SrcPaths: getSrcPaths([]string{"/api/v1/query", "/api/v1/query_range", "/api/v1/label/[^./]+/.+"}),
|
SrcPaths: getSrcPaths([]string{"/api/v1/query", "/api/v1/query_range", "/api/v1/label/[^./]+/.+"}),
|
||||||
URLPrefix: mustParseURL("http://vmselect/select/0/prometheus"),
|
URLPrefix: mustParseURL("http://vmselect/select/0/prometheus"),
|
||||||
|
|
|
@ -52,7 +52,7 @@ func createTargetURL(ui *UserInfo, uOrig *url.URL) (*url.URL, []Header, error) {
|
||||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1554
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1554
|
||||||
u.Path = ""
|
u.Path = ""
|
||||||
}
|
}
|
||||||
for _, e := range ui.URLMap {
|
for _, e := range ui.URLMaps {
|
||||||
for _, sp := range e.SrcPaths {
|
for _, sp := range e.SrcPaths {
|
||||||
if sp.match(u.Path) {
|
if sp.match(u.Path) {
|
||||||
return e.URLPrefix.mergeURLs(&u), e.Headers, nil
|
return e.URLPrefix.mergeURLs(&u), e.Headers, nil
|
||||||
|
|
|
@ -54,7 +54,7 @@ func TestCreateTargetURLSuccess(t *testing.T) {
|
||||||
|
|
||||||
// Complex routing with `url_map`
|
// Complex routing with `url_map`
|
||||||
ui := &UserInfo{
|
ui := &UserInfo{
|
||||||
URLMap: []URLMap{
|
URLMaps: []URLMap{
|
||||||
{
|
{
|
||||||
SrcPaths: getSrcPaths([]string{"/api/v1/query"}),
|
SrcPaths: getSrcPaths([]string{"/api/v1/query"}),
|
||||||
URLPrefix: mustParseURL("http://vmselect/0/prometheus"),
|
URLPrefix: mustParseURL("http://vmselect/0/prometheus"),
|
||||||
|
@ -86,7 +86,7 @@ func TestCreateTargetURLSuccess(t *testing.T) {
|
||||||
|
|
||||||
// Complex routing regexp paths in `url_map`
|
// Complex routing regexp paths in `url_map`
|
||||||
ui = &UserInfo{
|
ui = &UserInfo{
|
||||||
URLMap: []URLMap{
|
URLMaps: []URLMap{
|
||||||
{
|
{
|
||||||
SrcPaths: getSrcPaths([]string{"/api/v1/query(_range)?", "/api/v1/label/[^/]+/values"}),
|
SrcPaths: getSrcPaths([]string{"/api/v1/query(_range)?", "/api/v1/label/[^/]+/values"}),
|
||||||
URLPrefix: mustParseURL("http://vmselect/0/prometheus"),
|
URLPrefix: mustParseURL("http://vmselect/0/prometheus"),
|
||||||
|
@ -132,7 +132,7 @@ func TestCreateTargetURLFailure(t *testing.T) {
|
||||||
}
|
}
|
||||||
f(&UserInfo{}, "/foo/bar")
|
f(&UserInfo{}, "/foo/bar")
|
||||||
f(&UserInfo{
|
f(&UserInfo{
|
||||||
URLMap: []URLMap{
|
URLMaps: []URLMap{
|
||||||
{
|
{
|
||||||
SrcPaths: getSrcPaths([]string{"/api/v1/query"}),
|
SrcPaths: getSrcPaths([]string{"/api/v1/query"}),
|
||||||
URLPrefix: mustParseURL("http://foobar/baz"),
|
URLPrefix: mustParseURL("http://foobar/baz"),
|
||||||
|
|
Loading…
Reference in a new issue