mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-09 03:48:33 +03:00
Compare commits
1 Commits
feature/js
...
v0.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9eb6ea6e2 |
19
.github/workflows/cd.yml
vendored
19
.github/workflows/cd.yml
vendored
@@ -1,19 +0,0 @@
|
||||
name: CD
|
||||
on:
|
||||
push:
|
||||
branches: [ develop ]
|
||||
# pull_request:
|
||||
# branches: [ develop ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Trigger CD build
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
with:
|
||||
token: ${{ secrets.CI_DISPATCH_TOKEN }}
|
||||
repository: forensic-architecture/configs
|
||||
event-type: remote-build
|
||||
client-payload: '{"runtime_args": "datasheet", "branch": "${GITHUB_REF##*/}"}'
|
||||
|
||||
25
.github/workflows/ci.yml
vendored
25
.github/workflows/ci.yml
vendored
@@ -1,25 +0,0 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [ develop ]
|
||||
pull_request:
|
||||
branches: [ develop ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
- uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: '12'
|
||||
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
env:
|
||||
CI: true
|
||||
- run: npm run lint
|
||||
env:
|
||||
CI: true
|
||||
14
.travis.yml
Normal file
14
.travis.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
before_script:
|
||||
- npm install -g yarn
|
||||
install:
|
||||
- yarn
|
||||
script:
|
||||
- yarn build
|
||||
- yarn lint
|
||||
- yarn test
|
||||
@@ -13,8 +13,8 @@ RUN yarn build
|
||||
RUN mkdir -p data
|
||||
|
||||
# set your port
|
||||
ENV PORT 4040
|
||||
EXPOSE 4040
|
||||
ENV PORT 8080
|
||||
EXPOSE 8080
|
||||
|
||||
# start command as per package.json
|
||||
CMD ["yarn", "start"]
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,6 @@
|
||||
"version": "0.3.0",
|
||||
"description": "Starter project for an ES6 RESTful Express API",
|
||||
"main": "dist",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "env NODE_ENV=development nodemon -w src --exec \"babel-node src\"",
|
||||
"build": "env NODE_ENV=production npx babel src -d dist",
|
||||
@@ -27,7 +26,6 @@
|
||||
"express": "^4.13.3",
|
||||
"express-graphql": "^0.6.12",
|
||||
"express-handlebars": "^4.0.4",
|
||||
"file-system": "^2.2.2",
|
||||
"googleapis": "^39.1.0",
|
||||
"graphql": "^0.13.2",
|
||||
"morgan": "^1.8.0",
|
||||
|
||||
11
scripts/check-branch.sh
Executable file
11
scripts/check-branch.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
ENCRYPT_MESSAGE="\nThe .env.enc file has not changed its contents from the version on origin/develop.\nTo ensure that tests pass in Travis, you need to encrypt the contents of .env before pushing to the remote, so that the Travis server can use your service account credentials.\nEnsure that the Travis CLI is installed on your local, run\n\n\tnpm run travis-encrypt\n\nand then push to the remote again.\nIf you don't care whether your build passes on Travis, you can run:\n\n\tgit push --no-verify\n\nand bypass this check.\n\n"
|
||||
|
||||
# check whether .env.enc has changed
|
||||
if [ -z "`git diff origin/develop -- .env.enc`" ]; then
|
||||
echo $ENCRYPT_MESSAGE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
38
scripts/encrypt.sh
Executable file
38
scripts/encrypt.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
echo "Encrypting .env file for Travis..."
|
||||
|
||||
# confirm that the user has the core repo as origin, and is therefore a maintainer
|
||||
# if [ -z `git config --get remote.origin.url | grep "forensic-architecture/datasheet-server"` ]; then
|
||||
# echo "Travis encryption not required for satellite contributors, continuing.."
|
||||
# exit 0
|
||||
# fi
|
||||
|
||||
# confirm travis is installed
|
||||
if [ ! hash travis 2>/dev/null ]; then
|
||||
echo "============================================================================================"
|
||||
echo "ERROR: Travis CLI is not installed on your local. Please install from:"
|
||||
echo "\thttps://github.com/travis-ci/travis.rb"
|
||||
echo "After installing, make sure that you login with:"
|
||||
echo "\ttravis login --pro"
|
||||
echo "============================================================================================"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# confirm there is a .env file to encrypt
|
||||
if [ ! -f .env ]; then
|
||||
echo "============================================================================================"
|
||||
echo "ERROR: You must create a .env file and add your credentials. See .env.example for an example"
|
||||
echo "============================================================================================"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# regex to match and delete 'before_install' and everything after it
|
||||
# necessary to delete these lines to get Travis to build for multiple accounts
|
||||
echo "creating new .travis.yml configuration"
|
||||
sed -i.old '/^before_install.*/,$ d' .travis.yml
|
||||
echo "old config file saved as .travis.yml.old"
|
||||
|
||||
travis encrypt-file .env --add --force --org
|
||||
git add .env.enc
|
||||
git add .travis.yml
|
||||
echo ".env.enc created and added to commit"
|
||||
@@ -4,7 +4,6 @@ import copy from '../copy/en'
|
||||
|
||||
export default ({ config, controller }) => {
|
||||
let api = Router()
|
||||
const fileDest = config.EXPORT_FILE_DEST || null
|
||||
|
||||
api.get('/', (req, res) => {
|
||||
res.json({
|
||||
@@ -23,20 +22,6 @@ export default ({ config, controller }) => {
|
||||
})
|
||||
})
|
||||
|
||||
api.get('/export', (req, res) => {
|
||||
controller
|
||||
.retrieveAll(fileDest)
|
||||
.then(msg =>
|
||||
res.json({
|
||||
success: msg
|
||||
})
|
||||
)
|
||||
.catch(err =>
|
||||
res.status(404)
|
||||
.send({ error: err.message, err })
|
||||
)
|
||||
})
|
||||
|
||||
api.get('/update', (req, res) => {
|
||||
controller
|
||||
.update()
|
||||
|
||||
@@ -63,7 +63,10 @@ export default (data) => {
|
||||
structure.__flat.forEach(label => {
|
||||
deepRow[label] = baseRow[label]
|
||||
})
|
||||
if (!Object.keys(deepRow).every(k => deepRow[k] === '')) {
|
||||
if (!Object.keys(deepRow).every(k => (
|
||||
(deepRow[k] === '') ||
|
||||
(Array.isArray(deepRow[k]) && deepRow[k].length === 0)
|
||||
))) {
|
||||
output.push(deepRow)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
export default {
|
||||
errors: {
|
||||
update: 'The server could not update. Check your API credentials and internet connection and try again.',
|
||||
export: {
|
||||
fileMissing: 'The server could not export. Check that you provided a file path to export to and try again.',
|
||||
writeFailed: 'The server could not export the data to the file. There is an issue with the data format'
|
||||
},
|
||||
onlySheet: 'You cannot query a sheet directly. The URL needs to be in the format /:sheet/:tab/:resource.',
|
||||
onlyTab: 'You cannot query a tab directly. The URL needs to be in the format /:sheet/:tab/:resource.',
|
||||
noSheet: sheet => `The sheet ${sheet} is not available in this server.`,
|
||||
@@ -13,7 +9,6 @@ export default {
|
||||
modelLayer: prts => `Something went wrong at the model layer`
|
||||
},
|
||||
success: {
|
||||
update: 'All sheets updated',
|
||||
export: dest => `All resources exported to the file: ${dest}`
|
||||
update: 'All sheets updated'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import copy from '../copy/en'
|
||||
import { exportToFile } from '../lib/util'
|
||||
|
||||
/**
|
||||
* Controller
|
||||
@@ -40,37 +39,6 @@ class Controller {
|
||||
})
|
||||
}
|
||||
|
||||
// Controller function to retrieve all blueprints and export to user defined file location
|
||||
retrieveAll (fileDest) {
|
||||
if (!fileDest) return Promise.reject(new Error(copy.errors.export.fileMissing))
|
||||
|
||||
const indexedData = {}
|
||||
const urls = []
|
||||
|
||||
const bps = this.blueprints()
|
||||
return Promise.all(
|
||||
bps.map(bp => {
|
||||
const resource = Object.keys(bp.resources)[0]
|
||||
urls.push(bp.urls[0])
|
||||
return this.retrieve(bp.sheet.name, bp.name, resource)
|
||||
})
|
||||
).then(async results => {
|
||||
if (results.every(res => res)) {
|
||||
urls.forEach((item, idx) => {
|
||||
indexedData[item] = results[idx]
|
||||
})
|
||||
try {
|
||||
const message = await exportToFile(fileDest, indexedData)
|
||||
return message
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
} else {
|
||||
throw new Error(copy.errors.export.writeFailed)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
retrieve (sheet, tab, resource) {
|
||||
if (this._sheetExists(sheet)) {
|
||||
const fetcher = this.fetchers[sheet]
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import R from 'ramda'
|
||||
import { promises as fs } from 'file-system'
|
||||
import copy from '../copy/en'
|
||||
|
||||
/* eslint-disable */
|
||||
String.prototype.replaceAll = function (search, replacement) {
|
||||
@@ -16,18 +14,6 @@ function camelize (str) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function exportToFile (fileDest, data) {
|
||||
const stringifiedData = JSON.stringify(data, null, 2)
|
||||
const filePath = `${fileDest}/export.json`
|
||||
|
||||
try {
|
||||
await fs.writeFile(filePath, stringifiedData)
|
||||
return copy.success.export(filePath)
|
||||
} catch (err) {
|
||||
throw new Error(copy.errors.export.writeFailed)
|
||||
}
|
||||
}
|
||||
|
||||
export const fmtObj = R.curry(
|
||||
(
|
||||
columnNames,
|
||||
|
||||
@@ -54,7 +54,7 @@ test('should launch', t => {
|
||||
})
|
||||
|
||||
const passUrls = [
|
||||
'/api/'
|
||||
'/api/',
|
||||
]
|
||||
|
||||
const failUrls = [
|
||||
|
||||
Reference in New Issue
Block a user