ECR.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 57 CC 4 SCAR 13.9
CC
4
Cov
0%
describe_images
6.0
get_latest_image
6.0
validate_images
6.0
CRAP 4.0
1 package App::ECR;
2  
3 use strict;
4 use warnings;
5  
6 use Carp;
7 use English qw(-no_match_vars);
8  
9 use Role::Tiny::With;
10 with 'App::AWS';
11  
12 __PACKAGE__->follow_best_practice;
13 __PACKAGE__->mk_accessors(qw(profile region));
14  
15 use parent qw(App::Command);
16  
17 ########################################################################
18 sub describe_images {
19 ########################################################################
20 my ( $self, $repository_name, $query ) = @_;
21  
22 return $self->command(
23 'describe-images' => [
24 '--repository-name' => $repository_name,
25 $query ? ( '--query' => $query ) : ()
26 ]
27 );
28 }
29  
30 ########################################################################
31 sub get_latest_image {
32 ########################################################################
33 my ( $self, $repository_name ) = @_;
34  
35 if ( $repository_name =~ /\//xsm ) {
36 $repository_name = ( split /\//xsm, $repository_name )[-1];
37 }
38  
39 ($repository_name) = split /:/xsm, $repository_name;
40  
41 my $query = 'imageDetails[?imageTags != null && contains(imageTags, `latest`)]';
42  
43 my $result = $self->describe_images( $repository_name, $query );
44  
45 return @{ $result || [] };
46 }
47  
48 ########################################################################
49 sub validate_images {
50 ########################################################################
51 my ( $self, @images ) = @_;
52  
53 foreach my $image (@images) {
54 warn sprintf "WARN: image not found in ECR: [%s]\n", $image
55 if !$self->get_latest_image($image);
56 }
57  
58 return;
59 }
60  
61 1;