update nginx/dep updates/fix eslint/change line endings

Signed-off-by: Zoey <zoey@z0ey.de>
This commit is contained in:
Zoey
2024-03-25 18:24:21 +01:00
parent ef5ac4cbd8
commit 906d7ce04a
96 changed files with 2579 additions and 2859 deletions

View File

@@ -1,12 +1,12 @@
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const internalAuditLog = require('../../internal/audit-log');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -25,26 +25,28 @@ router
* Retrieve all logs
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalAuditLog.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
});

View File

@@ -1,27 +1,27 @@
const express = require('express');
const pjson = require('../../package.json');
const error = require('../../lib/error');
const pjson = require('../../package.json');
const error = require('../../lib/error');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
* Health Check
* GET /api
*/
router.get('/', (req, res/*, next*/) => {
let version = pjson.version.split('-').shift().split('.');
router.get('/', (req, res /*, next */) => {
const version = pjson.version.split('-').shift().split('.');
res.status(200).send({
status: 'OK',
status: 'OK',
version: {
major: parseInt(version.shift(), 10),
minor: parseInt(version.shift(), 10),
revision: parseInt(version.shift(), 10)
}
major: parseInt(version.shift(), 10),
minor: parseInt(version.shift(), 10),
revision: parseInt(version.shift(), 10),
},
});
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalAccessList = require('../../../internal/access-list');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all access-lists
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalAccessList.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,13 +58,12 @@ router
* Create a new access-list
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/access-lists#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/access-lists#/links/1/schema' }, req.body)
.then((payload) => {
return internalAccessList.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -85,30 +86,32 @@ router
* Retrieve a specific access-list
*/
.get((req, res, next) => {
validator({
required: ['list_id'],
additionalProperties: false,
properties: {
list_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['list_id'],
additionalProperties: false,
properties: {
list_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
list_id: req.params.list_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
list_id: req.params.list_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalAccessList.get(res.locals.access, {
id: parseInt(data.list_id, 10),
expand: data.expand
id: parseInt(data.list_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -119,14 +122,13 @@ router
* Update and existing access-list
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/access-lists#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/access-lists#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.list_id, 10);
return internalAccessList.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -137,10 +139,10 @@ router
* Delete and existing access-list
*/
.delete((req, res, next) => {
internalAccessList.delete(res.locals.access, {id: parseInt(req.params.list_id, 10)})
internalAccessList
.delete(res.locals.access, { id: parseInt(req.params.list_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalCertificate = require('../../../internal/certificate');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all certificates
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalCertificate.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,14 +58,13 @@ router
* Create a new certificate
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/certificates#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/certificates#/links/1/schema' }, req.body)
.then((payload) => {
req.setTimeout(900000); // 15 minutes timeout
return internalCertificate.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -80,16 +81,16 @@ router
})
.all(jwtdecode())
/**
* GET /api/nginx/certificates/test-http
*
* Test HTTP challenge for domains
*/
/**
* GET /api/nginx/certificates/test-http
*
* Test HTTP challenge for domains
*/
.get((req, res, next) => {
internalCertificate.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
internalCertificate
.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -112,30 +113,32 @@ router
* Retrieve a specific certificate
*/
.get((req, res, next) => {
validator({
required: ['certificate_id'],
additionalProperties: false,
properties: {
certificate_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['certificate_id'],
additionalProperties: false,
properties: {
certificate_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
certificate_id: req.params.certificate_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
certificate_id: req.params.certificate_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalCertificate.get(res.locals.access, {
id: parseInt(data.certificate_id, 10),
expand: data.expand
id: parseInt(data.certificate_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -146,14 +149,13 @@ router
* Update and existing certificate
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/certificates#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/certificates#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.certificate_id, 10);
return internalCertificate.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -164,10 +166,10 @@ router
* Update and existing certificate
*/
.delete((req, res, next) => {
internalCertificate.delete(res.locals.access, {id: parseInt(req.params.certificate_id, 10)})
internalCertificate
.delete(res.locals.access, { id: parseInt(req.params.certificate_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -191,16 +193,15 @@ router
*/
.post((req, res, next) => {
if (!req.files) {
res.status(400)
.send({error: 'No files were uploaded'});
res.status(400).send({ error: 'No files were uploaded' });
} else {
internalCertificate.upload(res.locals.access, {
id: parseInt(req.params.certificate_id, 10),
files: req.files
})
internalCertificate
.upload(res.locals.access, {
id: parseInt(req.params.certificate_id, 10),
files: req.files,
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
}
@@ -225,12 +226,12 @@ router
*/
.post((req, res, next) => {
req.setTimeout(900000); // 15 minutes timeout
internalCertificate.renew(res.locals.access, {
id: parseInt(req.params.certificate_id, 10)
})
internalCertificate
.renew(res.locals.access, {
id: parseInt(req.params.certificate_id, 10),
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -253,12 +254,12 @@ router
* Renew certificate
*/
.get((req, res, next) => {
internalCertificate.download(res.locals.access, {
id: parseInt(req.params.certificate_id, 10)
})
internalCertificate
.download(res.locals.access, {
id: parseInt(req.params.certificate_id, 10),
})
.then((result) => {
res.status(200)
.download(result.fileName);
res.status(200).download(result.fileName);
})
.catch(next);
});
@@ -282,15 +283,14 @@ router
*/
.post((req, res, next) => {
if (!req.files) {
res.status(400)
.send({error: 'No files were uploaded'});
res.status(400).send({ error: 'No files were uploaded' });
} else {
internalCertificate.validate({
files: req.files
})
internalCertificate
.validate({
files: req.files,
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
}

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalDeadHost = require('../../../internal/dead-host');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all dead-hosts
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalDeadHost.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,13 +58,12 @@ router
* Create a new dead-host
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/dead-hosts#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/dead-hosts#/links/1/schema' }, req.body)
.then((payload) => {
return internalDeadHost.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -85,30 +86,32 @@ router
* Retrieve a specific dead-host
*/
.get((req, res, next) => {
validator({
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
host_id: req.params.host_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
host_id: req.params.host_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalDeadHost.get(res.locals.access, {
id: parseInt(data.host_id, 10),
expand: data.expand
id: parseInt(data.host_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -119,14 +122,13 @@ router
* Update and existing dead-host
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/dead-hosts#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/dead-hosts#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.host_id, 10);
return internalDeadHost.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -137,10 +139,10 @@ router
* Update and existing dead-host
*/
.delete((req, res, next) => {
internalDeadHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalDeadHost
.delete(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -161,10 +163,10 @@ router
* POST /api/nginx/dead-hosts/123/enable
*/
.post((req, res, next) => {
internalDeadHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalDeadHost
.enable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -185,10 +187,10 @@ router
* POST /api/nginx/dead-hosts/123/disable
*/
.post((req, res, next) => {
internalDeadHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalDeadHost
.disable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalProxyHost = require('../../../internal/proxy-host');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all proxy-hosts
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalProxyHost.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,13 +58,12 @@ router
* Create a new proxy-host
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/proxy-hosts#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/proxy-hosts#/links/1/schema' }, req.body)
.then((payload) => {
return internalProxyHost.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -85,30 +86,32 @@ router
* Retrieve a specific proxy-host
*/
.get((req, res, next) => {
validator({
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
host_id: req.params.host_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
host_id: req.params.host_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalProxyHost.get(res.locals.access, {
id: parseInt(data.host_id, 10),
expand: data.expand
id: parseInt(data.host_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -119,14 +122,13 @@ router
* Update and existing proxy-host
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/proxy-hosts#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/proxy-hosts#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.host_id, 10);
return internalProxyHost.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -137,10 +139,10 @@ router
* Update and existing proxy-host
*/
.delete((req, res, next) => {
internalProxyHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalProxyHost
.delete(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -161,10 +163,10 @@ router
* POST /api/nginx/proxy-hosts/123/enable
*/
.post((req, res, next) => {
internalProxyHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalProxyHost
.enable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -185,10 +187,10 @@ router
* POST /api/nginx/proxy-hosts/123/disable
*/
.post((req, res, next) => {
internalProxyHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalProxyHost
.disable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalRedirectionHost = require('../../../internal/redirection-host');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all redirection-hosts
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalRedirectionHost.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,13 +58,12 @@ router
* Create a new redirection-host
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/redirection-hosts#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/redirection-hosts#/links/1/schema' }, req.body)
.then((payload) => {
return internalRedirectionHost.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -85,30 +86,32 @@ router
* Retrieve a specific redirection-host
*/
.get((req, res, next) => {
validator({
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['host_id'],
additionalProperties: false,
properties: {
host_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
host_id: req.params.host_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
host_id: req.params.host_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalRedirectionHost.get(res.locals.access, {
id: parseInt(data.host_id, 10),
expand: data.expand
id: parseInt(data.host_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -119,14 +122,13 @@ router
* Update and existing redirection-host
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/redirection-hosts#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/redirection-hosts#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.host_id, 10);
return internalRedirectionHost.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -137,10 +139,10 @@ router
* Update and existing redirection-host
*/
.delete((req, res, next) => {
internalRedirectionHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalRedirectionHost
.delete(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -161,10 +163,10 @@ router
* POST /api/nginx/redirection-hosts/123/enable
*/
.post((req, res, next) => {
internalRedirectionHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalRedirectionHost
.enable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -185,10 +187,10 @@ router
* POST /api/nginx/redirection-hosts/123/disable
*/
.post((req, res, next) => {
internalRedirectionHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalRedirectionHost
.disable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../../lib/validator');
const jwtdecode = require('../../../lib/express/jwt-decode');
const internalStream = require('../../../internal/stream');
const apiValidator = require('../../../lib/validator/api');
const apiValidator = require('../../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,26 +26,28 @@ router
* Retrieve all streams
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalStream.getAll(res.locals.access, data.expand, data.query);
})
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
})
@@ -56,13 +58,12 @@ router
* Create a new stream
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/streams#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/streams#/links/1/schema' }, req.body)
.then((payload) => {
return internalStream.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -85,30 +86,32 @@ router
* Retrieve a specific stream
*/
.get((req, res, next) => {
validator({
required: ['stream_id'],
additionalProperties: false,
properties: {
stream_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['stream_id'],
additionalProperties: false,
properties: {
stream_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
stream_id: req.params.stream_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
stream_id: req.params.stream_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalStream.get(res.locals.access, {
id: parseInt(data.stream_id, 10),
expand: data.expand
id: parseInt(data.stream_id, 10),
expand: data.expand,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -119,14 +122,13 @@ router
* Update and existing stream
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/streams#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/streams#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = parseInt(req.params.stream_id, 10);
return internalStream.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -137,10 +139,10 @@ router
* Update and existing stream
*/
.delete((req, res, next) => {
internalStream.delete(res.locals.access, {id: parseInt(req.params.stream_id, 10)})
internalStream
.delete(res.locals.access, { id: parseInt(req.params.stream_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -161,10 +163,10 @@ router
* POST /api/nginx/streams/123/enable
*/
.post((req, res, next) => {
internalStream.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalStream
.enable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -185,10 +187,10 @@ router
* POST /api/nginx/streams/123/disable
*/
.post((req, res, next) => {
internalStream.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
internalStream
.disable(res.locals.access, { id: parseInt(req.params.host_id, 10) })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,11 +1,11 @@
const express = require('express');
const jwtdecode = require('../../lib/express/jwt-decode');
const express = require('express');
const jwtdecode = require('../../lib/express/jwt-decode');
const internalReport = require('../../internal/report');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
router
@@ -18,10 +18,10 @@ router
* GET /reports/hosts
*/
.get(jwtdecode(), (req, res, next) => {
internalReport.getHostsReport(res.locals.access)
internalReport
.getHostsReport(res.locals.access)
.then((data) => {
res.status(200)
.send(data);
res.status(200).send(data);
})
.catch(next);
});

View File

@@ -1,11 +1,11 @@
const express = require('express');
const express = require('express');
const swaggerJSON = require('../../doc/api.swagger.json');
const PACKAGE = require('../../package.json');
const PACKAGE = require('../../package.json');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
router
@@ -17,7 +17,7 @@ router
/**
* GET /schema
*/
.get((req, res/*, next*/) => {
.get((req, res /*, next */) => {
let proto = req.protocol;
if (typeof req.headers['x-forwarded-proto'] !== 'undefined' && req.headers['x-forwarded-proto']) {
proto = req.headers['x-forwarded-proto'];
@@ -28,7 +28,7 @@ router
origin = req.headers.origin;
}
swaggerJSON.info.version = PACKAGE.version;
swaggerJSON.info.version = PACKAGE.version;
swaggerJSON.servers[0].url = origin + '/api';
res.status(200).send(swaggerJSON);
});

View File

@@ -1,13 +1,13 @@
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const internalSetting = require('../../internal/setting');
const apiValidator = require('../../lib/validator/api');
const apiValidator = require('../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -26,10 +26,10 @@ router
* Retrieve all settings
*/
.get((req, res, next) => {
internalSetting.getAll(res.locals.access)
internalSetting
.getAll(res.locals.access)
.then((rows) => {
res.status(200)
.send(rows);
res.status(200).send(rows);
})
.catch(next);
});
@@ -52,25 +52,27 @@ router
* Retrieve a specific setting
*/
.get((req, res, next) => {
validator({
required: ['setting_id'],
additionalProperties: false,
properties: {
setting_id: {
$ref: 'definitions#/definitions/setting_id'
}
}
}, {
setting_id: req.params.setting_id
})
validator(
{
required: ['setting_id'],
additionalProperties: false,
properties: {
setting_id: {
$ref: 'definitions#/definitions/setting_id',
},
},
},
{
setting_id: req.params.setting_id,
},
)
.then((data) => {
return internalSetting.get(res.locals.access, {
id: data.setting_id
id: data.setting_id,
});
})
.then((row) => {
res.status(200)
.send(row);
res.status(200).send(row);
})
.catch(next);
})
@@ -81,14 +83,13 @@ router
* Update and existing setting
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/settings#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/settings#/links/1/schema' }, req.body)
.then((payload) => {
payload.id = req.params.setting_id;
return internalSetting.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});

View File

@@ -1,12 +1,12 @@
const express = require('express');
const jwtdecode = require('../../lib/express/jwt-decode');
const express = require('express');
const jwtdecode = require('../../lib/express/jwt-decode');
const internalToken = require('../../internal/token');
const apiValidator = require('../../lib/validator/api');
const apiValidator = require('../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
router
@@ -23,13 +23,13 @@ router
* for services like Job board and Worker.
*/
.get(jwtdecode(), (req, res, next) => {
internalToken.getFreshToken(res.locals.access, {
expiry: (typeof req.query.expiry !== 'undefined' ? req.query.expiry : null),
scope: (typeof req.query.scope !== 'undefined' ? req.query.scope : null)
})
internalToken
.getFreshToken(res.locals.access, {
expiry: typeof req.query.expiry !== 'undefined' ? req.query.expiry : null,
scope: typeof req.query.scope !== 'undefined' ? req.query.scope : null,
})
.then((data) => {
res.status(200)
.send(data);
res.status(200).send(data);
})
.catch(next);
})
@@ -40,13 +40,12 @@ router
* Create a new Token
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/tokens#/links/0/schema'}, req.body)
apiValidator({ $ref: 'endpoints/tokens#/links/0/schema' }, req.body)
.then((payload) => {
return internalToken.getTokenFromEmail(payload);
})
.then((data) => {
res.status(200)
.send(data);
res.status(200).send(data);
})
.catch(next);
});

View File

@@ -1,14 +1,14 @@
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const express = require('express');
const validator = require('../../lib/validator');
const jwtdecode = require('../../lib/express/jwt-decode');
const userIdFromMe = require('../../lib/express/user-id-from-me');
const internalUser = require('../../internal/user');
const apiValidator = require('../../lib/validator/api');
let router = express.Router({
const router = express.Router({
caseSensitive: true,
strict: true,
mergeParams: true
strict: true,
mergeParams: true,
});
/**
@@ -27,26 +27,28 @@ router
* Retrieve all users
*/
.get((req, res, next) => {
validator({
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand'
validator(
{
additionalProperties: false,
properties: {
expand: {
$ref: 'definitions#/definitions/expand',
},
query: {
$ref: 'definitions#/definitions/query',
},
},
query: {
$ref: 'definitions#/definitions/query'
}
}
}, {
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
query: (typeof req.query.query === 'string' ? req.query.query : null)
})
},
{
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
query: typeof req.query.query === 'string' ? req.query.query : null,
},
)
.then((data) => {
return internalUser.getAll(res.locals.access, data.expand, data.query);
})
.then((users) => {
res.status(200)
.send(users);
res.status(200).send(users);
})
.catch(next);
})
@@ -57,13 +59,12 @@ router
* Create a new User
*/
.post((req, res, next) => {
apiValidator({$ref: 'endpoints/users#/links/1/schema'}, req.body)
apiValidator({ $ref: 'endpoints/users#/links/1/schema' }, req.body)
.then((payload) => {
return internalUser.create(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -87,31 +88,33 @@ router
* Retrieve a specific user
*/
.get((req, res, next) => {
validator({
required: ['user_id'],
additionalProperties: false,
properties: {
user_id: {
$ref: 'definitions#/definitions/id'
validator(
{
required: ['user_id'],
additionalProperties: false,
properties: {
user_id: {
$ref: 'definitions#/definitions/id',
},
expand: {
$ref: 'definitions#/definitions/expand',
},
},
expand: {
$ref: 'definitions#/definitions/expand'
}
}
}, {
user_id: req.params.user_id,
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
})
},
{
user_id: req.params.user_id,
expand: typeof req.query.expand === 'string' ? req.query.expand.split(',') : null,
},
)
.then((data) => {
return internalUser.get(res.locals.access, {
id: data.user_id,
id: data.user_id,
expand: data.expand,
omit: internalUser.getUserOmisionsByAccess(res.locals.access, data.user_id)
omit: internalUser.getUserOmisionsByAccess(res.locals.access, data.user_id),
});
})
.then((user) => {
res.status(200)
.send(user);
res.status(200).send(user);
})
.catch(next);
})
@@ -122,14 +125,13 @@ router
* Update and existing user
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/users#/links/2/schema'}, req.body)
apiValidator({ $ref: 'endpoints/users#/links/2/schema' }, req.body)
.then((payload) => {
payload.id = req.params.user_id;
return internalUser.update(res.locals.access, payload);
})
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
})
@@ -140,10 +142,10 @@ router
* Update and existing user
*/
.delete((req, res, next) => {
internalUser.delete(res.locals.access, {id: req.params.user_id})
internalUser
.delete(res.locals.access, { id: req.params.user_id })
.then((result) => {
res.status(200)
.send(result);
res.status(200).send(result);
})
.catch(next);
});
@@ -167,14 +169,13 @@ router
* Update password for a user
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/users#/links/4/schema'}, req.body)
apiValidator({ $ref: 'endpoints/users#/links/4/schema' }, req.body)
.then((payload) => {
payload.id = req.params.user_id;
return internalUser.setPassword(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -198,14 +199,13 @@ router
* Set some or all permissions for a user
*/
.put((req, res, next) => {
apiValidator({$ref: 'endpoints/users#/links/5/schema'}, req.body)
apiValidator({ $ref: 'endpoints/users#/links/5/schema' }, req.body)
.then((payload) => {
payload.id = req.params.user_id;
return internalUser.setPermissions(res.locals.access, payload);
})
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});
@@ -228,10 +228,10 @@ router
* Log in as a user
*/
.post((req, res, next) => {
internalUser.loginAs(res.locals.access, {id: parseInt(req.params.user_id, 10)})
internalUser
.loginAs(res.locals.access, { id: parseInt(req.params.user_id, 10) })
.then((result) => {
res.status(201)
.send(result);
res.status(201).send(result);
})
.catch(next);
});