generated from fluffy-bunny/fluffycore-grpc-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
212 lines (199 loc) · 6.42 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package config
import (
"strings"
contracts_email "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/email"
contracts_webauthn "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/webauthn"
proto_oidc_models "github.com/fluffy-bunny/fluffycore-rage-identity/proto/oidc/models"
fluffycore_contracts_config "github.com/fluffy-bunny/fluffycore/contracts/config"
fluffycore_echo_contracts_cookies "github.com/fluffy-bunny/fluffycore/echo/contracts/cookies"
contracts_sessions "github.com/fluffy-bunny/fluffycore/echo/contracts/sessions"
)
type (
JWTValidators struct {
Issuers []string `json:"issuers"`
JWKSURLS []string `json:"jwksUrls"`
}
ConfigFiles struct {
OIDCClientPath string `json:"oidcClientPath"`
IDPsPath string `json:"idpsPath"`
SigningKeyJsonPath string `json:"signingKeyJsonPath"`
RagePath string `json:"ragePath"`
SeedUsersPath string `json:"seedUsersPath"`
}
InMemoryClient struct {
Secret string `json:"secret"`
ClientId string `json:"clientId"`
}
InMemoryClients struct {
Clients []*proto_oidc_models.Client `json:"clients"`
}
EchoConfig struct {
Port int `json:"port"`
SecureCookies *fluffycore_echo_contracts_cookies.SecureCookiesConfig `json:"secureCookies"`
DisableSecureCookies bool `json:"disableSecureCookies"`
}
PasswordConfig struct {
MinEntropyBits float64 `json:"minEntropyBits"`
}
InMemoryCacheConfig struct {
DefaultExpirationSeconds int `json:"defaultExpirationSeconds"`
CleanupIntervalSeconds int `json:"cleanupIntervalSeconds"`
}
BackingCacheConfig struct {
Type string `json:"type"`
InMemoryCache InMemoryCacheConfig `json:"inMemoryCache"`
}
SelfIDPConfig struct {
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
RedirectURL string `json:"redirectUrl"`
Authority string `json:"authority"`
Scopes []string `json:"scopes"`
}
OIDCConfig struct {
BaseUrl string `json:"baseUrl"`
OAuth2CallbackPath string `json:"oauth2CallbackPath"`
}
CookieConfig struct {
Domain string `json:"domain"`
}
SystemConfig struct {
DeveloperMode bool `json:"developerMode"`
Domain string `json:"domain"`
}
InitialConfig struct {
ConfigFiles ConfigFiles `json:"configFiles"`
}
Config struct {
fluffycore_contracts_config.CoreConfig `mapstructure:",squash"`
ConfigFiles ConfigFiles `json:"configFiles"`
Echo *EchoConfig `json:"echo"`
InMemoryClients InMemoryClients `json:"inMemoryClients"`
OIDCConfig *OIDCConfig `json:"oidcConfig"`
BackingCache *BackingCacheConfig `json:"backingCache"`
AutolinkOnEmailMatch bool `json:"autolinkOnEmailMatch"`
EmailVerificationRequired bool `json:"emailVerificationRequired"`
EmailConfig *contracts_email.EmailConfig `json:"emailConfig"`
SelfIDPConfig *SelfIDPConfig `json:"selfIDPConfig"`
CookieConfig *CookieConfig `json:"cookieConfig"`
SystemConfig *SystemConfig `json:"systemConfig"`
SessionConfig *contracts_sessions.SessionConfig `json:"sessionConfig"`
WebAuthNConfig *contracts_webauthn.WebAuthNConfig `json:"webAuthNConfig"`
PasswordConfig *PasswordConfig `json:"passwordConfig"`
}
)
const (
BackingCacheTypeInMemory = "in-memory"
BackingCacheTypeRedis = "redis"
)
// ConfigDefaultJSON default json
const configDefaultJSONTemplate = `
{
"APPLICATION_NAME": "in-environment",
"APPLICATION_ENVIRONMENT": "in-environment",
"PRETTY_LOG": false,
"LOG_LEVEL": "info",
"PORT": 50051,
"REST_PORT": 50052,
"GRPC_GATEWAY_ENABLED": true,
"cookieConfig": {
},
"jwtValidators": {},
"autolinkOnEmailMatch": true,
"emailVerificationRequired": true,
"selfIDPConfig": {
"clientId": "self-client",
"clientSecret": "secret",
"redirectUrl": "http://localhost:9044/auth/callback",
"authority": "http://localhost:9044",
"scopes": ["openid", "profile", "email"]
},
"emailConfig": {
"justLogIt": false,
"fromName": "IN_ENVIRONMENT",
"fromEmail": "IN_ENVIRONMENT@example.com",
"host": "localhost:25",
"auth": {
"plainAuth": {
"identity": "",
"username": "",
"password": "",
"host": "localhost"
}
}
},
"backingCache": {
"type": "${{BACKING_CACHE_TYPE}}",
"inMemoryCache": {
"defaultExpirationSeconds": -1,
"cleanupIntervalSeconds": 60
}
},
"configFiles": {
"ragePath": "./config/rage.json",
"oidcClientPath": "./config/oidc-clients.json",
"idpsPath": "./config/idps.json",
"signingKeyJsonPath": "./config/signing-keys.json",
"seedUsersPath": "./config/seed-users.json"
},
"ddProfilerConfig": {
"ENABLED": false,
"SERVICE_NAME": "in-environment",
"APPLICATION_ENVIRONMENT": "in-environment",
"VERSION": "1.0.0"
},
"echo": {
"port": 0,
"disableSecureCookies": false,
"secureCookies": {
"hashKey": "7f6a8b9c0d1e2f3a4b5c6d7e8f9a0b1c",
"blockKey": "1234567890abcdef1234567890abcdef"
}
},
"inMemoryClients": {
"clients": []
},
"oidcConfig": {
"baseUrl": "IN_ENVIRONMENT",
"oauth2CallbackPath": "/oauth2/callback"
},
"sessionConfig": {
"sessionName": "_session",
"authenticationKey": "7f6a8b9c0d1e2f3a4b5c6d7e8f9a0b1c",
"encryptionKey": "1234567890abcdef1234567890abcdef",
"maxAge": 1800,
"domain": "@@C"
},
"systemConfig": {
"domain": "@@CHANGEME@@",
"developerMode": false
},
"webAuthNConfig": {
"rpDisplayName": "RAGE",
"rpID": "[the domain]",
"rpOrigins": []
},
"passwordConfig": {
"minEntropyBits": 60
}
}
`
/*
Minimum length of 8 characters
At least 2 uppercase letters
At least 1 special character (such as !, @, #, $, &, )
At least 2 digits
At least 3 lowercase letters
pattern := `^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$`
*/
var ConfigDefaultJSON = []byte(``)
func init() {
replaceMap := map[string]string{
"${{BACKING_CACHE_TYPE}}": BackingCacheTypeInMemory,
}
fixed := configDefaultJSONTemplate
for k, v := range replaceMap {
fixed = strings.Replace(fixed, k, v, -1)
}
ConfigDefaultJSON = []byte(fixed)
}