-
Notifications
You must be signed in to change notification settings - Fork 41
/
config.js
104 lines (100 loc) · 3.89 KB
/
config.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
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license.
// SPDX-License-Identifier: MIT
const config = require('painless-config')
const { get } = require('lodash')
const providers = require('../providers')
/**
* Loads the given factory for the indicated namespace. The namespace can be a subcomponent
* of the providers module (e.g., search or store). The `spec` is the name of a module (e.g.,
* file, memory, mongo) and an optional object path within that module that leads to the
* desired factory.
* Dispatch to multiple with + (e.g. spec=dispatch+mongo+azblob)
* @param {*} spec - indicator of the module and factory to load
* @param {*} namespace - an optional place to look for built in factories
*/
function loadFactory(spec, namespace) {
const names = spec.split('+')
const factory = loadOne(names[0], namespace)
const factories = names.slice(1).map(name => loadOne(name, namespace))
if (factories.length) {
return () => factory({ factories })
}
return factory
}
function loadOne(spec, namespace) {
const [requirePath, objectPath] = spec.split('|')
const getPath = (namespace ? namespace + '.' : '') + requirePath
let target = get(providers, getPath)
try {
if (!target) target = require(requirePath)
return objectPath ? get(target, objectPath) : target
} catch (e) {
throw new Error(`could not load provider for ${requirePath}`)
}
}
module.exports = {
summary: {},
logging: {
logger: loadFactory(config.get('LOGGING_PROVIDER') || 'winston', 'logging')
},
curation: {
queue: loadFactory(config.get('CURATION_QUEUE_PROVIDER') || 'memory', 'curation.queue'),
service: loadFactory(config.get('CURATION_PROVIDER') || 'github', 'curation.service'),
store: loadFactory(config.get('CURATION_STORE_PROVIDER') || 'memory', 'curation.store')
},
harvest: {
queue: loadFactory(config.get('HARVEST_QUEUE_PROVIDER') || 'memory', 'harvest.queue'),
service: loadFactory(config.get('HARVESTER_PROVIDER') || 'crawler', 'harvest.service'),
store: loadFactory(config.get('HARVEST_STORE_PROVIDER') || 'file', 'harvest.store')
},
aggregator: {
precedence: [['clearlydefined', 'reuse', 'licensee', 'scancode', 'fossology', 'cdsource']]
},
definition: {
store: loadFactory(config.get('DEFINITION_STORE_PROVIDER') || 'file', 'definition')
},
attachment: {
store: loadFactory(config.get('ATTACHMENT_STORE_PROVIDER') || 'file', 'attachment')
},
auth: {
service: loadFactory(config.get('AUTH_PROVIDER') || 'github', 'auth')
},
caching: {
service: loadFactory(config.get('CACHING_PROVIDER') || 'memory', 'caching'),
caching_redis_service: config.get('CACHING_REDIS_SERVICE'),
caching_redis_api_key: config.get('CACHING_REDIS_API_KEY')
},
endpoints: {
service: config.get('SERVICE_ENDPOINT') || 'http://localhost:4000',
website: config.get('WEBSITE_ENDPOINT') || 'http://localhost:3000'
},
limits: {
windowSeconds: parseInt(config.get('RATE_LIMIT_WINDOW')) || 1,
max: parseInt(config.get('RATE_LIMIT_MAX')) || 0,
batchWindowSeconds: parseInt(config.get('BATCH_RATE_LIMIT_WINDOW')) || 1,
batchMax: parseInt(config.get('BATCH_RATE_LIMIT_MAX')) || 0
},
webhook: {
githubSecret:
config.get('WEBHOOK_GITHUB_SECRET') ||
(() => {
throw new Error('WEBHOOK_GITHUB_SECRET is required')
})(),
crawlerSecret:
config.get('WEBHOOK_CRAWLER_SECRET') ||
(() => {
throw new Error('WEBHOOK_CRAWLER_SECRET is required')
})()
},
search: {
service: loadFactory(config.get('SEARCH_PROVIDER') || 'memory', 'search')
},
insights: {
serviceId: config.get('APPINSIGHTS_SERVICE_APPLICATIONID'),
serviceKey: config.get('APPINSIGHTS_SERVICE_APIKEY'),
crawlerId: config.get('APPINSIGHTS_CRAWLER_APPLICATIONID'),
crawlerKey: config.get('APPINSIGHTS_CRAWLER_APIKEY')
},
appVersion: config.get('APP_VERSION'),
buildsha: config.get('BUILD_SHA')
}