remove settings route entirely, redundant by now

This commit is contained in:
Girish Ramakrishnan
2023-08-04 14:02:50 +05:30
parent 2cdbf4d2c5
commit d79d24efad
6 changed files with 39 additions and 84 deletions
+37
View File
@@ -0,0 +1,37 @@
'use strict';
exports = module.exports = {
getRegistryConfig,
setRegistryConfig
};
const assert = require('assert'),
BoxError = require('../boxerror.js'),
docker = require('../docker.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
safe = require('safetydance');
async function getRegistryConfig(req, res, next) {
const [error, registryConfig] = await safe(docker.getRegistryConfig());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, docker.removePrivateFields(registryConfig)));
}
async function setRegistryConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
if (req.body.provider !== 'noop') {
if (typeof req.body.serverAddress !== 'string') return next(new HttpError(400, 'serverAddress is required'));
if ('username' in req.body && typeof req.body.username !== 'string') return next(new HttpError(400, 'username is required'));
if ('email' in req.body && typeof req.body.email !== 'string') return next(new HttpError(400, 'email is required'));
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password is required'));
}
const [error] = await safe(docker.setRegistryConfig(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200));
}