mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-10 04:18:31 +03:00
* new server test with precommit hook to secure .env files, set up CI environment (#3) * [TESTS] added all registered routes to api server test * [WIP] abstracting config to env where it makes sense, refactoring elsewhere, adding more tests * [WIP] fixed tests so they fail as expected * [WIP] * [DEBUG] fixed issues with the env configuration, added correct tests * [MISC] env didn't get readded on last precommit * [TESTS] added longer wait time for server as sometimtimes tests fail arbitrarily
47 lines
1.4 KiB
JavaScript
Executable File
47 lines
1.4 KiB
JavaScript
Executable File
import StoreJson from './models/StoreJson'
|
|
import Fetcher from './lib/Fetcher'
|
|
import Controller from './lib/Controller'
|
|
import sheetsConfig from './sheets_config'
|
|
|
|
const { googleSheets } = sheetsConfig
|
|
const { sheets } = googleSheets
|
|
|
|
function authenticate (_fetcher) {
|
|
return _fetcher.fetcher.authenticate(process.env.SERVICE_ACCOUNT_EMAIL, process.env.SERVICE_ACCOUNT_PRIVATE_KEY).then(msg => {
|
|
console.log(msg)
|
|
return true
|
|
})
|
|
}
|
|
|
|
export default callback => {
|
|
const fetchers = sheets.map(sheet => {
|
|
return {
|
|
name: sheet.name,
|
|
fetcher: new Fetcher(new StoreJson(), sheet.name, sheet.id, sheet.tabs)
|
|
}
|
|
})
|
|
|
|
Promise.all(fetchers.map(authenticate))
|
|
.then(() => {
|
|
console.log(`===================`)
|
|
console.log(`grant access to: ${process.env.SERVICE_ACCOUNT_EMAIL}`)
|
|
console.log(`===================`)
|
|
|
|
// NB: reformat fetchers as config for controller
|
|
const config = {}
|
|
fetchers.forEach(fetcher => {
|
|
config[fetcher.name] = fetcher.fetcher
|
|
})
|
|
const controller = new Controller(config)
|
|
callback(controller)
|
|
})
|
|
.catch(err => {
|
|
console.log(err)
|
|
console.log(
|
|
`ERROR: the server couldn't connect to all of the sheets you provided. Ensure you have granted access to ${
|
|
process.env.SERVICE_ACCOUNT_EMAIL
|
|
} on ALL listed sheets.`
|
|
)
|
|
})
|
|
}
|