Skip to content

Commit eb45544

Browse files
fix issues with image (#65)
1 parent e910df1 commit eb45544

File tree

2 files changed

+44
-37
lines changed

2 files changed

+44
-37
lines changed

lib/interface/cli/commands/image/get.cmd.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ const command = new Command({
6767
let images;
6868
// TODO:need to decide for one way for error handeling
6969
if (imageId) {
70-
images = await image.getImageById(imageId);
70+
images = await image.getImageById({
71+
imageId,
72+
allRegistries,
73+
});
7174
} else {
7275
images = await image.getAll({
7376
labels,

lib/logic/api/image.js

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const _extractFieldsForImageEntity = (image, tag) => {
1212
name: image.imageDisplayName,
1313
size: filesize(image.size),
1414
};
15-
newImage.image_id = image.internalImageId ? image.internalImageId.substring(0, 12) : '';
15+
newImage.image_id = image.internalImageId ? image.internalImageId.substring(0, 12) : '\b';
1616
if (_.isEqual(tag, '<none>')) {
1717
newImage.tag = tag;
1818
newImage.pull = '';
@@ -28,6 +28,32 @@ const _extractFieldsForImageEntity = (image, tag) => {
2828
};
2929

3030

31+
const _extractImages = (image, options) => {
32+
const res = [];
33+
let addedCfCrTag = false;
34+
_.forEach(image.tags, (tag) => {
35+
// in case we are filtering by registries, ignore the image if it is not from the registires list
36+
if (options.filterRegistries && options.filterRegistries.indexOf(tag.registry) === -1) {
37+
return;
38+
}
39+
if (_.isEqual(tag.tag, 'volume')) {
40+
addedCfCrTag = true;
41+
return;
42+
}
43+
if (DEFAULTS.CODEFRESH_REGISTRIES.indexOf(tag.registry) !== -1) {
44+
addedCfCrTag = true;
45+
}
46+
const data = _extractFieldsForImageEntity(image, tag);
47+
res.push(new Image(data));
48+
});
49+
if (_.isEmpty(image.tags) || !addedCfCrTag) {
50+
const data = _extractFieldsForImageEntity(image, '<none>');
51+
res.push(new Image(data));
52+
}
53+
return res;
54+
};
55+
56+
3157
const getAll = async (options) => {
3258
const qs = {
3359
limit: options.limit,
@@ -52,49 +78,27 @@ const getAll = async (options) => {
5278
if (_.isEmpty(images)) {
5379
throw new CFError('Error from server (NotFound): Images not found');
5480
}
55-
const res = [];
81+
let res = [];
5682
_.forEach(images.docs, (image) => {
57-
let addedCfCrTag = false;
58-
_.forEach(image.tags, (tag) => {
59-
// in case we are filtering by registries, ignore the image if it is not from the registires list
60-
if (options.filterRegistries && options.filterRegistries.indexOf(tag.registry) === -1) {
61-
return;
62-
}
63-
if (_.isEqual(tag.tag, 'volume')) {
64-
addedCfCrTag = true;
65-
return;
66-
}
67-
if (DEFAULTS.CODEFRESH_REGISTRIES.indexOf(tag.registry) !== -1) {
68-
addedCfCrTag = true;
69-
}
70-
const data = _extractFieldsForImageEntity(image, tag);
71-
res.push(new Image(data));
72-
});
73-
if (_.isEmpty(image.tags) || !addedCfCrTag) {
74-
const data = _extractFieldsForImageEntity(image, '<none>');
75-
res.push(new Image(data));
76-
}
83+
res = res.concat(_extractImages(image, options));
7784
});
7885
return res;
7986
};
8087

81-
const getImageById = async (imageId) => {
82-
const options = {
83-
url: `/api/images/${encodeURIComponent(imageId)}`,
88+
const getImageById = async (options) => {
89+
const id = options.imageId;
90+
const RequestOptions = {
91+
url: `/api/images/${encodeURIComponent(id)}`,
8492
method: 'GET',
8593
};
86-
const image = await sendHttpRequest(options);
87-
if (_.isEmpty(image)) {
88-
throw new CFError(`Error from server (NotFound): Image ${imageId} not found`);
94+
const image = await sendHttpRequest(RequestOptions);
95+
if (!_.isEmpty(image)) {
96+
const res = _extractImages(image, options);
97+
if (!_.isEmpty(res)) {
98+
return res;
99+
}
89100
}
90-
const res = [];
91-
let data = {};
92-
_.forEach(image.tags, (tag) => {
93-
data = _extractFieldsForImageEntity(image, tag);
94-
res.push(new Image(data));
95-
});
96-
97-
return res;
101+
throw new CFError(`Error from server (NotFound): Image ${id} not found`);
98102
};
99103

100104
const getDockerImageId = async (imageDisplayName, tag) => {

0 commit comments

Comments
 (0)