move provider into sysinfo

this is ideally "auto-detectable" runtime information
This commit is contained in:
Girish Ramakrishnan
2019-07-26 07:25:40 -07:00
parent 7fe66aa7fa
commit 9e7e9d66bf
11 changed files with 34 additions and 21 deletions
+2 -2
View File
@@ -10,18 +10,18 @@ exports = module.exports = {
var assert = require('assert'),
auditSource = require('../auditsource'),
config = require('../config.js'),
debug = require('debug')('box:routes/setup'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
provision = require('../provision.js'),
ProvisionError = require('../provision.js').ProvisionError,
sysinfo = require('../sysinfo.js'),
superagent = require('superagent');
function providerTokenAuth(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (config.provider() === 'ami') {
if (sysinfo.provider() === 'ami') {
if (typeof req.body.providerToken !== 'string' || !req.body.providerToken) return next(new HttpError(400, 'providerToken must be a non empty string'));
superagent.get('http://169.254.169.254/latest/meta-data/instance-id').timeout(30 * 1000).end(function (error, result) {
+3 -3
View File
@@ -128,15 +128,15 @@ function getCloudronAvatar(req, res, next) {
}
function getBackupConfig(req, res, next) {
settings.getBackupConfig(function (error, config) {
settings.getBackupConfig(function (error, backupConfig) {
if (error) return next(new HttpError(500, error));
// always send provider as it is used by the UI to figure if backups are disabled ('noop' backend)
if (!custom.spec().backups.configurable) {
return next(new HttpSuccess(200, { provider: config.provider }));
return next(new HttpSuccess(200, { provider: backupConfig.provider }));
}
next(new HttpSuccess(200, backups.removePrivateFields(config)));
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
});
}