Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/random data provider #42

Merged
merged 58 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
86fbbad
Ignoring IntelliJ conf for convenience
May 29, 2019
37077de
Benchmark implementation for the tests
May 29, 2019
03afcf5
Bugfix of naive implementation + refactor suggestions
May 30, 2019
a355220
Implemented a working fallback random.org provider. It's untested and…
May 30, 2019
1fecf73
Passing value bounds from request, cleaned up request format to 'rand…
May 31, 2019
9d66a28
Test adjust
May 31, 2019
1b4e167
Naming adjust
May 31, 2019
ac8cc81
Moved random.org api key to .env
May 31, 2019
d8851f3
Random.org integration tests
May 31, 2019
9daae9f
Minor refactor + better error handling
Jun 3, 2019
41efe36
Removed redundant method
Jun 3, 2019
0d54d7a
Merge branch 'master' into feature/random-data-provider
Jun 12, 2019
b77ea26
Implemented SGX random data provider (not working yet, need to fix *.…
Jun 26, 2019
7dd5809
Merge branch 'master' into feature/random-data-provider
Jun 27, 2019
e9fa94b
Resolved conflicts and adjusted to changes in master
Jun 27, 2019
6deea52
Added NoSelectSelector tests
Jun 27, 2019
105f2d6
Added NoSelectSelector test
Jun 27, 2019
c69caa6
Moved stuff around and added exception if 'path' is unexpectedly prov…
Jun 27, 2019
c9e3d71
Added logging.
Jun 27, 2019
8e2623a
Merge branch 'bug/custom-errors-not-correctly-handled' into feature/r…
Jun 27, 2019
e6a4721
correctly implemented SGX dynamic libs
Jul 3, 2019
7bb92c1
refactored data fetchers to be more abstract
Jul 3, 2019
d8b4343
change some names that were incorrectly too concrete
Jul 3, 2019
7509d3c
Merge branch 'refactor/abstractonise-data-fetchers' into feature/rand…
Jul 3, 2019
79845f4
removed naste .gitignore entry
Jul 3, 2019
b1827db
Merge branch 'master' into refactor/abstractonise-data-fetchers
Jul 4, 2019
6a87ac2
added flag that imports paths from tsconfig
Jul 4, 2019
669b0d2
Merge branch 'bug/integration-test-error-after-ts-migration' into ref…
Jul 4, 2019
a406111
tslint fixes and fixed npm run tslint for Windows
Jul 4, 2019
d8bf615
adding a change that somehow was not merged from master
Jul 4, 2019
f2ec02c
Merge branch 'master' into refactor/abstractonise-data-fetchers
Jul 5, 2019
dbd673b
parameter rename that wsa not applied after TS migration
Jul 5, 2019
e71cf72
added files that were not referenced to index.ts, because tslint want…
Jul 5, 2019
bfb1f7b
implemented request executor factory
Jul 5, 2019
67a2ef8
moved request executor to domain
Jul 8, 2019
c914f9f
preinstalling both sgx and node in docker container
Jul 12, 2019
571c557
successfully integrated sgx lib using node-ffi
Jul 17, 2019
a092881
fixed peculiar tslint errors
Jul 17, 2019
1097e10
using request executors
Jul 18, 2019
da20813
using request executor
Jul 18, 2019
18a15e9
argument types
Jul 18, 2019
bd8832e
merged typescript migration from master
Jul 19, 2019
6b2cea1
making request executors aware of which contentTypes they can handle …
Jul 19, 2019
5157d03
Merge branch 'refactor/abstractonise-data-fetchers' into feature/rand…
Jul 19, 2019
01ac038
simplified request executor choosing + stylistic changes
Jul 19, 2019
3a95fc8
Merge branch 'refactor/abstractonise-data-fetchers' into feature/rand…
Jul 19, 2019
9e40809
removed response from request executor interface
Jul 22, 2019
04f297c
rename
Jul 22, 2019
8afdfed
fixed random.org error handling and added proper API key
Jul 22, 2019
308694f
moved sgx libs to separate dir
Jul 22, 2019
527fb56
rename
Jul 22, 2019
72c5b99
Merge branch 'refactor/abstractonise-data-fetchers' into feature/rand…
Jul 22, 2019
9302b2d
Merge branch 'master' into feature/random-data-provider
Jul 22, 2019
bab78c2
accept negative random bounds
Jul 22, 2019
a154cb8
moved test data to distinct location + other CR changes
Jul 23, 2019
d4541ab
more CR changes
Jul 23, 2019
201df56
consistent path naming
Jul 23, 2019
4d35fc3
Merge branch 'master' into feature/random-data-provider
Jul 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.bitbucket
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ API_PORT=3001
SAFE_BLOCK_DELAY=2
START_BLOCK=0
PERSISTENCE=INMEMORY
SGX_ENABLED=false
RANDOMDOTORG_API_KEY=ba3139ef-4f53-48fc-a7e8-af437005e09c

2 changes: 2 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ API_PORT=3001
SAFE_BLOCK_DELAY=2
START_BLOCK=0
PERSISTENCE=INMEMORY
SGX_ENABLED=false
RANDOMDOTORG_API_KEY=ba3139ef-4f53-48fc-a7e8-af437005e09c
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ API_PORT=3001
SAFE_BLOCK_DELAY=2
START_BLOCK=0
PERSISTENCE=INMEMORY
SGX_ENABLED=false
RANDOMDOTORG_API_KEY=ba3139ef-4f53-48fc-a7e8-af437005e09c
2 changes: 2 additions & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ API_PORT=3001
SAFE_BLOCK_DELAY=0
START_BLOCK=0
PERSISTENCE=INMEMORY
SGX_ENABLED=false
RANDOMDOTORG_API_KEY=ba3139ef-4f53-48fc-a7e8-af437005e09c
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ node_modules
logs/*
!logs/.gitkeep
/docs/_build/
dist
dist
17 changes: 16 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
FROM node:10.15
FROM sebvaucher/sgx-base:sgx_2.5

# Add SGX SDK libs to source. It does what 'source /opt/intel/sgxsdk/environment' does
ENV SGX_SDK /opt/intel/sgxsdk
ENV PATH=$SGX_SDK/bin:$SGX_SDK/bin/x64:$PATH \
PKG_CONFIG_PATH=$SGX_SDK/pkgconfig:$PKG_CONFIG_PATH \
LD_LIBRARY_PATH=$SGX_SDK/sdk_libs:./libs:$LD_LIBRARY_PATH

# Install nodejs dependencies
RUN apt-get update -q -q && \
apt-get install curl libssl1.0-dev --yes

# Install nodejs v11
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN npm install npm --global

# Create app directory
WORKDIR /usr/src/app
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ services:
- mongo
ports:
- ${API_PORT}:${API_PORT}
devices:
- /dev/isgx
- /dev/mei0
command: bash -c "./wait-for-it.sh mongo:27017 && npm start"
mongo:
container_name: oracle-db
Expand Down
Binary file added libs/Enclave.signed.so
Binary file not shown.
Binary file added libs/EnclaveWrapper.so
Binary file not shown.
Binary file added libs/libsgx_urts.so
Binary file not shown.
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
"dotenv": "6.0.0",
"execution-time": "1.3.0",
"express": "4.16.3",
"ffi": "2.3.0",
"jsonpath": "1.0.2",
"lodash": "4.17.11",
"mongoose": "5.3.12",
"node-schedule": "1.3.0",
"ref": "1.3.5",
"web3": "1.0.0-beta.36",
"web3-eth-contract": "1.0.0-beta.55",
"web3-utils": "1.0.0-beta.55",
Expand All @@ -59,8 +61,12 @@
"devDependencies": {
"@types/dotenv": "6.1.1",
"@types/express": "4.17.0",
"@types/ffi": "0.2.2",
"@types/jsonpath": "0.2.0",
"@types/lodash": "4.14.134",
"@types/mongoose": "5.5.6",
"@types/nock": "10.0.3",
"@types/ref": "0.0.28",
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"coveralls": "3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/application/dataFetcher/AxiosUrlDataFetcherAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Request from '@core/domain/request/Request';
import axios from 'axios';

import DataFetcher from '@core/domain/common/port/DataFetcherPort';
import { HttpError } from '@core/domain/common/utils/error';
import Request from '@core/domain/request/Request';
import RequestUrlParser from '@core/domain/request/RequestUrlParser';

class AxiosUrlDataFetcherAdapter implements DataFetcher {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import * as nock from 'nock';

import Request from '@core/domain/request/Request';
import {response} from '@testData/application/dataFetcher/random/RandomDotOrgResponse';
import RandomDotOrgDataFetcherAdapter from './RandomDotOrgDataFetcherAdapter';

describe('RandomSgxDataFetcherAdapter', () => {
const request = new Request('SOME_REQUEST_ID', 'random(0,10)', null);

it('return first data item on successful response', async () => {
// given
nock('https://api.random.org')
.post('/json-rpc/2/invoke')
.reply(200, response);
const sut = new RandomDotOrgDataFetcherAdapter('some-api-key');
// when
const result = await sut.fetch(request);
// then
expect(result).to.equal('2');
});

it('throw error on failed response', async () => {
// given
nock('https://api.random.org')
.post('/json-rpc/2/invoke')
.reply(500);
const sut = new RandomDotOrgDataFetcherAdapter('some-api-key');
// when
// then
return expect(sut.fetch(request)).to.be.rejected;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import RequestUrlParser from '@core/domain/request/RequestUrlParser';
import axios from 'axios';
import * as jp from 'jsonpath';

import DataFetcher from '@core/domain/common/port/DataFetcherPort';
import { HttpError } from '@core/domain/common/utils/error';
import Request from '@core/domain/request/Request';

class RandomDotOrgDataFetcherAdapter implements DataFetcher {
constructor(private apiKey: string) {}

async fetch(request: Request) {
let response;

const min = RequestUrlParser.resolveLeftSideBound(request.url);
const max = RequestUrlParser.resolveRightSideBound(request.url);

try {
response = await axios({
method: 'post',
url: 'https://api.random.org/json-rpc/2/invoke',
headers: {
'Content-Type': 'application/json',
},
data: this.createRequestData(Number(min), Number(max)),
});

return jp.value(response.data, 'result.random.data[0]').toString();
} catch (e) {
const randomDotOrgErrorCode = jp.value(response.data, 'error.code').toString();
const randomDotOrgErrorMessage = jp.value(response.data, 'error.message').toString();

throw new HttpError(randomDotOrgErrorMessage, randomDotOrgErrorCode);
}
}

private createRequestData(min: number, max: number): string {
return JSON.stringify({
jsonrpc: '2.0',
method: 'generateIntegers',
params: {
apiKey: this.apiKey,
n: 1,
min,
max,
replacement: true,
base: 10,
},
id: 0,
});
}
}

export default RandomDotOrgDataFetcherAdapter;
Loading