MCPcopy Index your code
hub / github.com/VictoriaMetrics/VictoriaLogs / CheckAuthFlag

Function CheckAuthFlag

lib/httpserver/httpserver.go:465–481  ·  view source on GitHub ↗

CheckAuthFlag checks whether the given authKey is set and valid Falls back to checkBasicAuth if authKey is not set

(w http.ResponseWriter, r *http.Request, expectedKey *flagutil.Password)

Source from the content-addressed store, hash-verified

463//
464// Falls back to checkBasicAuth if authKey is not set
465func CheckAuthFlag(w http.ResponseWriter, r *http.Request, expectedKey *flagutil.Password) bool {
466 expectedValue := expectedKey.Get()
467 if expectedValue == "" {
468 return CheckBasicAuth(w, r)
469 }
470 if len(r.FormValue("authKey")) == 0 {
471 authKeyRequestErrors.Inc()
472 http.Error(w, fmt.Sprintf("Expected to receive non-empty authKey when -%s is set", expectedKey.Name()), http.StatusUnauthorized)
473 return false
474 }
475 if r.FormValue("authKey") != expectedValue {
476 authKeyRequestErrors.Inc()
477 http.Error(w, fmt.Sprintf("The provided authKey doesn't match -%s", expectedKey.Name()), http.StatusUnauthorized)
478 return false
479 }
480 return true
481}
482
483// CheckBasicAuth validates credentials provided in request if httpAuth.* flags are set
484// returns true if credentials are valid or httpAuth.* flags are not set

Callers 10

RequestHandlerFunction · 0.92
handlerMethod · 0.92
processForceMergeFunction · 0.92
processForceFlushFunction · 0.92
RequestHandlerFunction · 0.92
RequestHandlerFunction · 0.92
requestHandlerFunction · 0.92
internalRequestHandlerFunction · 0.92
TestAuthKeyMetricsFunction · 0.85
builtinRoutesHandlerFunction · 0.85

Calls 4

CheckBasicAuthFunction · 0.85
GetMethod · 0.45
ErrorMethod · 0.45
NameMethod · 0.45

Tested by 1

TestAuthKeyMetricsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…