Initial commit
This commit is contained in:
121
manager/src/backend/routes/api/access.js
Normal file
121
manager/src/backend/routes/api/access.js
Normal file
@ -0,0 +1,121 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const validator = require('../../lib/validator');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalAccess = require('../../internal/access');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/access
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /api/access
|
||||
*
|
||||
* Retrieve all access lists
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
internalAccess.getAll()
|
||||
.then(lists => {
|
||||
res.status(200)
|
||||
.send(lists);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* POST /api/access
|
||||
*
|
||||
* Create a new Access List
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/access#/links/1/schema'}, req.body)
|
||||
.then(payload => {
|
||||
return internalAccess.create(payload);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Specific Access List
|
||||
*
|
||||
* /api/access/123
|
||||
*/
|
||||
router
|
||||
.route('/:list_id')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /access/123
|
||||
*
|
||||
* Retrieve a specific Access List
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['list_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
}
|
||||
}
|
||||
}, req.params)
|
||||
.then(data => {
|
||||
return internalAccess.get(data.list_id);
|
||||
})
|
||||
.then(list => {
|
||||
res.status(200)
|
||||
.send(list);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* PUT /api/access/123
|
||||
*
|
||||
* Update an existing Access List
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/access#/links/2/schema'}, req.body)
|
||||
.then(payload => {
|
||||
return internalAccess.update(req.params.list_id, payload);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* DELETE /api/access/123
|
||||
*
|
||||
* Delete an existing Access List
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalAccess.delete(req.params.list_id)
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
189
manager/src/backend/routes/api/hosts.js
Normal file
189
manager/src/backend/routes/api/hosts.js
Normal file
@ -0,0 +1,189 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const validator = require('../../lib/validator');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalHost = require('../../internal/host');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/hosts
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /api/hosts
|
||||
*
|
||||
* Retrieve all hosts
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
internalHost.getAll()
|
||||
.then(hosts => {
|
||||
res.status(200)
|
||||
.send(hosts);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* POST /api/hosts
|
||||
*
|
||||
* Create a new Host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/hosts#/links/1/schema'}, req.body)
|
||||
.then(payload => {
|
||||
return internalHost.create(payload);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Specific Host
|
||||
*
|
||||
* /api/hosts/123
|
||||
*/
|
||||
router
|
||||
.route('/:host_id')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /hosts/123
|
||||
*
|
||||
* Retrieve a specific Host
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/_id'
|
||||
}
|
||||
}
|
||||
}, req.params)
|
||||
.then(data => {
|
||||
return internalHost.get(data.host_id);
|
||||
})
|
||||
.then(host => {
|
||||
res.status(200)
|
||||
.send(host);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* PUT /api/hosts/123
|
||||
*
|
||||
* Update an existing Host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/hosts#/links/2/schema'}, req.body)
|
||||
.then(payload => {
|
||||
return internalHost.update(req.params.host_id, payload);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* DELETE /api/hosts/123
|
||||
*
|
||||
* Delete an existing Host
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalHost.delete(req.params.host_id)
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Reconfigure Host Action
|
||||
*
|
||||
* /api/hosts/123/reconfigure
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/reconfigure')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* POST /api/hosts/123/reconfigure
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/_id'
|
||||
}
|
||||
}
|
||||
}, req.params)
|
||||
.then(data => {
|
||||
return internalHost.reconfigure(data.host_id);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
/**
|
||||
* Renew Host Action
|
||||
*
|
||||
* /api/hosts/123/renew
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/renew')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* POST /api/hosts/123/renew
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/_id'
|
||||
}
|
||||
}
|
||||
}, req.params)
|
||||
.then(data => {
|
||||
return internalHost.renew(data.host_id);
|
||||
})
|
||||
.then(result => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
31
manager/src/backend/routes/api/main.js
Normal file
31
manager/src/backend/routes/api/main.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const pjson = require('../../../../package.json');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api
|
||||
*/
|
||||
router.get('/', (req, res/*, next*/) => {
|
||||
let version = pjson.version.split('-').shift().split('.');
|
||||
|
||||
res.status(200).send({
|
||||
status: 'Healthy',
|
||||
version: {
|
||||
major: parseInt(version.shift(), 10),
|
||||
minor: parseInt(version.shift(), 10),
|
||||
revision: parseInt(version.shift(), 10)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.use('/hosts', require('./hosts'));
|
||||
router.use('/access', require('./access'));
|
||||
|
||||
module.exports = router;
|
Reference in New Issue
Block a user