-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
56 lines (45 loc) · 1.27 KB
/
init.go
File metadata and controls
56 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package vbjwt
import (
"encoding/hex"
"go.uber.org/zap"
)
var (
defaultCtx *zap.Logger
isProd bool
defaultIssuer string
skid string
skstore map[string][]byte
)
// Init prepares `vbjwt` for handling authentication later. `isProduction`
// indicates if the default `Generate` methods use "vikebot_production" or
// "vikebot_qa" as JWT issuer. The `signingKeys` map contains all ever used
// keys as [id]hexkeyformat. If you want to deprecate a single key-id remove
// the hexkey and use a empty string.
func Init(isProduction bool, defaultSigningkey string, signingKeys map[string]string, ctx *zap.Logger) error {
// Save production mode flag and set defaulIssuer accourdingly
isProd = isProduction
if isProduction {
defaultIssuer = "vikebot_production"
} else {
defaultIssuer = "vikebot_debug"
}
// Store default signing-key and init general store
skid = defaultSigningkey
skstore = make(map[string][]byte)
for k, v := range signingKeys {
// Check if the key is marked as deprecated
if len(v) == 0 {
skstore[k] = nil
}
// Try to decode string
buffer, err := hex.DecodeString(v)
if err != nil {
return err
}
// Store keyid and buffer in our memory store
skstore[k] = buffer
}
// Save default logging context
defaultCtx = ctx
return nil
}