-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
80 lines (69 loc) · 2.15 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
expectedJWTIssuer string
expectedJWTAudience string
extraCACerts []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
}
}
// WithExpectedJWTIssuer sets the expected JWT issuer claim in the config. If
// set to the empty string, the issuer claim will not be validated.
func WithExpectedJWTIssuer(issuer string) Option {
return func(cfg *config) {
cfg.expectedJWTIssuer = issuer
}
}
// WithExpectedJWTAudience sets the expected JWT audience claim in the config.
// If set to the empty string, the audience claim will not be validated.
func WithExpectedJWTAudience(audience string) Option {
return func(cfg *config) {
cfg.expectedJWTAudience = audience
}
}
// WithFirestoreProjectID sets the firestore project id in the config.
func WithFirestoreProjectID(projectID string) Option {
return func(cfg *config) {
cfg.firestoreProjectID = projectID
}
}
// WithExtraCACerts adds paths to custom CA certificates to the config.
// Certificates added with this option will be used in addition to the system
// default pool.
func WithExtraCACerts(paths ...string) Option {
return func(cfg *config) {
cfg.extraCACerts = append(cfg.extraCACerts, paths...)
}
}
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
}