Files
cloudron-box/src/routes/docker.js
T

38 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict';
exports = module.exports = {
getRegistryConfig,
setRegistryConfig
};
2021-05-14 15:07:29 -07:00
const assert = require('assert'),
2019-10-25 15:58:11 -07:00
BoxError = require('../boxerror.js'),
2018-10-12 17:04:04 -07:00
docker = require('../docker.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
safe = require('safetydance');
2019-10-22 11:03:56 -07:00
2021-08-19 13:24:38 -07:00
async function getRegistryConfig(req, res, next) {
const [error, registryConfig] = await safe(docker.getRegistryConfig());
2021-08-19 13:24:38 -07:00
if (error) return next(BoxError.toHttpError(error));
2019-10-22 22:07:44 -07:00
2021-08-19 13:24:38 -07:00
next(new HttpSuccess(200, docker.removePrivateFields(registryConfig)));
2019-10-22 22:07:44 -07:00
}
2021-08-19 13:24:38 -07:00
async function setRegistryConfig(req, res, next) {
2018-10-12 17:04:04 -07:00
assert.strictEqual(typeof req.body, 'object');
2021-03-02 18:21:35 -08:00
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'));
}
2018-10-12 17:04:04 -07:00
const [error] = await safe(docker.setRegistryConfig(req.body));
2021-08-19 13:24:38 -07:00
if (error) return next(BoxError.toHttpError(error));
2018-10-12 17:04:04 -07:00
2021-08-19 13:24:38 -07:00
next(new HttpSuccess(200));
2018-10-12 17:04:04 -07:00
}