@@ -164,9 +164,7 @@ const parseImageURI = async (
164164 logger : pino . Logger ,
165165 uri : string ,
166166) : Promise < ImageDescriptor > => {
167- const match = uri . match (
168- / \/ ( [ A - Z a - z 0 - 9 _ - ] + ) .( s h a 2 5 6 : [ A - F a - f 0 - 9 ] { 64 } | [ A - F a - f 0 - 9 ] { 40 } ) $ / ,
169- ) ;
167+ const match = uri . match ( / \. a m a z o n a w s \. c o m \/ ( [ A - Z a - z 0 - 9 _ - ] + ) : ( .+ ) $ / ) ;
170168
171169 if (
172170 match === null ||
@@ -175,13 +173,14 @@ const parseImageURI = async (
175173 ) {
176174 // If match is an array, 1 and 2 will always be strings, but typescript
177175 // doesn't know that.
176+ logger . fatal ( `Attempted to parse URI: ${ uri } ` ) ;
178177 throw new Error ( "Unable to parse ECR Image URI." ) ;
179178 }
180179 const repo = match [ 1 ] ;
181180 const imageID = match [ 2 ] ;
182181
183182 // 64 character hash + 'sha256: = 71'
184- if ( imageID . length === 71 ) {
183+ if ( imageID . length === 71 && imageID . includes ( "sha256:" ) ) {
185184 logger . debug ( `We got a digest in the image URI: ${ imageID } ` ) ;
186185
187186 return {
@@ -190,7 +189,7 @@ const parseImageURI = async (
190189 imageDigest : imageID ,
191190 } ,
192191 } ;
193- } else if ( imageID . length === 40 ) {
192+ } else {
194193 logger . debug ( `We got a tag in the image URI: ${ imageID } ` ) ;
195194
196195 const input = {
@@ -217,8 +216,6 @@ const parseImageURI = async (
217216 imageTag : imageID ,
218217 } ,
219218 } ;
220- } else {
221- throw new Error ( "Something went wrong with our regex" ) ;
222219 }
223220} ;
224221
@@ -315,12 +312,9 @@ const scanNeedsAlert = async (
315312
316313 if ( await isFindingIgnored ( finding ) ) {
317314 logger . debug ( `Ignoring vulnerability '${ finding . name } '` ) ;
318- } else if ( await isClusterSnoozed ( cluster ) ) {
319- logger . debug ( `Cluster '${ cluster } ' has been snoozed. Skipping alert` ) ;
320315 } else {
321316 // There was a vulnerability >= our alert level that was not ignored.
322317 logger . debug ( `Found open vulnerability '${ finding . name } '.` ) ;
323-
324318 return true ;
325319 }
326320 }
@@ -400,6 +394,12 @@ const handler: Handler<Input, void> = async (
400394 } ) ;
401395 const { ERROR_TOPIC_ARN , ALERT_SEVERITY_LEVEL } = getEnv ( ) ;
402396
397+ // Check if the cluster is snoozed before doing anything else
398+ if ( await isClusterSnoozed ( cluster ) ) {
399+ logger . debug ( `Cluster '${ cluster } ' has been snoozed. Skipping it` ) ;
400+ return ;
401+ }
402+
403403 const now = new Date ( ) ;
404404 const alertLevel = ALERT_SEVERITY_LEVEL ;
405405 const images = await getContainerImages ( ecs , cluster , logger ) ;
0 commit comments