You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
834 B
35 lines
834 B
6 years ago
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package web
|
||
6 years ago
|
|
||
|
import (
|
||
5 years ago
|
"crypto/subtle"
|
||
4 years ago
|
"net/http"
|
||
5 years ago
|
|
||
6 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
5 years ago
|
|
||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||
6 years ago
|
)
|
||
|
|
||
|
// Metrics validate auth token and render prometheus metrics
|
||
4 years ago
|
func Metrics(resp http.ResponseWriter, req *http.Request) {
|
||
6 years ago
|
if setting.Metrics.Token == "" {
|
||
4 years ago
|
promhttp.Handler().ServeHTTP(resp, req)
|
||
6 years ago
|
return
|
||
|
}
|
||
4 years ago
|
header := req.Header.Get("Authorization")
|
||
6 years ago
|
if header == "" {
|
||
4 years ago
|
http.Error(resp, "", 401)
|
||
6 years ago
|
return
|
||
|
}
|
||
5 years ago
|
got := []byte(header)
|
||
|
want := []byte("Bearer " + setting.Metrics.Token)
|
||
|
if subtle.ConstantTimeCompare(got, want) != 1 {
|
||
4 years ago
|
http.Error(resp, "", 401)
|
||
6 years ago
|
return
|
||
|
}
|
||
4 years ago
|
promhttp.Handler().ServeHTTP(resp, req)
|
||
6 years ago
|
}
|