remove settings route entirely, redundant by now
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
testRegistryConfig,
|
||||
injectPrivateFields,
|
||||
removePrivateFields,
|
||||
getRegistryConfig,
|
||||
setRegistryConfig,
|
||||
|
||||
ping,
|
||||
|
||||
@@ -84,15 +84,15 @@ async function ping() {
|
||||
throw new BoxError(BoxError.DOCKER_ERROR, 'Unable to ping the docker daemon');
|
||||
}
|
||||
|
||||
async function getRegistryConfig(image) {
|
||||
async function getAuthConfig(image) {
|
||||
// https://github.com/docker/distribution/blob/release/2.7/reference/normalize.go#L62
|
||||
const parts = image.split('/');
|
||||
if (parts.length === 1 || (parts[0].match(/[.:]/) === null)) return null; // public docker registry
|
||||
|
||||
const registryConfig = await settings.getRegistryConfig();
|
||||
const registryConfig = await getRegistryConfig();
|
||||
|
||||
// https://github.com/apocas/dockerode#pull-from-private-repos
|
||||
const auth = {
|
||||
const autoConfig = {
|
||||
username: registryConfig.username,
|
||||
password: registryConfig.password,
|
||||
auth: registryConfig.auth || '', // the auth token at login time
|
||||
@@ -100,15 +100,15 @@ async function getRegistryConfig(image) {
|
||||
serveraddress: registryConfig.serverAddress
|
||||
};
|
||||
|
||||
return auth;
|
||||
return autoConfig;
|
||||
}
|
||||
|
||||
async function pullImage(manifest) {
|
||||
const config = await getRegistryConfig(manifest.dockerImage);
|
||||
const authConfig = await getAuthConfig(manifest.dockerImage);
|
||||
|
||||
debug(`pullImage: will pull ${manifest.dockerImage}. auth: ${config ? 'yes' : 'no'}`);
|
||||
debug(`pullImage: will pull ${manifest.dockerImage}. auth: ${authConfig ? 'yes' : 'no'}`);
|
||||
|
||||
const [error, stream] = await safe(gConnection.pull(manifest.dockerImage, { authconfig: config }));
|
||||
const [error, stream] = await safe(gConnection.pull(manifest.dockerImage, { authconfig: authConfig }));
|
||||
if (error && error.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, `Unable to pull image ${manifest.dockerImage}. message: ${error.message} statusCode: ${error.statusCode}`);
|
||||
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Unable to pull image ${manifest.dockerImage}. Please check the network or if the image needs authentication. statusCode: ${error.statusCode}`);
|
||||
|
||||
@@ -654,3 +654,20 @@ async function update(name, memory, memorySwap) {
|
||||
|
||||
throw new BoxError(BoxError.DOCKER_ERROR, 'Unable to update container');
|
||||
}
|
||||
|
||||
async function getRegistryConfig() {
|
||||
const value = await settings.getJson(settings.REGISTRY_CONFIG_KEY);
|
||||
return value || { provider: 'noop' };
|
||||
}
|
||||
|
||||
async function setRegistryConfig(registryConfig) {
|
||||
assert.strictEqual(typeof registryConfig, 'object');
|
||||
|
||||
const currentConfig = await getRegistryConfig();
|
||||
|
||||
injectPrivateFields(registryConfig, currentConfig);
|
||||
|
||||
await testRegistryConfig(registryConfig);
|
||||
|
||||
await settings.setJson(settings.REGISTRY_CONFIG_KEY, registryConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user