-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathimageHelper.js
44 lines (39 loc) · 1.05 KB
/
imageHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { buildImageFullURIFromModel, imageContainsURL } from '@/react/docker/images/utils';
angular.module('portainer.docker').factory('ImageHelper', ImageHelperFactory);
function ImageHelperFactory() {
return {
isValidTag,
createImageConfigForContainer,
getImagesNamesForDownload,
removeDigestFromRepository,
imageContainsURL,
};
function isValidTag(tag) {
return tag.match(/^(?![\.\-])([a-zA-Z0-9\_\.\-])+$/g);
}
/**
*
* @param {Array<{tags: Array<string>; id: string;}>} images
* @returns {{names: string[]}}}
*/
function getImagesNamesForDownload(images) {
var names = images.map(function (image) {
return image.tags[0] !== '<none>:<none>' ? image.tags[0] : image.id;
});
return {
names,
};
}
/**
*
* @param {PorImageRegistryModel} registry
*/
function createImageConfigForContainer(imageModel) {
return {
fromImage: buildImageFullURIFromModel(imageModel),
};
}
function removeDigestFromRepository(repository) {
return repository.split('@sha')[0];
}
}