diff --git a/src/docker.js b/src/docker.js index 7f2c2c8fb..8a6afece6 100644 --- a/src/docker.js +++ b/src/docker.js @@ -59,11 +59,13 @@ const CLEARVOLUME_CMD = path.join(__dirname, 'scripts/clearvolume.sh'), const DOCKER_SOCKET_PATH = '/var/run/docker.sock'; const gConnection = new Docker({ socketPath: DOCKER_SOCKET_PATH }); -function testRegistryConfig(auth, callback) { - assert.strictEqual(typeof auth, 'object'); +function testRegistryConfig(config, callback) { + assert.strictEqual(typeof config, 'object'); assert.strictEqual(typeof callback, 'function'); - gConnection.checkAuth(auth, function (error /*, data */) { // this returns a 500 even for auth errors + if (config.provider === 'noop') return callback(); + + gConnection.checkAuth(config, function (error /*, data */) { // this returns a 500 even for auth errors if (error) return callback(new BoxError(BoxError.BAD_FIELD, error, { field: 'serverAddress' })); callback(); @@ -82,14 +84,14 @@ function removePrivateFields(registryConfig) { return registryConfig; } -function setRegistryConfig(auth, callback) { - assert.strictEqual(typeof auth, 'object'); +function setRegistryConfig(config, callback) { + assert.strictEqual(typeof config, 'object'); assert.strictEqual(typeof callback, 'function'); - const isLogin = !!auth.password; + const isLogin = !!config.password; // currently, auth info is not stashed in the db but maybe it should for restore to work? - const cmd = isLogin ? `docker login ${auth.serverAddress} --username ${auth.username} --password ${auth.password}` : `docker logout ${auth.serverAddress}`; + const cmd = isLogin ? `docker login ${config.serverAddress} --username ${config.username} --password ${config.password}` : `docker logout ${config.serverAddress}`; child_process.exec(cmd, { }, function (error /*, stdout, stderr */) { if (error) return callback(new BoxError(BoxError.ACCESS_DENIED, error.message)); @@ -135,12 +137,12 @@ function getRegistryConfig(image, callback) { } function pullImage(manifest, callback) { - getRegistryConfig(manifest.dockerImage, function (error, authConfig) { + getRegistryConfig(manifest.dockerImage, function (error, config) { if (error) return callback(error); - debug(`pullImage: will pull ${manifest.dockerImage}. auth: ${authConfig ? 'yes' : 'no'}`); + debug(`pullImage: will pull ${manifest.dockerImage}. auth: ${config ? 'yes' : 'no'}`); - gConnection.pull(manifest.dockerImage, { authconfig: authConfig }, function (error, stream) { + gConnection.pull(manifest.dockerImage, { authconfig: config }, function (error, stream) { if (error && error.statusCode === 404) return callback(new BoxError(BoxError.NOT_FOUND, `Unable to pull image ${manifest.dockerImage}. message: ${error.message} statusCode: ${error.statusCode}`)); if (error) return callback(new BoxError(BoxError.DOCKER_ERROR, `Unable to pull image ${manifest.dockerImage}. Please check the network or if the image needs authentication. statusCode: ${error.statusCode}`)); diff --git a/src/routes/settings.js b/src/routes/settings.js index 565579247..38ba3b352 100644 --- a/src/routes/settings.js +++ b/src/routes/settings.js @@ -194,11 +194,13 @@ function getRegistryConfig(req, res, next) { function setRegistryConfig(req, res, next) { assert.strictEqual(typeof req.body, 'object'); - if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required')); - 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')); + 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')); + } settings.setRegistryConfig(req.body, function (error) { if (error) return next(BoxError.toHttpError(error)); diff --git a/src/settings.js b/src/settings.js index 0dae6b9d2..f80af8d62 100644 --- a/src/settings.js +++ b/src/settings.js @@ -159,7 +159,9 @@ let gDefaults = (function () { provider: 'noop', autoCreate: false }; - result[exports.REGISTRY_CONFIG_KEY] = {}; + result[exports.REGISTRY_CONFIG_KEY] = { + provider: 'noop' + }; result[exports.SYSINFO_CONFIG_KEY] = { provider: 'generic' };