-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall.py
410 lines (393 loc) · 15.3 KB
/
install.py
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
"""Configuration options that affect an entire instance of Codecov"""
import logging
from shared.utils.enums import TaskConfigGroup
from shared.validation.user_schema import schema as user_yaml_schema
from shared.validation.validator import CodecovYamlValidator
log = logging.getLogger(__name__)
def check_task_config_key(field, value, error):
if value == "celery":
return
if value in set(group.value for group in TaskConfigGroup):
return
error(field, "Not a valid TaskConfigGroup")
# Bot is a git provider account configured to be used in place of another
bot_details_fields = {
# This is a PAT for some provider account that is going to be used as a bot
"key": {"type": "string", "required": True},
# This is used only for Bitbucket (uses Oauth1)
"secret": {"type": "string"},
# Identifies the bot in the logs
"username": {"type": "string"},
}
# Credentials used by the OAuth App used when logging into Codecov UI
# note: the OAuth App acts in behalf of the user. The user will need to authorize it
# and enter user's own credentials for logging into the git provider
oauth_credential_fields = {
"client_id": {"type": "string"},
"client_secret": {"type": "string"},
# The URI to redirect the user after authorization is granted to the OAuth App
"redirect_uri": {"type": "string"},
}
# Default app [GitHub exclusive] - Credentials for a GitHub app used by this installation
# note: these credentials are used to get access_tokens for installations
GitHub_app_fields = {
"expires": {"type": "integer"},
"id": {"type": "integer", "required": True},
"pem": {"type": ["string", "dict"], "required": True},
}
default_service_fields = {
"verify_ssl": {"type": "boolean"},
"ssl_pem": {"type": "string"},
**oauth_credential_fields,
"url": {"type": "string"},
"api_url": {"type": "string"},
# bot [enterprise (self-hosted)] - Bot that is used for all repos belonging to a given service.
# bot [cloud] - Used as public bot fallback if bots.tokenless is not provided.
"bot": {
"type": "dict",
"schema": bot_details_fields,
},
# global_upload_token [enterprise (self-hosted)] - Master upload token.
# Any upload (for any repo) made to the instance using this token will be validated.
"global_upload_token": {"type": "string"},
"organizations": {"type": "list", "schema": {"type": "string"}},
"webhook_secret": {"type": "string"},
# bots - Function-specific bots used as fallbacks for public repos
# Certain functions in the torngit adapter will use one of these tokens if none is present.
# 'bots.tokenless' is the default fallback
"bots": {
"type": "dict",
"schema": {
"read": {
"type": "dict",
"schema": bot_details_fields,
},
"comment": {
"type": "dict",
"schema": bot_details_fields,
},
"status": {
"type": "dict",
"schema": bot_details_fields,
},
"tokenless": {
"type": "dict",
"schema": bot_details_fields,
},
},
},
}
enterprise_queue_fields = {
"type": "dict",
"schema": {
"soft_timelimit": {"type": "integer"},
"hard_timelimit": {"type": "integer"},
},
}
default_task_fields = {
"queue": {"type": "string"},
"timeout": {"type": "integer"},
"interval_seconds": {
"type": "integer",
"min": 0,
},
"enterprise": {**enterprise_queue_fields},
}
config_schema = {
"setup": {
"type": "dict",
"schema": {
"cache": {
"type": "dict",
"schema": {
"chunks": {"type": "integer"},
"diff": {"type": "integer"},
"tree": {"type": "integer"},
"uploads": {"type": "integer"},
"yaml": {"type": "integer"},
},
},
"legacy_report_style": {"type": "boolean"},
"loglvl": {"type": "string", "allowed": ("INFO",)},
"max_sessions": {"type": "integer"},
"debug": {"type": "boolean"},
"codecov_url": {"type": "string"},
"codecov_api_url": {"type": "string"},
"webhook_url": {"type": "string"},
"api_cors_allowed_origins": {"type": "string"},
"codecov_dashboard_url": {"type": "string"},
"enterprise_license": {"type": "string"},
"hide_all_codecov_tokens": {"type": "boolean"},
"admins": {
"type": "list",
"schema": {
"type": "dict",
"schema": {
"service": {"type": "string"},
"username": {"type": "string"},
},
},
},
"api_allowed_hosts": {"type": "list", "schema": {"type": "string"}},
"secure_cookie": {"type": "boolean"},
"pubsub": {
"type": "dict",
"schema": {
"project_id": {"type": "string"},
"topic": {"type": "string"},
"enabled": {"type": "boolean"},
},
},
"marketo": {
"type": "dict",
"schema": {
"client_id": {"type": "string"},
"client_secret": {"type": "string"},
"base_url": {"type": "string"},
"enabled": {"type": "boolean"},
},
},
"http": {
"type": "dict",
"schema": {
"timeouts": {
"type": "dict",
"schema": {
"external": {"type": "integer"},
"connect": {"type": "integer"},
"receive": {"type": "integer"},
},
},
"cookie_secret": {"type": "string"},
"force_https": {"type": "boolean"},
},
},
"encryption_secret": {"type": "string"},
"encryption": {
"type": "dict",
"schema": {
"keys": {
"type": "list",
"schema": {
"type": "dict",
"schema": {
"code": {"type": "string"},
"value": {"type": "string"},
},
},
},
"yaml_secret": {"type": "string"},
"write_key": {"type": "string"},
},
},
"media": {
"type": "dict",
"schema": {
"assets": {"type": "string"},
"dependancies": {"type": "string"},
},
},
"tasks": {
"type": "dict",
"keysrules": {"type": "string", "check_with": check_task_config_key},
"valuesrules": {
"type": "dict",
"oneof": [
# Regular tasks config
{"schema": {**default_task_fields}},
# Special value for 'celery' key
{
"schema": {
"default_queue": {"type": "string"},
"acks_late": {"type": "boolean"},
"prefetch": {"type": "integer"},
"soft_timelimit": {"type": "integer"},
"hard_timelimit": {"type": "integer"},
"enterprise": {**enterprise_queue_fields},
"worker_max_memory_per_child": {"type": "integer"},
}
},
],
},
},
"upload_processing_delay": {"type": "integer"},
"skip_feature_cache": {"type": "boolean"},
"timeseries": {
"type": "dict",
"schema": {"enabled": {"type": "boolean"}},
},
"telemetry": {
"type": "dict",
"schema": {
"enabled": {"type": "boolean"},
"admin_email": {"type": "string"},
"anonymous": {"type": "boolean"},
"endpoint_override": {"type": "string"},
},
},
"health_check": {
"type": "dict",
"schema": {
"enabled": {"type": "boolean"},
},
},
"push_webhook_ignore_repo_names": {
"type": "list",
"schema": {"type": "string"},
},
# guest_access [enterprise (self-hosted)] - Wether to allow non-logged in users to access the UI in this Codecov instance
"guest_access": {"type": "boolean"},
},
},
"services": {
"type": "dict",
"schema": {
"external_dependencies_folder": {"type": "string"},
"google_analytics_key": {"type": "string"},
"minio": {
"type": "dict",
"schema": {
"host": {"type": "string"},
"port": {"type": "integer"},
"hash_key": {"type": "string"},
"iam_auth": {"type": "boolean"},
"iam_endpoint": {"type": "string", "nullable": True},
"access_key_id": {"type": "string"},
"secret_access_key": {"type": "string"},
"bucket": {"type": "string"},
"region": {"type": "string"},
"expire_raw_after_n_days": {"type": "boolean"},
"periodic_callback_ms": {"type": ("boolean", "integer")},
"verify_ssl": {"type": "boolean"},
},
},
"gcp": {
"type": "dict",
"schema": {"google_credentials_location": {"type": "string"}},
},
"aws": {
"type": "dict",
"schema": {
"region_name": {"type": "string"},
"resource": {"type": "string"},
},
},
"chosen_storage": {"type": "string"},
"database_url": {"type": "string"},
"timeseries_database_url": {"type": "string"},
"database": {
"type": "dict",
"schema": {"conn_max_age": {"type": "integer"}},
},
"redis_url": {"type": "string"},
"github_marketplace": {
"type": "dict",
"schema": {"use_stubbed": {"type": "boolean"}},
},
"stripe": {"type": "dict", "schema": {"api_key": {"type": "string"}}},
"celery_broker": {"type": "string"},
"gravatar": {"type": "boolean"},
"avatars.io": {"type": "boolean"},
"sentry": {"type": "dict", "schema": {"server_dsn": {"type": "string"}}},
"ci_providers": {"type": ["string", "list"], "schema": {"type": "string"}},
"notifications": {
"type": "dict",
"schema": {
"slack": {
"type": ["boolean", "list"],
"schema": {"type": "string"},
},
"gitter": {
"type": ["boolean", "list"],
"schema": {"type": "string"},
},
"email": {
"type": ["boolean", "list"],
"schema": {"type": "string"},
},
"webhook": {
"type": ["boolean", "list"],
"schema": {"type": "string"},
},
"irc": {"type": ["boolean", "list"], "schema": {"type": "string"}},
"hipchat": {
"type": ["boolean", "list"],
"schema": {"type": "string"},
},
},
},
"vsc_cache": {
"type": "dict",
"schema": {
"enabled": {"type": "boolean"},
"metrics_app": {"type": "string"},
"check_duration": {"type": "integer"},
"compare_duration": {"type": "integer"},
"status_duration": {"type": "integer"},
},
},
"smtp": {
"type": "dict",
"schema": {
"host": {"type": "string"},
"port": {"type": "integer"},
"username": {"type": "string", "required": False},
"password": {"type": "string", "required": False},
},
"required": False,
},
},
},
"site": {"type": "dict", "schema": user_yaml_schema},
"additional_user_yamls": {
"type": "list",
"schema": {
"type": "dict",
"schema": {
"percentage": {"type": "integer"},
"name": {"type": "string"},
"override": {"type": "dict", "schema": user_yaml_schema},
},
},
},
"github": {
"type": "dict",
"schema": {
**default_service_fields,
# integration - Credentials for the default Codecov App
"integration": {
"type": "dict",
"schema": GitHub_app_fields,
},
# dedicated_apps - Dedicated apps are used in specific tasks.
# They can have a different set of permissions than the default Codecov App, allowing us to provide different opt-in services
"dedicated_apps": {
"type": "dict",
"valuesrules": {"type": "dict", "schema": GitHub_app_fields},
},
},
},
"bitbucket": {"type": "dict", "schema": {**default_service_fields}},
"bitbucket_server": {"type": "dict", "schema": {**default_service_fields}},
"github_enterprise": {"type": "dict", "schema": {**default_service_fields}},
"gitlab": {"type": "dict", "schema": {**default_service_fields}},
"gitlab_enterprise": {"type": "dict", "schema": {**default_service_fields}},
"compatibility": {
"type": "dict",
"schema": {"flag_pattern_matching": {"type": "boolean"}},
},
"migrations": {"type": "dict", "schema": {"skip_risky_steps": {"type": "boolean"}}},
}
def pre_process_config(inputted_dict):
# TODO: Add user yaml preprocess to here
pass
def validate_install_configuration(inputted_dict):
pre_process_config(inputted_dict)
validator = CodecovYamlValidator(show_secret=True)
is_valid = validator.validate(inputted_dict, config_schema)
if not is_valid:
log.debug(
"Configuration considered invalid, using dict as it is",
extra=dict(errors=validator.errors),
)
return validator.document