mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-22 03:06:36 +03:00
all: allow dynamically reading *AuthKey flag values from files and urls
Examples: 1) -metricsAuthKey=file:///abs/path/to/file - reads flag value from the given absolute filepath 2) -metricsAuthKey=file://./relative/path/to/file - reads flag value from the given relative filepath 3) -metricsAuthKey=http://some-host/some/path?query_arg=abc - reads flag value from the given url The flag value is automatically updated when the file contents changes.
This commit is contained in:
@@ -39,9 +39,11 @@ func TestGetQuotedRemoteAddr(t *testing.T) {
|
||||
|
||||
func TestBasicAuthMetrics(t *testing.T) {
|
||||
origUsername := *httpAuthUsername
|
||||
origPasswd := *httpAuthPassword
|
||||
origPasswd := httpAuthPassword.Get()
|
||||
defer func() {
|
||||
*httpAuthPassword = origPasswd
|
||||
if err := httpAuthPassword.Set(origPasswd); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
*httpAuthUsername = origUsername
|
||||
}()
|
||||
|
||||
@@ -61,14 +63,18 @@ func TestBasicAuthMetrics(t *testing.T) {
|
||||
}
|
||||
|
||||
*httpAuthUsername = "test"
|
||||
*httpAuthPassword = "pass"
|
||||
if err := httpAuthPassword.Set("pass"); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
f("test", "pass", 200)
|
||||
f("test", "wrong", 401)
|
||||
f("wrong", "pass", 401)
|
||||
f("wrong", "wrong", 401)
|
||||
|
||||
*httpAuthUsername = ""
|
||||
*httpAuthPassword = ""
|
||||
if err := httpAuthPassword.Set(""); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
f("test", "pass", 200)
|
||||
f("test", "wrong", 200)
|
||||
f("wrong", "pass", 200)
|
||||
@@ -77,9 +83,11 @@ func TestBasicAuthMetrics(t *testing.T) {
|
||||
|
||||
func TestAuthKeyMetrics(t *testing.T) {
|
||||
origUsername := *httpAuthUsername
|
||||
origPasswd := *httpAuthPassword
|
||||
origPasswd := httpAuthPassword.Get()
|
||||
defer func() {
|
||||
*httpAuthPassword = origPasswd
|
||||
if err := httpAuthPassword.Set(origPasswd); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
*httpAuthUsername = origUsername
|
||||
}()
|
||||
|
||||
@@ -117,7 +125,9 @@ func TestAuthKeyMetrics(t *testing.T) {
|
||||
}
|
||||
|
||||
*httpAuthUsername = "test"
|
||||
*httpAuthPassword = "pass"
|
||||
if err := httpAuthPassword.Set("pass"); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
tstWithOutAuthKey("test", "pass", 200)
|
||||
tstWithOutAuthKey("test", "wrong", 401)
|
||||
tstWithOutAuthKey("wrong", "pass", 401)
|
||||
|
||||
Reference in New Issue
Block a user