Skip to content

Commit

Permalink
Admin API key
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed Nov 9, 2024
1 parent 24ccc16 commit 05dbd35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions controller/http_api_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ func (hc *HttpController) HandleAction(w http.ResponseWriter, r *http.Request) {
ErrInvalidRequest(w, r)
return
}
if countAsInt > 1000 || countAsInt < 0 {
countAsInt = 1000
// Get admin api key
adminAPIKey := r.Header.Get("Authorization")
// get from env
adminAPIKeyEnv := utils.GetEnv("ADMIN_API_KEY", "")
maxCount := 1000
if adminAPIKeyEnv != "" && adminAPIKey == adminAPIKeyEnv {
maxCount = 100000
}
if countAsInt > int64(maxCount) || countAsInt < 0 {
countAsInt = int64(maxCount)
}
baseRequest["count"] = countAsInt
}
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/kalium/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ spec:
secretKeyRef:
name: kalium
key: rate_limit_whitelist
- name: ADMIN_API_KEY
valueFrom:
secretKeyRef:
name: kalium
key: admin_api_key
# - name: BPOW_URL
# value: http://boompow-service.boompow-next:8080/graphql
- name: NODE_WS_URL
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func main() {

// Get RATE_LIMIT_WHITELIST from env
rateLimitWhitelist := strings.Split(utils.GetEnv("RATE_LIMIT_WHITELIST", ""), ",")
// Get ADMIN_API_KEY from env
adminAPIKey := utils.GetEnv("ADMIN_API_KEY", "")

// Cors middleware
app.Use(cors.Handler(cors.Options{
Expand All @@ -210,6 +212,10 @@ func main() {
// Make key unique for whitelisted IPs
key = fmt.Sprint(time.Now().UnixNano())
}
if adminAPIKey != "" && r.Header.Get("Authorization") == adminAPIKey {
// Make key unique for admin API key
key = fmt.Sprint(time.Now().UnixNano())
}
return key, nil
}),
))
Expand Down

0 comments on commit 05dbd35

Please sign in to comment.