Skip to content

Commit 54e3205

Browse files
committed
refactor token config parsing
1 parent 7665f94 commit 54e3205

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/codeshelldev/gotl v0.0.9 h1:cdLA6XzPt+f4RIW24Yx3dqBbRAq5JO0obzuwhaOgsEo=
2-
github.com/codeshelldev/gotl v0.0.9/go.mod h1:rDkJma6eQSRfCr7ieX9/esn3/uAWNzjHfpjlr9j6FFk=
31
github.com/codeshelldev/gotl v0.0.12 h1:VM3W6hiEfPgK+cCLT70S004tYAdhQWXD72FtFqCF+2Q=
42
github.com/codeshelldev/gotl v0.0.12/go.mod h1:rDkJma6eQSRfCr7ieX9/esn3/uAWNzjHfpjlr9j6FFk=
53
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

internals/config/structure/structure.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ type ENV struct {
55
DEFAULTS_PATH string
66
FAVICON_PATH string
77
TOKENS_DIR string
8+
89
INSECURE bool
910

11+
TOKENS []string
12+
1013
CONFIGS map[string]*CONFIG
1114
}
1215

internals/config/tokens.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func InitTokens() {
7171
if len(apiTokens) > 0 {
7272
log.Debug("Registered " + strconv.Itoa(len(apiTokens)) + " Tokens")
7373
}
74+
75+
ENV.TOKENS = apiTokens
7476
}
7577

7678
func parseTokenConfigs(configArray []structure.CONFIG) map[string]structure.CONFIG {

internals/proxy/middlewares/auth.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package middlewares
33
import (
44
"context"
55
"encoding/base64"
6-
"maps"
76
"net/http"
87
"slices"
98
"strings"
@@ -18,15 +17,14 @@ var Auth Middleware = Middleware{
1817
}
1918

2019
func authHandler(next http.Handler) http.Handler {
21-
tokenKeys := maps.Keys(config.ENV.CONFIGS)
22-
tokens := slices.Collect(tokenKeys)
20+
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
21+
tokens := config.ENV.TOKENS
2322

24-
if tokens == nil {
25-
tokens = []string{}
26-
}
23+
if tokens == nil {
24+
tokens = []string{}
25+
}
2726

28-
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
29-
if len(tokens) <= 0 {
27+
if config.ENV.INSECURE || len(tokens) <= 0 {
3028
next.ServeHTTP(w, req)
3129
return
3230
}

0 commit comments

Comments
 (0)