aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2021-11-16 22:18:20 -0800
committerMike Crute <mike@crute.us>2021-11-17 07:56:17 -0800
commite90d734c7c70513a21a7eaf78e424b2a190f2f1c (patch)
treea761caea62332ddaa140a5899da2660fb47cee1d
parent73ab23b5f74174ec6b6a988103306eeec389d5a8 (diff)
downloadcloud-identity-broker-e90d734c7c70513a21a7eaf78e424b2a190f2f1c.tar.bz2
cloud-identity-broker-e90d734c7c70513a21a7eaf78e424b2a190f2f1c.tar.xz
cloud-identity-broker-e90d734c7c70513a21a7eaf78e424b2a190f2f1c.zip
Track X-API-Key request count
-rw-r--r--app/middleware/auth.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/middleware/auth.go b/app/middleware/auth.go
index 167d261..0a20a9e 100644
--- a/app/middleware/auth.go
+++ b/app/middleware/auth.go
@@ -12,8 +12,19 @@ import (
12 "code.crute.us/mcrute/cloud-identity-broker/auth/github" 12 "code.crute.us/mcrute/cloud-identity-broker/auth/github"
13 13
14 "github.com/labstack/echo/v4" 14 "github.com/labstack/echo/v4"
15 "github.com/prometheus/client_golang/prometheus"
16 "github.com/prometheus/client_golang/prometheus/promauto"
15) 17)
16 18
19// apiKeyRequests tracks the number of requests made with the legacy X-API-Key
20// header instead of the Authorization header so that we can track when it's
21// safe to remove that edge-case.
22var apiKeyRequests = promauto.NewCounterVec(prometheus.CounterOpts{
23 Namespace: "aws_access", // Legacy Namespace
24 Name: "api_key_request_total",
25 Help: "Total number of requests using the X-API-Key header",
26}, nil)
27
17// canRegisterUrls is an interface that identifies what about an HTTP router is 28// canRegisterUrls is an interface that identifies what about an HTTP router is
18// needed by this middleware. This mainly exists to work around the fact that 29// needed by this middleware. This mainly exists to work around the fact that
19// our server is actually a golib.EchoWrapper and not an echo.Echo. 30// our server is actually a golib.EchoWrapper and not an echo.Echo.
@@ -106,6 +117,8 @@ func (m *AuthenticationMiddleware) Middleware(next echo.HandlerFunc) echo.Handle
106 if len(tp) == 2 && tp[0] == "Bearer" { 117 if len(tp) == 2 && tp[0] == "Bearer" {
107 token = tp[1] 118 token = tp[1]
108 } 119 }
120 } else {
121 apiKeyRequests.With(nil).Inc()
109 } 122 }
110 123
111 // If an API key is specified this is a success or failure path. There 124 // If an API key is specified this is a success or failure path. There