mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
lib/httpserver: directly pass flag value to CheckAuthFlag()
There is no sense in passing a pointer to flag value there.
This is a follow-up for 4225a0bd75
This commit is contained in:
parent
10f314cdbd
commit
aa027529eb
5 changed files with 13 additions and 15 deletions
|
@ -347,7 +347,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case "/prometheus/config", "/config":
|
case "/prometheus/config", "/config":
|
||||||
if !httpserver.CheckAuthFlag(w, r, configAuthKey, "configAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *configAuthKey, "configAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
promscrapeConfigRequests.Inc()
|
promscrapeConfigRequests.Inc()
|
||||||
|
@ -356,7 +356,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
return true
|
return true
|
||||||
case "/prometheus/api/v1/status/config", "/api/v1/status/config":
|
case "/prometheus/api/v1/status/config", "/api/v1/status/config":
|
||||||
// See https://prometheus.io/docs/prometheus/latest/querying/api/#config
|
// See https://prometheus.io/docs/prometheus/latest/querying/api/#config
|
||||||
if !httpserver.CheckAuthFlag(w, r, configAuthKey, "configAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *configAuthKey, "configAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
promscrapeStatusConfigRequests.Inc()
|
promscrapeStatusConfigRequests.Inc()
|
||||||
|
|
|
@ -60,7 +60,7 @@ func main() {
|
||||||
func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/-/reload":
|
case "/-/reload":
|
||||||
if !httpserver.CheckAuthFlag(w, r, reloadAuthKey, "reloadAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *reloadAuthKey, "reloadAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
configReloadRequests.Inc()
|
configReloadRequests.Inc()
|
||||||
|
|
|
@ -237,7 +237,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|
||||||
path := strings.Replace(r.URL.Path, "//", "/", -1)
|
path := strings.Replace(r.URL.Path, "//", "/", -1)
|
||||||
if path == "/internal/resetRollupResultCache" {
|
if path == "/internal/resetRollupResultCache" {
|
||||||
if !httpserver.CheckAuthFlag(w, r, resetCacheAuthKey, "resetCacheAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *resetCacheAuthKey, "resetCacheAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
promql.ResetRollupResultCache()
|
promql.ResetRollupResultCache()
|
||||||
|
|
|
@ -170,7 +170,7 @@ func newRequestHandler(strg *storage.Storage) httpserver.RequestHandler {
|
||||||
func requestHandler(w http.ResponseWriter, r *http.Request, strg *storage.Storage) bool {
|
func requestHandler(w http.ResponseWriter, r *http.Request, strg *storage.Storage) bool {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
if path == "/internal/force_merge" {
|
if path == "/internal/force_merge" {
|
||||||
if !httpserver.CheckAuthFlag(w, r, forceMergeAuthKey, "forceMergeAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *forceMergeAuthKey, "forceMergeAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Run force merge in background
|
// Run force merge in background
|
||||||
|
@ -189,7 +189,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request, strg *storage.Storag
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if path == "/internal/force_flush" {
|
if path == "/internal/force_flush" {
|
||||||
if !httpserver.CheckAuthFlag(w, r, forceFlushAuthKey, "forceFlushAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *forceFlushAuthKey, "forceFlushAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
logger.Infof("flushing storage to make pending data available for reading")
|
logger.Infof("flushing storage to make pending data available for reading")
|
||||||
|
@ -199,7 +199,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request, strg *storage.Storag
|
||||||
if !strings.HasPrefix(path, "/snapshot") {
|
if !strings.HasPrefix(path, "/snapshot") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !httpserver.CheckAuthFlag(w, r, snapshotAuthKey, "snapshotAuthKey") {
|
if !httpserver.CheckAuthFlag(w, r, *snapshotAuthKey, "snapshotAuthKey") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
path = path[len("/snapshot"):]
|
path = path[len("/snapshot"):]
|
||||||
|
|
|
@ -292,7 +292,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
return
|
return
|
||||||
case "/metrics":
|
case "/metrics":
|
||||||
metricsRequests.Inc()
|
metricsRequests.Inc()
|
||||||
if !CheckAuthFlag(w, r, metricsAuthKey, "metricsAuthKey") {
|
if !CheckAuthFlag(w, r, *metricsAuthKey, "metricsAuthKey") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
@ -301,7 +301,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
metricsHandlerDuration.UpdateDuration(startTime)
|
metricsHandlerDuration.UpdateDuration(startTime)
|
||||||
return
|
return
|
||||||
case "/flags":
|
case "/flags":
|
||||||
if !CheckAuthFlag(w, r, flagsAuthKey, "flagsAuthKey") {
|
if !CheckAuthFlag(w, r, *flagsAuthKey, "flagsAuthKey") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
@ -320,7 +320,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
default:
|
default:
|
||||||
if strings.HasPrefix(r.URL.Path, "/debug/pprof/") {
|
if strings.HasPrefix(r.URL.Path, "/debug/pprof/") {
|
||||||
pprofRequests.Inc()
|
pprofRequests.Inc()
|
||||||
if !CheckAuthFlag(w, r, pprofAuthKey, "pprofAuthKey") {
|
if !CheckAuthFlag(w, r, *pprofAuthKey, "pprofAuthKey") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DisableResponseCompression(w)
|
DisableResponseCompression(w)
|
||||||
|
@ -344,16 +344,14 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
// CheckAuthFlag checks whether the given authKey is set and valid
|
// CheckAuthFlag checks whether the given authKey is set and valid
|
||||||
//
|
//
|
||||||
// Falls back to checkBasicAuth if authKey is not set
|
// Falls back to checkBasicAuth if authKey is not set
|
||||||
func CheckAuthFlag(w http.ResponseWriter, r *http.Request, flagValue *string, flagName string) bool {
|
func CheckAuthFlag(w http.ResponseWriter, r *http.Request, flagValue string, flagName string) bool {
|
||||||
if len(*flagValue) == 0 {
|
if flagValue == "" {
|
||||||
return CheckBasicAuth(w, r)
|
return CheckBasicAuth(w, r)
|
||||||
}
|
}
|
||||||
|
if r.FormValue("authKey") != flagValue {
|
||||||
if r.FormValue("authKey") != *flagValue {
|
|
||||||
http.Error(w, fmt.Sprintf("The provided authKey doesn't match -%s", flagName), http.StatusUnauthorized)
|
http.Error(w, fmt.Sprintf("The provided authKey doesn't match -%s", flagName), http.StatusUnauthorized)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue