forked from pomerium/verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
52 lines (44 loc) · 1.23 KB
/
config.go
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
package verify
import "cloud.google.com/go/firestore"
// config defaults
var (
DefaultBindAddress = ":8000"
DefaultJWKSEndpoint = "" // use the audience
DefaultProjectID = firestore.DetectProjectID
)
type config struct {
bindAddress string
firestoreProjectID string
jwksEndpoint string
}
// An Option customizes the config.
type Option func(cfg *config)
// WithBindAddress sets the bind address in the config.
func WithBindAddress(bindAddress string) Option {
return func(cfg *config) {
cfg.bindAddress = bindAddress
}
}
// WithJWKSEndpoint sets the jwks endpoint in the config.
func WithJWKSEndpoint(jwksEndpoint string) Option {
return func(cfg *config) {
cfg.jwksEndpoint = jwksEndpoint
}
}
// WithFirestoreProjectID sets the firestore project id in the config.
func WithFirestoreProjectID(projectID string) Option {
return func(cfg *config) {
cfg.firestoreProjectID = projectID
}
}
func getConfig(options ...Option) *config {
cfg := new(config)
WithBindAddress(DefaultBindAddress)(cfg)
// by default the firestore project id is derived from the environment
WithFirestoreProjectID(DefaultProjectID)(cfg)
WithJWKSEndpoint(DefaultJWKSEndpoint)(cfg)
for _, option := range options {
option(cfg)
}
return cfg
}