@@ -12,7 +12,7 @@ const _extractFieldsForImageEntity = (image, tag) => {
12
12
name : image . imageDisplayName ,
13
13
size : filesize ( image . size ) ,
14
14
} ;
15
- newImage . image_id = image . internalImageId ? image . internalImageId . substring ( 0 , 12 ) : '' ;
15
+ newImage . image_id = image . internalImageId ? image . internalImageId . substring ( 0 , 12 ) : '\b ' ;
16
16
if ( _ . isEqual ( tag , '<none>' ) ) {
17
17
newImage . tag = tag ;
18
18
newImage . pull = '' ;
@@ -28,6 +28,32 @@ const _extractFieldsForImageEntity = (image, tag) => {
28
28
} ;
29
29
30
30
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
+
31
57
const getAll = async ( options ) => {
32
58
const qs = {
33
59
limit : options . limit ,
@@ -52,49 +78,27 @@ const getAll = async (options) => {
52
78
if ( _ . isEmpty ( images ) ) {
53
79
throw new CFError ( 'Error from server (NotFound): Images not found' ) ;
54
80
}
55
- const res = [ ] ;
81
+ let res = [ ] ;
56
82
_ . 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 ) ) ;
77
84
} ) ;
78
85
return res ;
79
86
} ;
80
87
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 ) } ` ,
84
92
method : 'GET' ,
85
93
} ;
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
+ }
89
100
}
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` ) ;
98
102
} ;
99
103
100
104
const getDockerImageId = async ( imageDisplayName , tag ) => {
0 commit comments