FargateStack/Builder/Cluster.pm

filter: Statementstmt 36.6% 22 / 60 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 2 totaltotal 27.6% 29 / 105 CC 13 SCAR 39.6
CC
13
Cov
26%
build_fargate_cluster
110.0
add_ecr_policy
12.0
__ANON__
6.0
CRAP 52.5
« FargateStack/Builder/S3Bucket.pm ↑ Summary WafV2.pm »
1 package App::FargateStack::Builder::Cluster;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use App::FargateStack::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 ########################################################################
15 0 ▶sub build_fargate_cluster {
Subroutine build_fargate_cluster: not called CC=10 SCAR=47.0
Pod undocumented
16 ########################################################################
17 0 my ($self) = @_;
18  
19 0 my ( $config, $cluster, $dryrun ) = $self->common_args(qw(config cluster dryrun));
20  
21 0 ▶ $cluster //= {};
Condition0%0/2
$cluster //= {}
l!l
00
MC/DC0%0/1
$cluster //= {}
$cluster
Truth table0%0/2
A
A= $cluster
Aresult
11
00
22  
23 0 my $ecs = $self->fetch_ecs;
24  
25 0 my ( $cluster_name, $cluster_arn ) = @{$cluster}{qw(name arn)};
26  
27 0 ▶ if ( !$cluster_name || !$cluster_arn ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cluster_name and $cluster_arn) 0 0 0
Condition0%0/3
$cluster_name and $cluster_arn
!ll&&!rl&&r
000
MC/DC0%0/2
$cluster_name and $cluster_arn
$cluster_name $cluster_arn
Truth table0%0/3
A and B
A= $cluster_nameB= $cluster_arn
ABresult
0X0
100
111
28 0 ▶ $config->{cluster} //= $cluster;
Condition0%0/3
$config->{"cluster"} //= $cluster
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"cluster"} //= $cluster
$config->{"cluster"} $cluster
Truth table0%0/3
A //= B
A= $config->{"cluster"}B= $cluster
ABresult
1X1
011
000
29 0 $cluster_name = $self->create_default('cluster-name');
30 0 $cluster->{name} = $cluster_name;
31 }
32  
33 ## - cluster exists? -
34 0 ▶ if ( !$cluster_arn || !$self->get_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cluster_arn and $self->get_cache) 0 0 0
Condition0%0/3
$cluster_arn and $self->get_cache
!ll&&!rl&&r
000
MC/DC0%0/2
$cluster_arn and $self->get_cache
$cluster_arn $self->get_cache
Truth table0%0/3
A and B
A= $cluster_arnB= $self->get_cache
ABresult
0X0
100
111
35 # - validate cluster arn
36 0 $cluster_arn = $ecs->cluster_exists($cluster_name);
37 }
38  
39 0 ▶ if ($cluster_arn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cluster_arn) 0 0 0
40 0 ▶ $self->log_info( sprintf 'cluster: [%s] exists...%s', $cluster_name, $self->get_cache || 'skipping' );
Condition0%0/2
$self->get_cache || 'skipping'
l!l
00
MC/DC0%0/1
$self->get_cache || 'skipping'
$self->get_cache
Truth table0%0/2
A
A= $self->get_cache
Aresult
11
00
41  
42 0 $self->inc_existing_resources( cluster => [$cluster_arn] );
43 0 $cluster->{arn} = $cluster_arn;
44  
45 0 return;
46 }
47  
48 ## - create cluster -
49 0 $self->log_warn( sprintf 'cluster: [%s] will be created...%s', $cluster_name, $dryrun );
50  
51 $self->inc_required_resources(
52 0 ▶ cluster => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 my ($dryrun) = @_;
54 0 ▶ return $dryrun ? "arn:???/$cluster_name" : $config->{cluster}->{arn};
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
55 }
56 0 );
57  
58 return
59 0 ▶ if $dryrun;
Branch: 1 branch
BranchTrueFalseTotal
if $dryrun 0 0 0
60  
61 0 my $result = $ecs->create_cluster($cluster_name);
62 0 $ecs->check_result( 'ERROR: could not create cluster [%s]', $cluster_name );
63  
64 0 $self->log_warn( sprintf 'cluster: [%s] created...', $cluster_name );
65  
66 0 $cluster->{arn} = $result->{cluster}->{clusterArn};
67  
68 0 return $TRUE;
69 }
70  
71 ########################################################################
72 0 ▶sub add_ecr_policy {
Subroutine add_ecr_policy: not called CC=3 SCAR=24.8
Pod undocumented
73 ########################################################################
74 0 my ($self) = @_;
75  
76 0 my $tasks = $self->get_config->{tasks};
77  
78 0 my @repos;
79  
80 0 foreach my $task_name ( keys %{$tasks} ) {
81 0 my $image = $self->resolve_image_name( $tasks->{$task_name}->{image} );
82 0 ▶ if ( $image =~ m{/}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($image =~ m[/]msx) 0 0 0
83 0 ($image) = ( split m{/}xsm, $image )[-1];
84 }
85  
86 0 my ( $name, $tag ) = split /:/xsm, $image;
87 0 push @repos, sprintf $ECR_ARN_TEMPLATE, $self->get_region, $self->get_account, $name;
88 }
89  
90 return (
91 0 { Effect => 'Allow',
92 Action => ['ecr:GetAuthorizationToken'],
93 Resource => q{*}
94 },
95 { Effect => 'Allow',
96 Action => [qw(ecr:BatchGetImage ecr:GetDownloadUrlForLayer ecr:BatchCheckLayerAvailability)],
97 Resource => \@repos,
98 }
99 );
100 }
101  
102 1 1;
« FargateStack/Builder/S3Bucket.pm ↑ Summary WafV2.pm »