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

API V3 #4250

Merged
merged 151 commits into from
Oct 9, 2019
Merged

API V3 #4250

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
589f61d
extended .gitignore for Visual Studio 2017
PetrOndrusek Feb 1, 2019
c0b265b
creating a lib for api3 and exposing it's swagger file
PetrOndrusek Feb 1, 2019
9e7b0de
adding pilot test (for /swagger.yaml)
PetrOndrusek Feb 1, 2019
403bce4
implementing public GET /version
PetrOndrusek Feb 1, 2019
bdb880d
setting api version to 3.0.0-alpha
PetrOndrusek Feb 2, 2019
48c3fa5
creating authorization skeleton + fetching some API env variables
PetrOndrusek Feb 2, 2019
cc4fb5b
reusing authorization library
PetrOndrusek Feb 3, 2019
3d382d0
implementing security
PetrOndrusek Feb 3, 2019
12d9315
forcing HTTPS and removing x-powered-by from response
PetrOndrusek Feb 4, 2019
e109d03
moving messages to constants, creating https instance fixture
PetrOndrusek Feb 4, 2019
f3580e2
testing HTTPS requiring
PetrOndrusek Feb 4, 2019
5cd47d6
testing Date header
PetrOndrusek Feb 5, 2019
4d68645
testing permission check
PetrOndrusek Feb 5, 2019
4e2153a
testing allowed operation
PetrOndrusek Feb 6, 2019
d077e7c
refactoring + storage stub
PetrOndrusek Feb 7, 2019
22faa60
create architecture for generic operations
PetrOndrusek Feb 7, 2019
bd89bfb
beginning of READ operation
PetrOndrusek Feb 12, 2019
71db189
tidying the code up
PetrOndrusek Feb 13, 2019
b9d0920
basic READ part
PetrOndrusek Feb 13, 2019
30870b6
going further with READ operation
PetrOndrusek Feb 13, 2019
7bff23a
DELETE operation
PetrOndrusek Feb 19, 2019
5ee6b1f
handling fields parameter
PetrOndrusek Feb 21, 2019
c1b7b03
refactoring to classes
PetrOndrusek Feb 22, 2019
91096c3
Merge remote-tracking branch 'base/dev' into wip/api3
PetrOndrusek Mar 3, 2019
cbc7f1d
going further with SEARCH operation
PetrOndrusek Mar 4, 2019
2477690
refactoring file structure
PetrOndrusek Mar 5, 2019
83a6747
filtering for SEARCH operation
PetrOndrusek Mar 13, 2019
632b544
preparations for fallback deduplication
PetrOndrusek Mar 13, 2019
c2e58cf
CREATE operation
PetrOndrusek Mar 19, 2019
b95cea0
UPDATE operation
PetrOndrusek Mar 20, 2019
c0a0e19
PATCH operation
PetrOndrusek Mar 21, 2019
ac53109
HISTORY operation
PetrOndrusek Mar 21, 2019
5901686
creating more precise variant of HISTORY operation
PetrOndrusek Mar 21, 2019
8fc76a4
autopruning
PetrOndrusek Mar 23, 2019
81291dc
long for timestamps in swagger
PetrOndrusek Mar 27, 2019
d4ecca9
bug fix (when search fields=srvCreated)
PetrOndrusek Apr 1, 2019
9a404b5
creating skeleton for generic collection API test
PetrOndrusek Apr 11, 2019
1e5b3e0
specific HISTORY skeleton
PetrOndrusek Apr 16, 2019
515076b
distinguish between collection logical and storage name
PetrOndrusek Apr 16, 2019
d566b37
renaming operation to LAST MODIFIED and getting it to work
PetrOndrusek Apr 17, 2019
f2e445c
fallback for LAST MODIFIED operation
PetrOndrusek Apr 23, 2019
94bfcdb
tidying a bit
PetrOndrusek Apr 24, 2019
8203760
LAST MODIFIED documentation
PetrOndrusek Apr 26, 2019
9b447b7
bugfix + emitting data-received
PetrOndrusek Apr 26, 2019
069fa4f
merge dev
PetrOndrusek Apr 26, 2019
bf49c82
adding some validations
PetrOndrusek Apr 26, 2019
194cfd9
bugfix - remove 'token' parameter from filtering
PetrOndrusek Apr 30, 2019
be2c35a
testing and debugging generic workflow
PetrOndrusek May 8, 2019
4dec6e9
test fix for empty db
PetrOndrusek May 8, 2019
6254c06
fixing security test fixture
PetrOndrusek May 9, 2019
b7b878c
trying to fix Travis CI testing DB problem
PetrOndrusek May 9, 2019
d409902
merge dev
PetrOndrusek May 10, 2019
741000b
multiple auth callback bugfix + adding user field on authed create/up…
PetrOndrusek May 12, 2019
bcd2563
messages for Travis CI debugging
PetrOndrusek May 12, 2019
8ed90b7
messages for Travis CI debugging
PetrOndrusek May 12, 2019
1d34d6d
messages for Travis CI debugging
PetrOndrusek May 12, 2019
7480956
test fix (to be prepared for future dates in db)
PetrOndrusek May 12, 2019
b63524f
test fix
PetrOndrusek May 12, 2019
ba4c40f
adding fallback created_at filling on each create/update
PetrOndrusek May 12, 2019
c835851
merge dev
PetrOndrusek May 21, 2019
faa571d
STATUS operation with API permissions
PetrOndrusek May 21, 2019
7fc66c9
querying srvDate from storage + include storage version info
PetrOndrusek May 21, 2019
ab47c5b
bugfix of missing apiConst require
PetrOndrusek May 21, 2019
a5ed6d7
getting mongo version with read-only user rights
PetrOndrusek May 30, 2019
2454b38
getting mongo current date with read-only user rights
PetrOndrusek May 30, 2019
90c19ca
trying to diagnose travis CI timeout
PetrOndrusek May 30, 2019
bcbbefd
refactoring storage version caching (due to some environments problems)
PetrOndrusek May 30, 2019
48d53bf
making VERSION work on empty database
PetrOndrusek May 30, 2019
55b01b8
more fixes
PetrOndrusek May 30, 2019
e689e44
skipping API HTTPS test for node 8
PetrOndrusek May 31, 2019
589e032
making code more readable using ES6 (Promises, async + await)
PetrOndrusek Jun 4, 2019
23f7c0a
extending treatments collection docs by inspecting the careportal code
PetrOndrusek Jun 4, 2019
5b57b8b
tidying existing API3 tests up to allow further grow
PetrOndrusek Jun 5, 2019
a637a01
tidying the authorization code up to increase readability and perform…
PetrOndrusek Jun 6, 2019
5b1e76a
more refactoring to ES6 and making APIv3 files structure more extendable
PetrOndrusek Jun 6, 2019
6776123
normalizing incoming dates to UTC and storing utcOffset
PetrOndrusek Jun 6, 2019
4839cc7
fixing srvDate to be of node.js server, not the mongo DB
PetrOndrusek Jun 6, 2019
915ae27
preparing test fixtures for permissions testing + skeleton for CREATE…
PetrOndrusek Jun 8, 2019
ce7cb83
intensive CREATE operation testing + minor bug fixes
PetrOndrusek Jun 10, 2019
25b1581
correcting the deduplication test
PetrOndrusek Jun 10, 2019
c6a9fc8
more deduplication testing of CREATE operation
PetrOndrusek Jun 11, 2019
ba22273
adding test skeletons for other generic operations
PetrOndrusek Jun 12, 2019
543251c
added variability in filtering by date, created_at, srvModified, srvC…
PetrOndrusek Jun 12, 2019
92f8bc0
fixing test accordingly to previous commit
PetrOndrusek Jun 12, 2019
757f57e
adding new collection settings for centralized apps' settings storage
PetrOndrusek Jun 12, 2019
15f617e
trying to solve travis CI testing problem - adding default collection…
PetrOndrusek Jun 12, 2019
d5d8e88
another attempt to travis CI test fix
PetrOndrusek Jun 12, 2019
f27faf5
adding some tests for READ operation
PetrOndrusek Jun 13, 2019
6ce6c2e
adding custom error handler (overriding bodyparser's errors)
PetrOndrusek Jun 13, 2019
a20ce3a
securing settings collection more and updating swagger accordingly
PetrOndrusek Jun 13, 2019
c951ea8
making HISTORY timestamp parameter more flexible + updating swagger d…
PetrOndrusek Jun 14, 2019
e203d1a
more testing and bug fixing
PetrOndrusek Jun 14, 2019
43af4c0
sending only HTTP status with empty body, when there is no message + …
PetrOndrusek Jun 14, 2019
1b307b0
more refactoring and testing (especially of UPDATE operation)
PetrOndrusek Jun 16, 2019
a858c3d
PATCH testing + adding userModified field for troubleshooting purposes
PetrOndrusek Jun 16, 2019
ba5248f
basic SEARCH operation testing
PetrOndrusek Jun 17, 2019
6c6e4c3
more SEARCH operation testing
PetrOndrusek Jun 18, 2019
9b7dd8f
adding alternative 'now' query parameter to 'Date' header to make GET…
PetrOndrusek Jun 19, 2019
c98764e
adding 'now' to reserved query parameters for SEARCH operation
PetrOndrusek Jun 19, 2019
07472d1
more testing
PetrOndrusek Jul 6, 2019
832f9b0
renaming field user to subject (and modifiedBy)
PetrOndrusek Jul 8, 2019
6a15763
Merge remote-tracking branch 'nsteam/dev' into wip/api3
PetrOndrusek Jul 8, 2019
3b1d594
bugfix - fixing RFC 2822 constant for moment parsing
PetrOndrusek Jul 9, 2019
2351125
storageSocket: creating skeleton for new Socket.IO namespace
PetrOndrusek Jul 12, 2019
8882d3a
storageSocket: authentication by accessToken
PetrOndrusek Jul 13, 2019
4075881
storageSocket: authorizing to subscribe rooms
PetrOndrusek Jul 20, 2019
7b7d5cf
storageSocket: emitting create, update and delete events
PetrOndrusek Jul 20, 2019
b22ce89
Merge remote-tracking branch 'nsteam/dev' into wip/api3-socket
PetrOndrusek Jul 20, 2019
02fa57a
APIv3: adding support for swagger UI at /api/v3/swagger-ui-dist
PetrOndrusek Jul 21, 2019
5781f83
solving some problems detected by eslint
PetrOndrusek Jul 22, 2019
58daac4
solving some problems detected by eslint
PetrOndrusek Jul 22, 2019
6ab8efd
APIv3: testing and debugging Socket.IO
PetrOndrusek Jul 25, 2019
30dd3e0
APIv3: testing and debugging Socket.IO
PetrOndrusek Jul 25, 2019
dbe59ff
APIv3: Socket.IO documentation
PetrOndrusek Jul 26, 2019
47514f2
APIv3: making the sample real
PetrOndrusek Jul 27, 2019
b894583
APIv3: starting to create a simple tutorial MD file
PetrOndrusek Jul 29, 2019
c335596
APIv3: small corrections
PetrOndrusek Jul 29, 2019
daa727d
Merge remote-tracking branch 'nsteam/dev' into wip/api3
PetrOndrusek Jul 29, 2019
cd16825
APIv3: minor corrections after dev merge
PetrOndrusek Jul 30, 2019
bbbd90f
APIv3: adding CREATE and READ operations to the tutorial.md
PetrOndrusek Jul 30, 2019
fff6cec
APIv3: adding SEARCH, LAST MODIFIED, UPDATE operations to the tutoria…
PetrOndrusek Jul 30, 2019
f4e1cbd
APIv3: finishing the tutorial.md
PetrOndrusek Jul 31, 2019
e5c7902
APIv3: minor bugfix (bad location after upsert)
PetrOndrusek Aug 1, 2019
a0b24aa
APIv3: refactoring SEARCH complexity
PetrOndrusek Aug 2, 2019
d56fb62
APIv3: refactoring mongoCollection complexity
PetrOndrusek Aug 2, 2019
0e1fb22
APIv3: refactoring complexity
PetrOndrusek Aug 2, 2019
55acb66
APIv3: tidying up a bit
PetrOndrusek Aug 3, 2019
04db4ef
APIv3: refactoring security (start)
PetrOndrusek Aug 3, 2019
a55aa15
APIv3: refactoring lastModified
PetrOndrusek Aug 3, 2019
e796d17
APIv3: refactoring create (start)
PetrOndrusek Aug 3, 2019
fb940aa
APIv3: refactoring create (finish)
PetrOndrusek Aug 3, 2019
6c3ca87
APIv3: refactoring delete
PetrOndrusek Aug 4, 2019
a6960f3
APIv3: refactoring history
PetrOndrusek Aug 4, 2019
30d58e9
APIv3: refactoring update
PetrOndrusek Aug 4, 2019
9e5893b
APIv3: refactoring patch
PetrOndrusek Aug 4, 2019
810030b
APIv3: refactoring read
PetrOndrusek Aug 4, 2019
6152e99
APIv3: refactoring search + removing deprecated authorizationBuilder
PetrOndrusek Aug 4, 2019
c51028b
APIv3: adding best practise for identifier constructing
PetrOndrusek Aug 5, 2019
fbeb792
APIv3: refactoring and enhancing the validation (immutable fields)
PetrOndrusek Aug 5, 2019
e24d40d
Merge remote-tracking branch 'nsteam/dev' into wip/api3
PetrOndrusek Aug 5, 2019
881e673
APIv3: adding security.md documentation file
PetrOndrusek Aug 5, 2019
a2f093e
APIv3: refactoring - splitting index.js into multiple files
PetrOndrusek Aug 14, 2019
e3eb5be
APIv3: calculating identifier on server side + deduplicating
PetrOndrusek Aug 14, 2019
6183f49
APIv3: refactoring cosmetics
PetrOndrusek Aug 15, 2019
89dc589
Merge remote-tracking branch 'nsteam/dev' into wip/api3
PetrOndrusek Aug 15, 2019
df1198a
APIv3: updating the documentation
PetrOndrusek Aug 15, 2019
5695ab4
APIv3: making basic and security tests more readable using async/await
PetrOndrusek Aug 26, 2019
437a842
Merge remote-tracking branch 'nsteam/dev' into wip/api3
PetrOndrusek Aug 26, 2019
b1a98ad
APIv3: making the rest of tests more readable using async/await
PetrOndrusek Aug 26, 2019
fb80d75
APIv3: adapting test of previous API
PetrOndrusek Aug 27, 2019
830efed
APIv3: adapting test of previous API
PetrOndrusek Aug 27, 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
Prev Previous commit
Next Next commit
creating authorization skeleton + fetching some API env variables
  • Loading branch information
PetrOndrusek committed Feb 2, 2019
commit 48c3fa5bf78561a29ba710bc203f0c483680a871
16 changes: 16 additions & 0 deletions lib/api3/authBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

function configure (env, ctx) {

function authBuilder (permission) {

return function authorize (req, res, next) {

res.sendJSONStatus(res, 401, 'Missing access token or JWT');
}
}

return authBuilder;
}

module.exports = configure;
4 changes: 3 additions & 1 deletion lib/api3/const.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"API3_VERSION": "3.0.0-alpha"
"API3_VERSION": "3.0.0-alpha",
"API3_SECURITY_ENABLE": true,
"API3_TIME_SKEW_TOLERANCE": 5
}
52 changes: 46 additions & 6 deletions lib/api3/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
'use strict';

function create(env, ctx) {
var _ = require('lodash')
, express = require('express')
, app = express()
, apiConst = require('./const.json')
function setENVTruthy (app, varName, defaultValue) {
//for some reason Azure uses this prefix, maybe there is a good reason
var value = process.env['CUSTOMCONNSTR_' + varName]
|| process.env['CUSTOMCONNSTR_' + varName.toLowerCase()]
|| process.env[varName]
|| process.env[varName.toLowerCase()];

value = value != null ? value : defaultValue;

if (typeof value === 'string' && (value.toLowerCase() === 'on' || value.toLowerCase() === 'true')) { value = true; }
if (typeof value === 'string' && (value.toLowerCase() === 'off' || value.toLowerCase() === 'false')) { value = false; }

app.set(varName, value);
}


function setupApiEnvironment (app, env) {
var apiConst = require('./const.json')

var wares = require('../middleware/')(env);
app.set('name', env.name);
app.set('version', env.version);
app.set('apiVersion', apiConst.API3_VERSION);
app.set('units', env.DISPLAY_UNITS);

// we don't need these here
app.set('x-powered-by', false);
app.set('etag', false);

setENVTruthy(app, 'API3_SECURITY_ENABLE', apiConst.API3_SECURITY_ENABLE);
setENVTruthy(app, 'API3_TIME_SKEW_TOLERANCE', apiConst.API3_TIME_SKEW_TOLERANCE);
setENVTruthy(app, 'API3_DEDUP_FALLBACK_ENABLED', apiConst.API3_DEDUP_FALLBACK_ENABLED);
}


function setupApiRoutes (app, env, ctx) {
var wares = require('../middleware/')(env)
, authBuilder = require('./authBuilder')(env, ctx)

app.get('/swagger.yaml', function getSwagger (req, res) {
res.sendFile(__dirname + '/swagger.yaml');
});

app.get('/version', require('./version')(app, wares, env, ctx));

app.get('/test', wares.sendJSONStatus, authBuilder('api:entries:read'), function test (req, res) {
res.status(200).end();
});
}


function create (env, ctx) {
var express = require('express')
, app = express()

setupApiEnvironment(app, env);

setupApiRoutes(app, env, ctx);

return app;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/api3/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function configure (app, wares, env, ctx) {
var express = require('express'),
api = express.Router( )

api.get('/version', function (req, res) {
api.get('/version', function getVersion (req, res) {
var date = new Date();
var info = { version: app.get('version')
, apiVersion: app.get('apiVersion')
Expand Down