2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2023-08-04 14:02:50 +05:30
|
|
|
getRegistryConfig,
|
|
|
|
|
setRegistryConfig
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
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'),
|
2015-07-20 00:09:47 -07:00
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
|
|
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
2023-08-04 14:02:50 +05:30
|
|
|
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) {
|
2023-08-04 14:02:50 +05:30
|
|
|
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
|
|
|
|
2023-08-04 14:02:50 +05:30
|
|
|
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
|
|
|
}
|