-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathenvSchema.js
194 lines (163 loc) · 6.81 KB
/
envSchema.js
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
const Joi = require('joi')
const ExtendedJoi = Joi.extend((joi) => ({
type: 'json',
base: joi.object(),
messages: {
'json.invalid': '"{{#label}}" has invalid JSON format',
},
coerce(value, helpers) {
try {
return { value: JSON.parse(value) }
} catch (ignoreErr) {
return { value, errors: helpers.error('json.invalid') }
}
},
}))
/* eslint-disable prettier/prettier */
const OAUTH2_STR = Joi.string().when('OAUTH2_BYPASS_SSO', {
is: false,
then: Joi.required(),
})
const OAUTH2_URI = Joi.string()
.uri()
.when('OAUTH2_BYPASS_SSO', { is: false, then: Joi.required() })
const envSchema = Joi.object({
// A mapping of { duns_number: url, .. } for the companies that have account plans
ACCOUNT_PLAN_URLS: ExtendedJoi.json().default({}),
// The url for a back end server instance for the service
API_ROOT: Joi.string().uri().required(),
// If running a server with OAUTH2_BYPASS_SSO=true then this can be used in
// conjunction with a password to setup basic HTTP auth to protect the server
BASIC_AUTH_USER: Joi.string(),
// Used in conjunction with BASIC_AUTH_USER to setup security for the server
BASIC_AUTH_PASSWORD: Joi.string(),
// Turn on caching for Nunjucks templates
CACHE_ASSETS: Joi.bool(),
// Long term cache duration, usually used to store metadata
CACHE_DURATION_LONG: Joi.number().integer().default(1000),
// Short term cache duration
CACHE_DURATION_SHORT: Joi.number().integer().default(100),
// Set to true for UAT testing, otherwise ignore
CI: Joi.bool(),
// Identifier of a Hawk key required to access the backend metadata endpoints
DATA_HUB_BACKEND_ACCESS_KEY_ID: Joi.string().required(),
// Secret Hawk key required to access the backend metadata endpoints
DATA_HUB_BACKEND_SECRET_ACCESS_KEY: Joi.string().required(),
// getAddress.io service for postcode lookup
DATA_STORE_SERVICE_POSTCODE: Joi.string().required(),
// Url to Data Workspace app
DATA_WORKSPACE_URL: Joi.string().uri(),
// Url to Find Exporters app
FIND_EXPORTERS_URL: Joi.string().uri(),
// Force using an HTTPS connection
FORCE_HTTPS: Joi.when('NODE_ENV', {
is: 'production',
then: Joi.bool().default(true),
otherwise: Joi.bool().default(false),
}),
// Current version of the app which contains a Git tag.
// See https://github.com/uktrade/ci-pipeline/blob/master/Jenkinsfile#L299
GIT_BRANCH: Joi.string().default('unknown'),
// The key needed to integrate with Google Tag Manager to track usage
GOOGLE_TAG_MANAGER_KEY: Joi.string(),
// Help centre announcements url
HELP_CENTRE_ANNOUNCMENTS_URL: Joi.string().uri().required(),
// Help centre feed API url
HELP_CENTRE_API_FEED: Joi.string().uri().required(),
// Help centre API Hawk Auth ID
HELP_CENTRE_ACCESS_KEY_ID: Joi.string().required(),
// Help centre API Hawk Auth Key
HELP_CENTRE_SECRET_ACCESS_KEY: Joi.string().required(),
// Help centre url
HELP_CENTRE_URL: Joi.string().uri().required(),
// How much logging to output
LOG_LEVEL: Joi.string()
.valid('error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly')
.default('error'),
// Url to Market access app
MARKET_ACCESS_URL: Joi.string().uri(),
// How long to store dropdown data etc for, in seconds. Defaults to 15 minutes
METADATA_TTL: Joi.number()
.integer()
.default(15 * 60),
// Whether to run the app in dev mode. Set to `production` in production, otherwise don't set for dev behaviour
NODE_ENV: Joi.string()
.valid('production', 'development', 'test')
.default('production'),
// If a developer wishes to bypass OAuth locally then set this to true
OAUTH2_BYPASS_SSO: Joi.bool().default(false),
// Token used for working with OAuth locally whilst developing. This token is
// also used with CircleCi for providing user with different permissions.
// Used only when OAUTH2_BYPASS_SSO is TRUE
OAUTH2_DEV_TOKEN: Joi.string().when('OAUTH2_BYPASS_SSO', {
is: true,
then: Joi.required(),
}),
// OAuth auth url
OAUTH2_AUTH_URL: OAUTH2_STR,
// OAuth client ID
OAUTH2_CLIENT_ID: OAUTH2_STR,
// OAuth client secret
OAUTH2_CLIENT_SECRET: OAUTH2_STR,
// Location where user will be redirected to after logging out
OAUTH2_LOGOUT_URL: OAUTH2_URI,
// OAuth callback url
OAUTH2_REDIRECT_URL: OAUTH2_URI,
// OAuth fetch token url
OAUTH2_TOKEN_FETCH_URL: OAUTH2_URI,
// OAuth user profile url
OAUTH2_USER_PROFILE_URL: OAUTH2_URI,
// Email address to the team responsible for changes to the One List companies
ONE_LIST_EMAIL: Joi.string().required(),
// Port on which the app runs
PORT: Joi.number().port().default(3000),
// Token used for address search from https://getaddress.io/
POSTCODE_KEY: Joi.string().required(),
// URL of a proxy to use to contact the API through. Useful for debugging
PROXY: Joi.string().uri(),
// You need to run redis and provide the host name for it here unless you
// specify the entire url
REDIS_HOST: Joi.string().alphanum().default('redis'),
// Redis port
REDIS_PORT: Joi.number().port().default(6379),
// A full length url to connect to redis
REDIS_URL: Joi.string().uri(),
// Whether Redis is proxied through stunnel or not
REDIS_USE_TLS: Joi.bool(),
// Sentry DSN
SENTRY_DSN: Joi.string().uri(),
// Environment name used by Sentry
SENTRY_ENVIRONMENT: Joi.string(),
// String to encrypt session data with
SESSION_SECRET: Joi.string().required(),
// How long the user session lasts, in millis. Defaults to 2 hours
SESSION_TTL: Joi.number()
.integer()
.default(2 * 60 * 60 * 1000),
// Zendesk field ID used to capture user's browser
ZEN_BROWSER: Joi.string(),
// Zendesk username used for API queries
ZEN_EMAIL: Joi.string().required(),
// Zendesk field ID used to service
ZEN_SERVICE: Joi.string(),
// Zendesk field value for service field
ZEN_SERVICE_CHANNEL: Joi.string().default('datahub'),
// Zendesk endpoint used to create support tickets
ZEN_TICKETS_URL: Joi.string().uri().required(),
// Zendesk token used for API queries
ZEN_TOKEN: Joi.string().required(),
// Elastic APM service name used to label the service you want to monitor
ELASTIC_APM_SERVICE_NAME: Joi.string().default('datahub-fe'),
// Elastic APM server url is where you host the monitoring of transactions
ELASTIC_APM_SERVER_URL: Joi.string().uri().required(),
// Elastic APM secret token used to authenticate the service
ELASTIC_APM_SECRET_TOKEN: Joi.string().required(),
// Elastic APM server timeout used to timeout if no response is found after 20 secs
ELASTIC_APM_SERVER_TIMEOUT: Joi.number().integer().default(20),
// The S3 bucket for investment evidence documents
INVESTMENT_DOCUMENT_BUCKET: Joi.string().required(),
// The S3 region for investment evidence documents
INVESTMENT_DOCUMENT_AWS_REGION: Joi.string().required(),
})
/* eslint-enable prettier/prettier */
module.exports = envSchema