Skip to content

Commit

Permalink
fix: devworkspace-container-registry-dockercfg secret (#610)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Aug 31, 2022
1 parent 4f33239 commit 8a147fc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/dto/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IPatch {
}

export interface IDockerConfig {
dockerconfig: string | undefined;
dockerconfig: string;
resourceVersion?: string;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/dashboard-backend/src/constants/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@

export const dockerConfigExample = {
get dockerconfig() {
const registry = 'quay.io';
const registry = 'https://index.docker.io/v1/';
const username = 'janedoe';
const password = 'xxxxxxxxxxxxxxxxxxxxxxx';
const auth = new Buffer(`${username}:${password}`).toString('base64');
const buff = new Buffer(
JSON.stringify({
auths: {
[registry]: { auth },
[registry]: {
username,
password,
auth,
},
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { helpers } from '@eclipse-che/common';

const SECRET_KEY = '.dockerconfigjson';
const SECRET_NAME = 'devworkspace-container-registry-dockercfg';
const SECRET_LABELS = { 'controller.devfile.io/devworkspace_pullsecret': 'true' };
const SECRET_LABELS = {
'controller.devfile.io/devworkspace_pullsecret': 'true',
'controller.devfile.io/watch-secret': 'true',
};
const DOCKER_CONFIG_API_ERROR_LABEL = 'CORE_V1_API_ERROR';

export class DockerConfigApi implements IDockerConfigApi {
Expand Down Expand Up @@ -73,7 +76,7 @@ export class DockerConfigApi implements IDockerConfigApi {
return {
apiVersion: 'v1',
data: {
[SECRET_KEY]: dockerCfg.dockerconfig || '',
[SECRET_KEY]: dockerCfg.dockerconfig,
},
kind: 'Secret',
metadata: {
Expand All @@ -84,8 +87,8 @@ export class DockerConfigApi implements IDockerConfigApi {
};
}

private getDockerConfig(secret?: V1Secret): string | undefined {
return secret?.data?.[SECRET_KEY];
private getDockerConfig(secret?: V1Secret): string {
return secret?.data?.[SECRET_KEY] || '';
}

private toDockerConfig(secret?: V1Secret): api.IDockerConfig {
Expand All @@ -99,7 +102,7 @@ export class DockerConfigApi implements IDockerConfigApi {
if (!secret.metadata) {
secret.metadata = {};
}
secret.data = { [SECRET_KEY]: dockerCfg.dockerconfig || '' };
secret.data = { [SECRET_KEY]: dockerCfg.dockerconfig };
secret.metadata.labels = SECRET_LABELS;
if (dockerCfg.resourceVersion) {
secret.metadata.resourceVersion = dockerCfg.resourceVersion;
Expand Down
22 changes: 11 additions & 11 deletions packages/dashboard-frontend/src/store/DockerConfig/dw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ function putDockerConfig(
registries: RegistryEntry[],
resourceVersion?: string,
): Promise<api.IDockerConfig> {
const configObj = { auths: {} };
const dockerconfig: api.IDockerConfig = { dockerconfig: '' };
const config: api.IDockerConfig = { dockerconfig: '' };
try {
const authInfo = { auths: {} };
registries.forEach(item => {
const { url, username, password } = item;
configObj.auths[url] = {};
configObj.auths[url].auth = window.btoa(username + ':' + password);
authInfo.auths[url] = { username, password };
authInfo.auths[url].auth = window.btoa(username + ':' + password);
});
dockerconfig.dockerconfig = window.btoa(JSON.stringify(configObj));
config.dockerconfig = window.btoa(JSON.stringify(authInfo));
if (resourceVersion) {
dockerconfig.resourceVersion = resourceVersion;
config.resourceVersion = resourceVersion;
}
try {
return DwApi.putDockerConfig(namespace, config);
} catch (err) {
throw 'Failed to update the docker cofig. Reason: ' + helpers.errors.getMessage(err);
}
} catch (e) {
throw 'Unable to parse and code data. Reason: ' + helpers.errors.getMessage(e);
}
try {
return DwApi.putDockerConfig(namespace, dockerconfig);
} catch (e) {
throw 'Failed to update the docker cofig. Reason: ' + helpers.errors.getMessage(e);
}
}

const unloadedState: State = {
Expand Down

0 comments on commit 8a147fc

Please sign in to comment.