/
environment.go
87 lines (63 loc) · 2.71 KB
/
environment.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
package config
import "strings"
type TrustProxy bool
type DevMode bool
type SentryDSN string
type AuthUISentryDSN string
type ImagesCDNHost string
type WebAppCDNHost string
type CORSAllowedOrigins string
type NFTIndexerAPIEndpoint string
type DenoEndpoint string
type AppHostSuffixes []string
func (s AppHostSuffixes) CheckIsDefaultDomain(host string) bool {
for _, suffix := range s {
if before, found := strings.CutSuffix(host, suffix); found {
if !strings.Contains(before, ".") {
// We have found a proof.
return true
}
}
}
return false
}
func (c *CORSAllowedOrigins) List() []string {
if string(*c) == "" {
return []string{}
}
return strings.Split(string(*c), ",")
}
type EnvironmentConfig struct {
// TrustProxy sets whether HTTP headers from proxy are to be trusted
TrustProxy TrustProxy `envconfig:"TRUST_PROXY" default:"false"`
// DevMode sets whether the server would be run under development mode
DevMode DevMode `envconfig:"DEV_MODE" default:"false"`
// LogLevel sets the global log level
LogLevel string `envconfig:"LOG_LEVEL" default:"warn"`
// SentryDSN sets the sentry DSN.
SentryDSN SentryDSN `envconfig:"SENTRY_DSN"`
// AuthUISentryDSN sets the sentry DSN for auth ui.
AuthUISentryDSN AuthUISentryDSN `envconfig:"AUTH_UI_SENTRY_DSN"`
// GlobalDatabase configures the global database
GlobalDatabase GlobalDatabaseCredentialsEnvironmentConfig `envconfig:"DATABASE"`
// AuditDatabase configures the audit database
AuditDatabase AuditDatabaseCredentialsEnvironmentConfig `envconfig:"AUDIT_DATABASE"`
// DatabaseConfig configures the database connection config
DatabaseConfig DatabaseEnvironmentConfig `envconfig:"DATABASE_CONFIG"`
GlobalRedis GlobalRedisCredentialsEnvironmentConfig `envconfig:"REDIS"`
// RedisConfig configures the redis connection config
RedisConfig RedisEnvironmentConfig `envconfig:"REDIS_CONFIG"`
ImagesCDNHost ImagesCDNHost `envconfig:"IMAGES_CDN_HOST"`
WebAppCDNHost WebAppCDNHost `envconfig:"WEB_APP_CDN_HOST"`
// CORSAllowOrigins configures a comma-separated list of allowed origins for CORSMiddleware
CORSAllowedOrigins CORSAllowedOrigins `envconfig:"CORS_ALLOWED_ORIGINS"`
NFTIndexerAPIEndpoint NFTIndexerAPIEndpoint `envconfig:"NFT_INDEXER_API_ENDPOINT"`
DenoEndpoint DenoEndpoint `envconfig:"DENO_ENDPOINT"`
RateLimits RateLimitsEnvironmentConfig `envconfig:"RATE_LIMITS"`
// AppHostSuffixes originates from the portal config.
AppHostSuffixes AppHostSuffixes `envconfig:"APP_HOST_SUFFIXES"`
// End2EndHTTPProxy sets the HTTP proxy for end-to-end tests
End2EndHTTPProxy string `envconfig:"E2E_HTTP_PROXY"`
// End2EndTLSCACertFile sets additional CA certificate for end-to-end tests
End2EndTLSCACertFile string `envconfig:"E2E_TLS_CA_CERT_FILE"`
}