@@ -17,7 +17,11 @@ import {
1717 ILocalWorkloadLocator ,
1818 Telemetry ,
1919} from '../transmitter/types' ;
20- import { IPullableImage , IScanImage } from './images/types' ;
20+ import {
21+ IPullableImage ,
22+ IScanImage ,
23+ SkopeoRepositoryType ,
24+ } from './images/types' ;
2125import {
2226 getWorkloadAlreadyScanned ,
2327 getWorkloadImageAlreadyScanned ,
@@ -29,7 +33,7 @@ export async function processWorkload(
2933) : Promise < void > {
3034 // every workload metadata references the same workload name, grab it from the first one
3135 const workloadName = workloadMetadata [ 0 ] . name ;
32- const uniqueImages : IScanImage [ ] = getUniqueImages ( workloadMetadata ) ;
36+ const uniqueImages = getUniqueImages ( workloadMetadata ) ;
3337
3438 logger . info (
3539 { workloadName, imageCount : uniqueImages . length } ,
@@ -74,42 +78,37 @@ export async function sendDeleteWorkloadRequest(
7478}
7579
7680export function getUniqueImages ( workloadMetadata : IWorkload [ ] ) : IScanImage [ ] {
77- const uniqueImages : { [ key : string ] : IScanImage } = workloadMetadata . reduce (
78- ( accum , meta ) => {
79- logger . info (
80- {
81- workloadName : workloadMetadata [ 0 ] . name ,
82- name : meta . imageName ,
83- id : meta . imageId ,
84- } ,
85- 'image metadata' ,
86- ) ;
87- // example: For DCR "redis:latest"
88- // example: For GCR "gcr.io/test-dummy/redis:latest"
89- // example: For ECR "291964488713.dkr.ecr.us-east-2.amazonaws.com/snyk/redis:latest"
90- // meta.imageName can be different depends on CR
91- const { imageName } = getImageParts ( meta . imageName ) ;
92- // meta.imageId can be different depends on CR
93- // example: For DCR "docker.io/library/redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
94- // example: For GCR "sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
95- // example: For ECR "sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
96- let digest : string | undefined = undefined ;
97- if (
98- meta . imageId . lastIndexOf ( '@' ) > - 1 ||
99- meta . imageId . startsWith ( 'sha' )
100- ) {
101- digest = meta . imageId . substring ( meta . imageId . lastIndexOf ( '@' ) + 1 ) ;
102- }
103-
104- accum [ meta . imageName ] = {
105- imageWithDigest : digest && `${ imageName } @${ digest } ` ,
106- imageName : meta . imageName , // Image name with tag
107- } ;
108-
109- return accum ;
110- } ,
111- { } ,
112- ) ;
81+ const uniqueImages = workloadMetadata . reduce ( ( accum , meta ) => {
82+ logger . info (
83+ {
84+ workloadName : workloadMetadata [ 0 ] . name ,
85+ name : meta . imageName ,
86+ id : meta . imageId ,
87+ } ,
88+ 'image metadata' ,
89+ ) ;
90+ // example: For DCR "redis:latest"
91+ // example: For GCR "gcr.io/test-dummy/redis:latest"
92+ // example: For ECR "291964488713.dkr.ecr.us-east-2.amazonaws.com/snyk/redis:latest"
93+ // meta.imageName can be different depends on CR
94+ const { imageName } = getImageParts ( meta . imageName ) ;
95+ // meta.imageId can be different depends on CR
96+ // example: For DCR "docker.io/library/redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
97+ // example: For GCR "sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
98+ // example: For ECR "sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6"
99+ let digest : string | undefined = undefined ;
100+ if ( meta . imageId . lastIndexOf ( '@' ) > - 1 || meta . imageId . startsWith ( 'sha' ) ) {
101+ digest = meta . imageId . substring ( meta . imageId . lastIndexOf ( '@' ) + 1 ) ;
102+ }
103+
104+ accum [ meta . imageName ] = {
105+ imageWithDigest : digest && `${ imageName } @${ digest } ` ,
106+ imageName : meta . imageName , // Image name with tag
107+ skopeoRepoType : SkopeoRepositoryType . DockerArchive ,
108+ } ;
109+
110+ return accum ;
111+ } , { } as Record < string , IScanImage > ) ;
113112
114113 return Object . values ( uniqueImages ) ;
115114}
@@ -121,7 +120,7 @@ async function scanImagesAndSendResults(
121120 telemetry : Partial < Telemetry > ,
122121) : Promise < void > {
123122 const imageScanStartTimestampMs = Date . now ( ) ;
124- const scannedImages = await scanImages ( pulledImages ) ;
123+ const scannedImages = await scanImages ( pulledImages , telemetry ) ;
125124 const imageScanDurationMs = Date . now ( ) - imageScanStartTimestampMs ;
126125
127126 if ( scannedImages . length === 0 ) {
0 commit comments