This repository was archived by the owner on May 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +48
-11
lines changed Expand file tree Collapse file tree 7 files changed +48
-11
lines changed Original file line number Diff line number Diff line change 14
14
Github
15
15
Slack
16
16
Webhook
17
+ Prometheus
17
18
}
18
19
19
20
Server struct {
@@ -57,6 +58,10 @@ type (
57
58
Webhook struct {
58
59
WebhookSecret string `split_words:"true"`
59
60
}
61
+
62
+ Prometheus struct {
63
+ PrometheusAuthSecret string `split_words:"true"`
64
+ }
60
65
)
61
66
62
67
func NewConfigFromEnv () (* Config , error ) {
Original file line number Diff line number Diff line change @@ -91,11 +91,12 @@ func newServerConfig(c *Config) *server.ServerConfig {
91
91
}
92
92
93
93
return & server.ServerConfig {
94
- Host : c .ServerHost ,
95
- Proto : c .ServerProto ,
96
- ProxyHost : proxyHost ,
97
- ProxyProto : proxyProto ,
98
- WebhookSecret : c .WebhookSecret ,
94
+ Host : c .ServerHost ,
95
+ Proto : c .ServerProto ,
96
+ ProxyHost : proxyHost ,
97
+ ProxyProto : proxyProto ,
98
+ WebhookSecret : c .WebhookSecret ,
99
+ PrometheusAuthSecret : c .PrometheusAuthSecret ,
99
100
}
100
101
}
101
102
Original file line number Diff line number Diff line change
1
+ # GITPLOY_PROMETHEUS_AUTH_SECRET
2
+
3
+ Optional string value to authorize the scrape request from the Prometheus. * It authorizes with the ` Authorization ` header on request.*
4
+
5
+ ```
6
+ GITPLOY_PROMETHEUS_AUTH_SECRET=92e6c41f002e71bf84e6c6b02e4c1e1b
7
+ ```
Original file line number Diff line number Diff line change 3
3
Optional string value to create an http-signature for the webhook. The webhook recipient use this secret to verify request authenticity.
4
4
5
5
```
6
- GITPLOY_WEBHOOK_SECRET=asd212fuas2lfjxye
6
+ GITPLOY_WEBHOOK_SECRET=ae354839ad94078b9ea125eec4874370
7
7
```
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Index of server configuration settings:
9
9
* [ GITPLOY_GITHUB_SCOPES] ( ./GITPLOY_GITHUB_SCOPES.md )
10
10
* [ GITPLOY_LICENSE] ( ./GITPLOY_LICENSE.md )
11
11
* [ GITPLOY_MEMBER_ENTRIES] ( ./GITPLOY_MEMBER_ENTRIES.md )
12
+ * [ GITPLOY_PROMETHEUS_AUTH_SECRET] ( ./GITPLOY_PROMETHEUS_AUTH_SECRET.md )
12
13
* [ GITPLOY_ORGANIZATION_ENTRIES] ( ./GITPLOY_ORGANIZATION_ENTRIES.md )
13
14
* [ GITPLOY_PROXY_SERVER_HOST] ( ./GITPLOY_PROXY_SERVER_HOST.md )
14
15
* [ GITPLOY_PROXY_SERVER_PROTO] ( ./GITPLOY_PROXY_SERVER_PROTO.md )
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package metrics
2
2
3
3
import (
4
4
"context"
5
+ "net/http"
6
+ "strings"
5
7
"time"
6
8
7
9
"github.com/gin-gonic/gin"
@@ -12,11 +14,18 @@ import (
12
14
"github.com/gitploy-io/gitploy/ent"
13
15
)
14
16
17
+ const (
18
+ headerAuth = "Authorization"
19
+ )
20
+
15
21
type (
16
- Metric struct {}
22
+ Metric struct {
23
+ prometheusAuthSecret string
24
+ }
17
25
18
26
MetricConfig struct {
19
27
Interactor
28
+ PrometheusAuthSecret string
20
29
}
21
30
22
31
collector struct {
@@ -34,10 +43,22 @@ func NewMetric(c *MetricConfig) *Metric {
34
43
newCollector (c .Interactor ),
35
44
)
36
45
37
- return & Metric {}
46
+ return & Metric {
47
+ prometheusAuthSecret : c .PrometheusAuthSecret ,
48
+ }
38
49
}
39
50
40
51
func (m * Metric ) CollectMetrics (c * gin.Context ) {
52
+ if m .prometheusAuthSecret != "" {
53
+ if value := strings .TrimPrefix (
54
+ c .GetHeader (headerAuth ),
55
+ "Bearer " ,
56
+ ); m .prometheusAuthSecret != value {
57
+ c .Status (http .StatusUnauthorized )
58
+ return
59
+ }
60
+ }
61
+
41
62
h := promhttp .Handler ()
42
63
h .ServeHTTP (c .Writer , c .Request )
43
64
}
Original file line number Diff line number Diff line change 41
41
ProxyHost string
42
42
ProxyProto string
43
43
44
- WebhookSecret string
44
+ WebhookSecret string
45
+ PrometheusAuthSecret string
45
46
}
46
47
47
48
SCMType string
@@ -196,9 +197,10 @@ func NewRouter(c *RouterConfig) *gin.Engine {
196
197
metricsapi := r .Group ("/metrics" )
197
198
{
198
199
m := metrics .NewMetric (& metrics.MetricConfig {
199
- Interactor : c .Interactor ,
200
+ Interactor : c .Interactor ,
201
+ PrometheusAuthSecret : c .PrometheusAuthSecret ,
200
202
})
201
- metricsapi .GET ("" , mw . OnlyAuthorized (), m .CollectMetrics )
203
+ metricsapi .GET ("" , m .CollectMetrics )
202
204
}
203
205
204
206
r .HEAD ("/slack" , func (gc * gin.Context ) {
You can’t perform that action at this time.
0 commit comments