| 1 | package App::FargateStack::Builder; | ||||||||||||||||||||||||||||
| 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 App::FargateStack::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::FargateStack::Builder::Utils qw(log_die confirm dmp); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use CLI::Simple::Constants qw(:booleans); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Temp qw(tempfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use List::Util qw(pairs any none uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Text::ASCIITable::EasyTable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use YAML qw(DumpFile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | ######################################################################## | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub build { | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=32 SCAR=69.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | ######################################################################## | ||||||||||||||||||||||||||||
| 26 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $self->benchmark; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $domain = $config->{domain}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $subnets = $self->get_subnets(); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( !$self->get_force && !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->get_force or $dryrun
MC/DC0%0/2
$self->get_force or $dryrun
$self->get_force
$dryrun
Truth table0%0/3
A or B
A= $self->get_forceB= $dryrun
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( !confirm('You are about to apply changes and possibly create or update resources. Proceed?') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $self->log_die('Aborting...'); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $self->log_info( 'Beginning %s phase...', $dryrun ? 'plan' : 'apply' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # -- log groups -- | ||||||||||||||||||||||||||||
| 48 | 0 | $self->build_log_group; | |||||||||||||||||||||||||||
| 49 | 0 | $self->benchmark('log-groups'); | |||||||||||||||||||||||||||
| 50 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # -- task definitions -- | ||||||||||||||||||||||||||||
| 53 | 0 | $self->create_taskdef_files; | |||||||||||||||||||||||||||
| 54 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # -- certificate -- | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $domain && $self->has_https_service ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$domain and $self->has_https_service
MC/DC0%0/2
$domain and $self->has_https_service
$domain
$self->has_https_service
Truth table0%0/3
A and B
A= $domainB= $self->has_https_service
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->build_certificate; | |||||||||||||||||||||||||||
| 59 | 0 | $self->benchmark('certificate'); | |||||||||||||||||||||||||||
| 60 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # -- queue -- | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $config->{queue} && $config->{queue}->{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$config->{"queue"} and $config->{"queue"}{"name"}
MC/DC0%0/2
$config->{"queue"} and $config->{"queue"}{"name"}
$config->{"queue"}
$config->{"queue"}{"name"}
Truth table0%0/3
A and B
A= $config->{"queue"}B= $config->{"queue"}{"name"}
| |||||||||||||||||||||||||||||
| 65 | 0 | $self->build_queue; | |||||||||||||||||||||||||||
| 66 | 0 | $self->benchmark('queue'); | |||||||||||||||||||||||||||
| 67 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # -- bucket -- | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $config->{bucket} && $config->{bucket}->{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$config->{"bucket"} and $config->{"bucket"}{"name"}
MC/DC0%0/2
$config->{"bucket"} and $config->{"bucket"}{"name"}
$config->{"bucket"}
$config->{"bucket"}{"name"}
Truth table0%0/3
A and B
A= $config->{"bucket"}B= $config->{"bucket"}{"name"}
| |||||||||||||||||||||||||||||
| 72 | 0 | $self->build_bucket; | |||||||||||||||||||||||||||
| 73 | 0 | $self->benchmark('bucket'); | |||||||||||||||||||||||||||
| 74 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | ## -- iam -- | ||||||||||||||||||||||||||||
| 78 | 0 | $self->build_iam_role; | |||||||||||||||||||||||||||
| 79 | 0 | $self->benchmark('iam'); | |||||||||||||||||||||||||||
| 80 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | ## -- cluster -- | ||||||||||||||||||||||||||||
| 83 | 0 | $self->build_fargate_cluster; | |||||||||||||||||||||||||||
| 84 | 0 | $self->benchmark('cluster'); | |||||||||||||||||||||||||||
| 85 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | ## -- security group -- | ||||||||||||||||||||||||||||
| 88 | 0 | $self->build_security_group; | |||||||||||||||||||||||||||
| 89 | 0 | $self->benchmark('security-group'); | |||||||||||||||||||||||||||
| 90 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # -- task definitions -- | ||||||||||||||||||||||||||||
| 93 | 0 | foreach my $task_name ( keys %{$tasks} ) { | |||||||||||||||||||||||||||
| 94 | 0 | $self->register_task_definition($task_name); | |||||||||||||||||||||||||||
| 95 | 0 | $self->benchmark( 'register-task-definition:' . $task_name ); | |||||||||||||||||||||||||||
| 96 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # -- EFS ingress | ||||||||||||||||||||||||||||
| 100 | 0 | foreach my $task_name ( keys %{$tasks} ) { | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | next if !exists $tasks->{$task_name}->{efs} || !$tasks->{$task_name}->{efs}->{authorize_ingress}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $tasks->{$task_name}{"efs"} and $tasks->{$task_name}{"efs"}{"authorize_ingress"}
MC/DC0%0/2
exists $tasks->{$task_name}{"efs"} and $tasks->{$task_name}{"efs"}{"authorize_ingress"}
exists $tasks->{$task_name}{"efs"}
$tasks->{$task_name}{"efs"}{"authorize_ingress"}
Truth table0%0/3
A and B
A= exists $tasks->{$task_name}{"efs"}B= $tasks->{$task_name}{"efs"}{"authorize_ingress"}
| |||||||||||||||||||||||||||||
| 102 | 0 | my $efs_config = $tasks->{$task_name}->{efs}; | |||||||||||||||||||||||||||
| 103 | 0 | my $efs_id = $efs_config->{id}; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( !$self->is_efs_ingress_authorized($efs_config) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $self->log_warn( 'efs: authorizing task: [%s] ingress to EFS: [%s]...%s', $task_name, $efs_id, $dryrun ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | $self->authorize_efs_ingress( $config->{security_groups}->{fargate}->{group_id}, $efs_config ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 0 | $self->log_info( 'efs: ingress for [%s] to [%s]...already authorized...skipping', $task_name, $efs_id ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | $self->benchmark('efs-ingress'); | |||||||||||||||||||||||||||
| 115 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | ## -- events -- | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( $self->has_events ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->build_events; | |||||||||||||||||||||||||||
| 121 | 0 | $self->benchmark('events'); | |||||||||||||||||||||||||||
| 122 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | ## -- http service -- | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ( $self->get_http() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | $self->build_http_service; | |||||||||||||||||||||||||||
| 128 | 0 | $self->benchmark('http-service'); | |||||||||||||||||||||||||||
| 129 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | ## -- autoscaling | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ( $self->get_http() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | $self->build_autoscaling(); | |||||||||||||||||||||||||||
| 135 | 0 | $self->benchmark('autoscaling'); | |||||||||||||||||||||||||||
| 136 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # -- route53 (create alias) | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( $self->get_http ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | $self->create_alias(); | |||||||||||||||||||||||||||
| 142 | 0 | $self->benchmark('route53'); | |||||||||||||||||||||||||||
| 143 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # -- WAF | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ( $self->get_http() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | $self->build_waf(); | |||||||||||||||||||||||||||
| 149 | 0 | $self->benchmark('waf'); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # -- finished -- | ||||||||||||||||||||||||||||
| 153 | 0 | $self->log_info( 'builder: build completed in %ds', $self->benchmark('elapsed_time') ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $self->log_info( 'builder: %d resources will be created.', scalar keys %{ $self->get_required_resources // {} } // 0 ); | ||||||||||||||||||||||||||
|
Condition0%0/4
scalar keys %{$self->get_required_resources // {};} // 0
$self->get_required_resources // {}
MC/DC0%0/1
scalar keys %{$self->get_required_resources // {};} // 0
scalar keys %{$self->get_required_resources // {};}
MC/DC0%0/1
$self->get_required_resources // {}
$self->get_required_resources
Truth table0%0/2
A
A= scalar keys %{$self->get_required_resources // {};}
Truth table0%0/2
A
A= $self->get_required_resources
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $self->log_info( 'builder: %d resources already exist', scalar keys %{ $self->get_existing_resources // {} } // 0 ); | ||||||||||||||||||||||||||
|
Condition0%0/4
scalar keys %{$self->get_existing_resources // {};} // 0
$self->get_existing_resources // {}
MC/DC0%0/1
scalar keys %{$self->get_existing_resources // {};} // 0
scalar keys %{$self->get_existing_resources // {};}
MC/DC0%0/1
$self->get_existing_resources // {}
$self->get_existing_resources
Truth table0%0/2
A
A= scalar keys %{$self->get_existing_resources // {};}
Truth table0%0/2
A
A= $self->get_existing_resources
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $self->section_break; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | ## -- benchmarks -- | ||||||||||||||||||||||||||||
| 162 | 0 | my @benchmarks; | |||||||||||||||||||||||||||
| 163 | 0 | foreach my $p ( pairs $self->dump_benchmarks() ) { | |||||||||||||||||||||||||||
| 164 | 0 | push @benchmarks, { Resource => $p->[0], Time => $p->[1] }; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | my $table = easy_table( | |||||||||||||||||||||||||||
| 168 | columns => [qw(Resource Time)], | ||||||||||||||||||||||||||||
| 169 | data => \@benchmarks, | ||||||||||||||||||||||||||||
| 170 | table_options => { headingText => 'Benchmarks' }, | ||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | $self->log_info("\n$table"); | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # -- resources -- | ||||||||||||||||||||||||||||
| 176 | 0 | foreach my $p ( pairs Required => $self->get_required_resources, Existing => $self->get_existing_resources ) { | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | my $data = []; | |||||||||||||||||||||||||||
| 179 | 0 | my $resources = $p->[1]; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | foreach my $k ( sort keys %{$resources} ) { | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $value = resolve_resource_value( $resources->{$k} // $EMPTY, $self->get_dryrun ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$resources->{$k} // $App::FargateStack::Builder::EMPTY
MC/DC0%0/2
$resources->{$k} // $App::FargateStack::Builder::EMPTY
$resources->{$k}
$App::FargateStack::Builder::EMPTY
Truth table0%0/3
A // B
A= $resources->{$k}B= $App::FargateStack::Builder::EMPTY
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $value = sprintf '%s', join( "\n", @{$value} ) // $EMPTY; | ||||||||||||||||||||||||||
|
Condition0%0/3
join("\n", @{$value;}) // $App::FargateStack::Builder::EMPTY
MC/DC0%0/2
join("\n", @{$value;}) // $App::FargateStack::Builder::EMPTY
join("\n", @{$value;})
$App::FargateStack::Builder::EMPTY
Truth table0%0/3
A // B
A= join("\n", @{$value;})B= $App::FargateStack::Builder::EMPTY
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | push @{$data}, { Resource => $k, Value => $value }; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( @{$data} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | my $table = easy_table( | |||||||||||||||||||||||||||
| 190 | columns => [qw(Resource Value)], | ||||||||||||||||||||||||||||
| 191 | data => $data, | ||||||||||||||||||||||||||||
| 192 | table_options => { headingText => $p->[0] . ' Resources' } | ||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $level = $p->[0] eq 'Required' ? 'warn' : 'info'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | $self->get_logger->$level("\n$table"); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||
| 200 | 0 | $self->log_warn( 'builder: no %s resources', lc $p->[0] ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | $self->update_config; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | return; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # resolves the resource value from the hash of resources | ||||||||||||||||||||||||||||
| 210 | # TBD: better documentation of this method | ||||||||||||||||||||||||||||
| 211 | ######################################################################## | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub resolve_resource_value { | ||||||||||||||||||||||||||
|
Subroutine
resolve_resource_value: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 213 | ######################################################################## | ||||||||||||||||||||||||||||
| 214 | 0 | my ( $value, $dryrun ) = @_; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return [$value] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | if !ref $value; | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( reftype($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | my @values; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | foreach my $v ( @{$value} ) { | |||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ( ref $v && reftype($v) eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $v and builtin::reftype($v) eq "CODE"
MC/DC0%0/2
ref $v and builtin::reftype($v) eq "CODE"
ref $v
builtin::reftype($v) eq "CODE"
Truth table0%0/3
A and B
A= ref $vB= builtin::reftype($v) eq "CODE"
| |||||||||||||||||||||||||||||
| 224 | 0 | push @values, $v->($dryrun); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||
| 227 | 0 | push @values, $v; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | 0 | return \@values; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||
| 233 | 0 | return [ $value->($dryrun) ]; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | ######################################################################## | ||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub get_scheduled_action_names { | ||||||||||||||||||||||||||
|
Subroutine
get_scheduled_action_names: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 239 | ######################################################################## | ||||||||||||||||||||||||||||
| 240 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||
| 243 | 0 | my @scheduled_action_names; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | foreach ( keys %{ $config->{tasks} } ) { | |||||||||||||||||||||||||||
| 246 | 0 | ▶ | next if !exists $config->{tasks}->{$_}->{autoscaling}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | next if !exists $config->{tasks}->{$_}->{autoscaling}->{scheduled}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | push @scheduled_action_names, keys %{ $config->{tasks}->{$_}->{autoscaling}->{scheduled} }; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | return @scheduled_action_names; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | ######################################################################## | ||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub update_config_id { | ||||||||||||||||||||||||||
|
Subroutine
update_config_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 256 | ######################################################################## | ||||||||||||||||||||||||||||
| 257 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | $Data::Dumper::Sortkeys = $TRUE; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | delete $config->{id}; | |||||||||||||||||||||||||||
| 264 | 0 | delete $config->{last_updated}; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | my $md5_hex = md5_hex( Dumper( $self->get_config ) ); | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $config->{id} = $md5_hex; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | $config->{last_updated} = scalar localtime; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | return $config; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | ######################################################################## | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub update_config { | ||||||||||||||||||||||||||
|
Subroutine
update_config: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 277 | ######################################################################## | ||||||||||||||||||||||||||||
| 278 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | $self->log_warn( 'builder: config file %s %s be updated', $self->get_config_name, $self->get_update ? 'will' : 'will not' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | return | ||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if !$self->get_update; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | my ( $fh, $filename ) = tempfile( 'fargate-stack-XXXX', SUFFIX => '.yml' ); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | my $config = $self->update_config_id(); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | DumpFile( $filename, $config ); | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | my $config_name = $self->get_config_name; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | rename $config_name, "${config_name}.bak"; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | rename $filename, $config_name; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | return; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | ######################################################################## | ||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub configure_alb { | ||||||||||||||||||||||||||
|
Subroutine
configure_alb: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 302 | ######################################################################## | ||||||||||||||||||||||||||||
| 303 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | my $is_secure = $self->has_https_service; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | # default ALB type is private with a listener on port 80 | ||||||||||||||||||||||||||||
| 310 | 0 | ▶ | my $alb_config = $config->{alb} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"alb"} // {}
MC/DC0%0/1
$config->{"alb"} // {}
$config->{"alb"}
Truth table0%0/2
A
A= $config->{"alb"}
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | $alb_config->{type} //= $is_secure ? 'public' : 'private'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$alb_config->{"type"} //= $is_secure ? "public" : "private"
MC/DC0%0/1
$alb_config->{"type"} //= $is_secure ? "public" : "private"
$alb_config->{"type"}
Truth table0%0/2
A
A= $alb_config->{"type"}
| |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $alb_config->{port} //= $is_secure ? '443' : '80'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$alb_config->{"port"} //= $is_secure ? 443 : 80
MC/DC0%0/1
$alb_config->{"port"} //= $is_secure ? 443 : 80
$alb_config->{"port"}
Truth table0%0/2
A
A= $alb_config->{"port"}
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | # if it was already defined as public w/o a port, then 443 and | ||||||||||||||||||||||||||||
| 315 | # redirect 80 -> 443 | ||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ( $alb_config->{type} eq 'public' && !$alb_config->{port} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$alb_config->{"type"} eq "public" and not $alb_config->{"port"}
MC/DC0%0/2
$alb_config->{"type"} eq "public" and not $alb_config->{"port"}
$alb_config->{"type"} eq "public"
not $alb_config->{"port"}
Truth table0%0/3
A and not(B)
A= $alb_config->{"type"} eq "public"B= not $alb_config->{"port"}
| |||||||||||||||||||||||||||||
| 317 | 0 | $alb_config->{port} = '443'; | |||||||||||||||||||||||||||
| 318 | 0 | ▶ | if ( !defined $alb_config->{redirect_80} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 0 | $alb_config->{redirect_80} = $TRUE; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | croak "invalid alb type, must be 'public' or 'private'\n" | ||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if $alb_config->{type} !~ /^public|private$/xsm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | $config->{alb} = $alb_config; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | return; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | ######################################################################## | ||||||||||||||||||||||||||||
| 332 | 0 | ▶ | sub remove_listener_rules { | ||||||||||||||||||||||||||
|
Subroutine
remove_listener_rules: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 333 | ######################################################################## | ||||||||||||||||||||||||||||
| 334 | 0 | my ( $self, $alb_arn ) = @_; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | my ( $config, $dryrun ) = $self->common_args(qw(config dryrun)); | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | my $elb = $self->get_elbv2; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | my $domain = $config->{domain}; | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 0 | my $listeners = $elb->describe_listeners( $alb_arn, 'Listeners' ); | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | foreach my $listener ( @{$listeners} ) { | |||||||||||||||||||||||||||
| 345 | 0 | my $rules = $elb->describe_rules( $listener->{ListenerArn}, 'Rules' ); | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | foreach my $rule ( @{$rules} ) { | |||||||||||||||||||||||||||
| 348 | 0 | my $action = $rule->{Actions}->[0]; | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | my $conditions = $rule->{Conditions}->[0] || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$rule->{'Conditions'}[0] || []
MC/DC0%0/1
$rule->{'Conditions'}[0] || []
$rule->{'Conditions'}[0]
Truth table0%0/2
A
A= $rule->{'Conditions'}[0]
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | next | ||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if !$conditions; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | next | ||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if !$conditions->{Field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | next | ||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if $conditions->{Field} ne 'host-header'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | next | ||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if $conditions->{Values}->[0] ne $domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | $self->log_warn( 'removing App::FargateStack provisioned listener rule type: [%s] for port: [%s]...%s', | ||||||||||||||||||||||||||||
| 361 | 0 | $action->{Type}, $listener->{Port}, $dryrun ); | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 0 | $elb->delete_rule( $rule->{RuleArn} ); | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 0 | last; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 0 | return; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =pod | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | For multi-task configuration files we cannot delete these resources: | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | - role, policy | ||||||||||||||||||||||||||||
| 379 | - log group | ||||||||||||||||||||||||||||
| 380 | - Fargate security group | ||||||||||||||||||||||||||||
| 381 | - cluster | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | For http services we can delete | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | - ALB if it is was provisioned by App::FargateStack | ||||||||||||||||||||||||||||
| 386 | - ALB security group | ||||||||||||||||||||||||||||
| 387 | - Alias record | ||||||||||||||||||||||||||||
| 388 | - target group | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | For scheduled task we can delete | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | - rule | ||||||||||||||||||||||||||||
| 393 | - rule target | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | If only 1 task in the configuration file, we can delete the entire stack. | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | The task definition ARN will be deleted to indicate that the task resources were | ||||||||||||||||||||||||||||
| 398 | removed. | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | ######################################################################## | ||||||||||||||||||||||||||||
| 403 | # type = task|scheduled|daemon|https? | ||||||||||||||||||||||||||||
| 404 | ######################################################################## | ||||||||||||||||||||||||||||
| 405 | 0 | ▶ | sub delete_task_resources { | ||||||||||||||||||||||||||
|
Subroutine
delete_task_resources: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 406 | ######################################################################## | ||||||||||||||||||||||||||||
| 407 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 0 | my ( $config, $tasks, $dryrun, $security_groups, $cluster ) | |||||||||||||||||||||||||||
| 410 | = $self->common_args(qw(config tasks dryrun security_groups cluster)); | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 0 | my @active_tasks = grep { $tasks->{$_}->{arn} } keys %{$tasks}; | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | my $num_tasks = scalar @active_tasks; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 0 | ▶ | $config->{cluster} //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"cluster"} //= {}
MC/DC0%0/1
$config->{"cluster"} //= {}
$config->{"cluster"}
Truth table0%0/2
A
A= $config->{"cluster"}
| |||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | ▶ | $cluster->{name} //= $self->create_default('cluster-name'); | ||||||||||||||||||||||||||
|
Condition0%0/3
$cluster->{"name"} //= $self->create_default("cluster-name")
MC/DC0%0/2
$cluster->{"name"} //= $self->create_default("cluster-name")
$cluster->{"name"}
$self->create_default("cluster-name")
Truth table0%0/3
A //= B
A= $cluster->{"name"}B= $self->create_default("cluster-name")
| |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | # check to see if service is running before removing resources | ||||||||||||||||||||||||||||
| 421 | 0 | my $type = $tasks->{$task_name}->{type}; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if ( !$self->get_force ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | 0 | ▶ | return $SUCCESS | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | if !confirm( sprintf 'Are you sure you want to delete the %s (%s) task?', $task_name, $type ); | ||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ( $type =~ /^(?:https?|daemon)$/xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 0 | ▶ | $self->log_trace( sub { return Dumper( [ cluster => $cluster ] ); } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 0 | ▶ | log_die( $self, 'ERROR: service [%s] is still running...stop service first.', $task_name ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | if $self->is_service_running($task_name); | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 0 | $self->log_error('WARNING: "dryrun" mode not enabled...resources will be removed!'); | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | my $confirm_all = $self->get_confirm_all; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | ###################################################################### | ||||||||||||||||||||||||||||
| 442 | # -- delete log group | ||||||||||||||||||||||||||||
| 443 | ###################################################################### | ||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( $num_tasks == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 0 | $self->_delete_log_group( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | ###################################################################### | ||||||||||||||||||||||||||||
| 449 | # -- delete roles & policies | ||||||||||||||||||||||||||||
| 450 | ###################################################################### | ||||||||||||||||||||||||||||
| 451 | 0 | ▶ | if ( $num_tasks == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | $self->_delete_roles($confirm_all); | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | ###################################################################### | ||||||||||||||||||||||||||||
| 456 | # -- delete scheduled task | ||||||||||||||||||||||||||||
| 457 | ###################################################################### | ||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ( defined $tasks->{$task_name}->{schedule} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | 0 | $self->_delete_scheduled_task( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | ###################################################################### | ||||||||||||||||||||||||||||
| 463 | # -- delete task definitions | ||||||||||||||||||||||||||||
| 464 | ###################################################################### | ||||||||||||||||||||||||||||
| 465 | 0 | $self->_delete_task_definitions( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | ###################################################################### | ||||||||||||||||||||||||||||
| 468 | # -- delete service | ||||||||||||||||||||||||||||
| 469 | ###################################################################### | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ( $type =~ /^(?:daemon|https?)$/xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | #################################################################### | ||||||||||||||||||||||||||||
| 473 | # -- remove alias record | ||||||||||||||||||||||||||||
| 474 | #################################################################### | ||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if ( $type ne 'daemon' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 476 | 0 | $self->_delete_alias_record($confirm_all); | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 0 | $self->_delete_service( $confirm_all, $task_name, $type ); | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | ###################################################################### | ||||||||||||||||||||||||||||
| 483 | # -- delete http(s) | ||||||||||||||||||||||||||||
| 484 | ###################################################################### | ||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ( $type =~ /^(?:https?)$/xsm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | $self->_delete_http( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | #################################################################### | ||||||||||||||||||||||||||||
| 490 | # -- remove target group | ||||||||||||||||||||||||||||
| 491 | #################################################################### | ||||||||||||||||||||||||||||
| 492 | 0 | $self->_delete_target_group( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | ###################################################################### | ||||||||||||||||||||||||||||
| 495 | # -- delete security group | ||||||||||||||||||||||||||||
| 496 | ###################################################################### | ||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if ( $num_tasks == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | 0 | $self->_delete_security_group( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | ###################################################################### | ||||||||||||||||||||||||||||
| 502 | # -- delete cluster | ||||||||||||||||||||||||||||
| 503 | ###################################################################### | ||||||||||||||||||||||||||||
| 504 | 0 | ▶ | if ( $num_tasks == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | 0 | $self->_delete_cluster( $confirm_all, $task_name ); | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | ###################################################################### | ||||||||||||||||||||||||||||
| 509 | # -- iam role (resource changes may require new policy) | ||||||||||||||||||||||||||||
| 510 | ###################################################################### | ||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if ( $num_tasks != 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | 0 | $self->log_warn('iam: looking to see if we need to update role...'); | |||||||||||||||||||||||||||
| 513 | 0 | $self->build_iam_role(); | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | ###################################################################### | ||||||||||||||||||||||||||||
| 517 | # NOTE: Skeletons of deleted tasks are left in the confguration file | ||||||||||||||||||||||||||||
| 518 | # for single task config and for multi-task configs. --purge-config | ||||||||||||||||||||||||||||
| 519 | # will allow purging of tasks in multi-task configs only... | ||||||||||||||||||||||||||||
| 520 | ###################################################################### | ||||||||||||||||||||||||||||
| 521 | 0 | ▶ | if ( $self->get_purge_config ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 0 | delete $tasks->{$task_name}; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 0 | delete $config->{id}; | |||||||||||||||||||||||||||
| 527 | 0 | delete $config->{last_updated}; | |||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 0 | $self->update_config; | |||||||||||||||||||||||||||
| 530 | 0 | $self->log_info( | |||||||||||||||||||||||||||
| 531 | 'builder: A skeleton configuration remains that will allow you to recreate the stack. Run "app-FargateStack plan" to rehydrate your configuration.' | ||||||||||||||||||||||||||||
| 532 | ); | ||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | ######################################################################## | ||||||||||||||||||||||||||||
| 539 | 0 | ▶ | sub _delete_cluster { | ||||||||||||||||||||||||||
|
Subroutine
_delete_cluster: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 540 | ######################################################################## | ||||||||||||||||||||||||||||
| 541 | 0 | my ( $self, $confirm_all, $service_name, $type ) = @_; | |||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | my ( $config, $dryrun, $tasks, $cluster ) = $self->common_args(qw(config dryrun tasks cluster)); | |||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 0 | my $cluster_name = $cluster->{name}; | |||||||||||||||||||||||||||
| 546 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'cluster: delete cluster: [%s]', $cluster_name ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 549 | 0 | my $ecs = $self->fetch_ecs; | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 0 | $self->log_warn( 'cluster: [%s] will be deleted...%s', $cluster_name, $dryrun ); | |||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | 0 | my $result = $ecs->delete_cluster($cluster_name); | |||||||||||||||||||||||||||
| 555 | 0 | $ecs->check_result( | |||||||||||||||||||||||||||
| 556 | message => 'ERROR: could not delete cluster: [%s]', | ||||||||||||||||||||||||||||
| 557 | params => [$cluster_name], | ||||||||||||||||||||||||||||
| 558 | regexp => qr/nosuchentity/xmsi, | ||||||||||||||||||||||||||||
| 559 | warn => $TRUE, | ||||||||||||||||||||||||||||
| 560 | ); | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 0 | $self->log_warn( 'cluster: [%s] deleted successfully...status: [%s]', $cluster_name, $result->{cluster}->{status} ); | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 0 | delete $config->{cluster}; | |||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | else { | ||||||||||||||||||||||||||||
| 568 | 0 | $self->log_warn( 'cluster: deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||
| 570 | 0 | return; | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | ######################################################################## | ||||||||||||||||||||||||||||
| 574 | 0 | ▶ | sub _delete_alias_record { | ||||||||||||||||||||||||||
|
Subroutine
_delete_alias_record: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 575 | ######################################################################## | ||||||||||||||||||||||||||||
| 576 | 0 | my ( $self, $confirm_all, $service_name, $type ) = @_; | |||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 0 | my ( $config, $dryrun, $tasks, $alb ) = $self->common_args(qw(config dryrun tasks alb)); | |||||||||||||||||||||||||||
| 579 | 0 | my $domain = $config->{domain}; | |||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | return # belt & suspenders...we should never get here | ||||||||||||||||||||||||||||
| 582 | 0 | ▶ | if !$domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'route53: delete alias record for: [%s]', $domain ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 587 | 0 | $self->log_warn( 'route53: alias record for: [%s] will be deleted...%s', $domain, $dryrun ); | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 590 | 0 | $self->remove_alias_record( $alb->{arn} ); | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||
| 593 | else { | ||||||||||||||||||||||||||||
| 594 | 0 | $self->log_warn( 'route53: alias record deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 0 | return; | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | ######################################################################## | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | sub _delete_service { | ||||||||||||||||||||||||||
|
Subroutine
_delete_service: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 602 | ######################################################################## | ||||||||||||||||||||||||||||
| 603 | 0 | my ( $self, $confirm_all, $service_name, $type ) = @_; | |||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'service: delete %s service?', $type ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | 0 | $self->log_warn( 'service: [%s] will be deleted...%s', $service_name, $dryrun ); | |||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 614 | 0 | my $ecs = $self->fetch_ecs; | |||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 0 | $ecs->delete_service( $config->{cluster}->{name}, $service_name ); | |||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 0 | $ecs->check_result( | |||||||||||||||||||||||||||
| 619 | message => 'ERROR: could not delete ECS service: [%s]', | ||||||||||||||||||||||||||||
| 620 | params => [$service_name], | ||||||||||||||||||||||||||||
| 621 | regexp => qr/notfound/xsmi, | ||||||||||||||||||||||||||||
| 622 | warn => $TRUE, | ||||||||||||||||||||||||||||
| 623 | ); | ||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | else { | ||||||||||||||||||||||||||||
| 627 | 0 | $self->log_warn( 'service: deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | return; | |||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | ######################################################################## | ||||||||||||||||||||||||||||
| 634 | 0 | ▶ | sub _delete_task_definitions { | ||||||||||||||||||||||||||
|
Subroutine
_delete_task_definitions: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 635 | ######################################################################## | ||||||||||||||||||||||||||||
| 636 | 0 | my ( $self, $confirm_all, $task_name ) = @_; | |||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'task: delete all task definitions for: [%s]', $task_name ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 643 | 0 | my $ecs = $self->fetch_ecs; | |||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | 0 | my $task_definitions = $ecs->list_task_definitions( $task_name, 'taskDefinitionArns' ); | |||||||||||||||||||||||||||
| 646 | 0 | $self->log_warn( 'task: definitions for: [%s] will be deleted...%s', $task_name, $dryrun ); | |||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ( $task_definitions && @{$task_definitions} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$task_definitions and @{$task_definitions;}
MC/DC0%0/2
$task_definitions and @{$task_definitions;}
$task_definitions
@{$task_definitions;}
Truth table0%0/3
A and B
A= $task_definitionsB= @{$task_definitions;}
| |||||||||||||||||||||||||||||
| 650 | 0 | $ecs->delete_task_definitions($task_definitions); | |||||||||||||||||||||||||||
| 651 | 0 | $ecs->check_result( message => 'ERROR: could not delete task definitions' ); | |||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | 0 | $task_definitions = $ecs->list_task_definitions( $task_name, 'taskDefinitionArns' ); | |||||||||||||||||||||||||||
| 655 | 0 | $ecs->check_result( message => 'ERROR: could not list task definitions' ); | |||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | # this should happen...delete_task_definitions() will croak if a | ||||||||||||||||||||||||||||
| 658 | # task definition cannot be deregistered and deleted | ||||||||||||||||||||||||||||
| 659 | croak "ERROR: could not delete all task definitions\n" | ||||||||||||||||||||||||||||
| 660 | 0 | ▶ | if @{$task_definitions}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | 0 | delete $tasks->{$task_name}->{arn}; | |||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||
| 665 | else { | ||||||||||||||||||||||||||||
| 666 | 0 | $self->log_warn( 'task: definition deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | 0 | return; | |||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | ######################################################################## | ||||||||||||||||||||||||||||
| 673 | 0 | ▶ | sub _delete_scheduled_task { | ||||||||||||||||||||||||||
|
Subroutine
_delete_scheduled_task: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 674 | ######################################################################## | ||||||||||||||||||||||||||||
| 675 | 0 | my ( $self, $confirm_all, $task_name, $type ) = @_; | |||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | ###################################################################### | ||||||||||||||||||||||||||||
| 680 | # -- delete schedule task | ||||||||||||||||||||||||||||
| 681 | ###################################################################### | ||||||||||||||||||||||||||||
| 682 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'Delete scheduled task: [%s]', $task_name ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | # -- delete target event | ||||||||||||||||||||||||||||
| 686 | 0 | my $events = $self->fetch_events; | |||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 0 | my $rule_name = $self->create_default( 'rule-name', $task_name ); | |||||||||||||||||||||||||||
| 689 | 0 | my $rule_id = $self->create_default( 'rule-id', $task_name ); | |||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 0 | $self->log_warn( 'scheduled task: [%s] will be deleted...%s', $task_name, $dryrun ); | |||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | #################################################################### | ||||||||||||||||||||||||||||
| 694 | # -- remove target | ||||||||||||||||||||||||||||
| 695 | #################################################################### | ||||||||||||||||||||||||||||
| 696 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 697 | 0 | $self->log_warn( 'scheduled task: deleting target for rule: [%s:%s]', $rule_name, $rule_id ); | |||||||||||||||||||||||||||
| 698 | 0 | $events->remove_targets( $rule_name, $rule_id ); | |||||||||||||||||||||||||||
| 699 | 0 | $events->check_result( | |||||||||||||||||||||||||||
| 700 | message => 'ERROR: could not remove target for rule: [%s], id: [%s]', | ||||||||||||||||||||||||||||
| 701 | params => [ $rule_name, $rule_id ], | ||||||||||||||||||||||||||||
| 702 | regexp => qr/notfound/xsmi | ||||||||||||||||||||||||||||
| 703 | ); | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | #################################################################### | ||||||||||||||||||||||||||||
| 706 | # -- delete rule | ||||||||||||||||||||||||||||
| 707 | #################################################################### | ||||||||||||||||||||||||||||
| 708 | 0 | $self->log_warn( 'scheduled task: deleting rule: [%s]', $rule_name ); | |||||||||||||||||||||||||||
| 709 | 0 | $events->delete_rule($rule_name); | |||||||||||||||||||||||||||
| 710 | 0 | $events->check_result( message => 'ERROR: could not remove rule: [%s]', params => [$rule_name] ); | |||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | 0 | $self->log_warn( 'schedule task: scheduled task: [%s] successfully deleted...', $task_name ); | |||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||
| 715 | else { | ||||||||||||||||||||||||||||
| 716 | 0 | $self->log_warn( 'event deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | 0 | return; | |||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | ######################################################################## | ||||||||||||||||||||||||||||
| 723 | 0 | ▶ | sub _delete_roles { | ||||||||||||||||||||||||||
|
Subroutine
_delete_roles: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 724 | ######################################################################## | ||||||||||||||||||||||||||||
| 725 | 0 | my ( $self, $confirm_all ) = @_; | |||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | 0 | my ( $config, $dryrun ) = $self->common_args(qw(config dryrun)); | |||||||||||||||||||||||||||
| 728 | 0 | my $cluster_name = $config->{cluster}->{name}; | |||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'iam: delete roles & policies for cluster: [%s]?', $cluster_name ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | ###################################################################### | ||||||||||||||||||||||||||||
| 733 | # -- delete roles & policies | ||||||||||||||||||||||||||||
| 734 | ###################################################################### | ||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | 0 | my $iam = $self->fetch_iam(); | |||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 0 | ▶ | my @roles = ( 'role', 'task_role', defined $config->{events_role} ? 'events_role' : () ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | 0 | foreach my $r (@roles) { | |||||||||||||||||||||||||||
| 742 | 0 | my $role = $config->{$r}; | |||||||||||||||||||||||||||
| 743 | 0 | my ( $role_arn, $role_name, $policy_name ) = @{$role}{qw(arn name policy_name)}; | |||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | 0 | ▶ | if ( !defined $role_name && !defined $role_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $role_name or defined $role_arn
MC/DC0%0/2
defined $role_name or defined $role_arn
defined $role_name
defined $role_arn
Truth table0%0/3
A or B
A= defined $role_nameB= defined $role_arn
| |||||||||||||||||||||||||||||
| 746 | 0 | $self->log_warn('iam: role not defined in configuration...skipping deletion'); | |||||||||||||||||||||||||||
| 747 | 0 | delete $role->{arn}; | |||||||||||||||||||||||||||
| 748 | 0 | next; | |||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | #################################################################### | ||||||||||||||||||||||||||||
| 752 | # -- delete role policy | ||||||||||||||||||||||||||||
| 753 | #################################################################### | ||||||||||||||||||||||||||||
| 754 | 0 | $self->log_warn( 'iam: role: [%s] and policy: [%s] will be deleted...%s', $role_name, $policy_name, $dryrun ); | |||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 757 | 0 | $iam->delete_role_policy( $role_name, $policy_name ); | |||||||||||||||||||||||||||
| 758 | 0 | $iam->check_result( | |||||||||||||||||||||||||||
| 759 | message => 'ERROR: could not delete role policy: [%s]', | ||||||||||||||||||||||||||||
| 760 | params => [$policy_name], | ||||||||||||||||||||||||||||
| 761 | regexp => qr/nosuchentity/xsmi | ||||||||||||||||||||||||||||
| 762 | ); | ||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | 0 | delete $role->{policy_name}; | |||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | #################################################################### | ||||||||||||||||||||||||||||
| 767 | # -- delete role | ||||||||||||||||||||||||||||
| 768 | #################################################################### | ||||||||||||||||||||||||||||
| 769 | 0 | $iam->delete_role($role_name); | |||||||||||||||||||||||||||
| 770 | 0 | $iam->check_result( | |||||||||||||||||||||||||||
| 771 | message => 'ERROR: could not delete role: [%s]', | ||||||||||||||||||||||||||||
| 772 | params => [$role_name], | ||||||||||||||||||||||||||||
| 773 | regexp => qr/nosuchentity/xsmi | ||||||||||||||||||||||||||||
| 774 | ); | ||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||
| 776 | 0 | delete $role->{name}; | |||||||||||||||||||||||||||
| 777 | 0 | delete $role->{arn}; | |||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||
| 781 | else { | ||||||||||||||||||||||||||||
| 782 | 0 | $self->log_warn( 'iam: role & policy deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | 0 | return; | |||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | ######################################################################## | ||||||||||||||||||||||||||||
| 789 | 0 | ▶ | sub _delete_log_group { | ||||||||||||||||||||||||||
|
Subroutine
_delete_log_group: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 790 | ######################################################################## | ||||||||||||||||||||||||||||
| 791 | 0 | my ( $self, $confirm_all, $task_name ) = @_; | |||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||
| 795 | 0 | my ( $log_group, $log_group_arn ) = @{ $config->{log_group} }{qw(name arn)}; | |||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if ( !$log_group && !$log_group_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$log_group or $log_group_arn
MC/DC0%0/2
$log_group or $log_group_arn
$log_group
$log_group_arn
Truth table0%0/3
A or B
A= $log_groupB= $log_group_arn
| |||||||||||||||||||||||||||||
| 798 | 0 | $self->log_warn('logs: log group not defined in configuration file...skipping deletion'); | |||||||||||||||||||||||||||
| 799 | 0 | return; | |||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'logs: delete log group: [%s]?', $log_group ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if ( !$confirmed ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 805 | 0 | $self->log_warn('log: log group deletion skipped...'); | |||||||||||||||||||||||||||
| 806 | 0 | return; | |||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | 0 | my $logs = $self->fetch_logs(); | |||||||||||||||||||||||||||
| 810 | 0 | ▶ | if ( !$log_group ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 811 | 0 | $log_group = ( split /:/xsm, $log_group_arn )[-1]; | |||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||
| 814 | 0 | $self->log_warn( 'logs: log group: [%s] will be deleted...%s', $log_group, $dryrun ); | |||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | return | ||||||||||||||||||||||||||||
| 817 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||
| 819 | 0 | $logs->delete_log_group($log_group); | |||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||
| 821 | 0 | $logs->check_result( | |||||||||||||||||||||||||||
| 822 | message => 'ERROR: could not delete log group: %s', | ||||||||||||||||||||||||||||
| 823 | params => [$log_group], | ||||||||||||||||||||||||||||
| 824 | regexp => qr/notfound/xsmi | ||||||||||||||||||||||||||||
| 825 | ); | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | 0 | delete $config->{log_group}; | |||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | 0 | return; | |||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||
| 832 | ######################################################################## | ||||||||||||||||||||||||||||
| 833 | 0 | ▶ | sub _delete_security_group { | ||||||||||||||||||||||||||
|
Subroutine
_delete_security_group: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 834 | ######################################################################## | ||||||||||||||||||||||||||||
| 835 | 0 | my ( $self, $confirm_all, $task_name ) = @_; | |||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | 0 | my ( $config, $dryrun, $security_groups, $tasks ) = $self->common_args(qw(config dryrun security_groups tasks)); | |||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | 0 | my $ec2 = $self->fetch_ec2; | |||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | 0 | my $efs_config = $tasks->{$task_name}->{efs}; | |||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||
| 843 | 0 | my $sg_id = $security_groups->{fargate}->{group_id}; | |||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||
| 845 | 0 | ▶ | if ( !$sg_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 846 | 0 | $self->log_warn('ec2: no security group defined in configuration...skipping deletion'); | |||||||||||||||||||||||||||
| 847 | 0 | return; | |||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'ec2: delete security_group: [%s]?', $sg_id ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 853 | 0 | ▶ | if ( $efs_config && $efs_config->{authorize_ingress} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$efs_config and $efs_config->{"authorize_ingress"}
MC/DC0%0/2
$efs_config and $efs_config->{"authorize_ingress"}
$efs_config
$efs_config->{"authorize_ingress"}
Truth table0%0/3
A and B
A= $efs_configB= $efs_config->{"authorize_ingress"}
| |||||||||||||||||||||||||||||
| 854 | 0 | $self->log_warn( q{ec2: fargate task's ingress to EFS will be revoked...%s}, $dryrun ); | |||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 857 | 0 | $self->revoke_efs_ingress( $sg_id, $efs_config->{id} ); | |||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | 0 | $self->log_warn( 'ec2: security group: [%s] will be deleted...%s', $sg_id, $dryrun ); | |||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||
| 863 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | 0 | ▶ | while ($TRUE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 866 | 0 | $ec2->delete_security_group($sg_id); | |||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||
| 868 | 0 | $ec2->check_result( | |||||||||||||||||||||||||||
| 869 | message => 'ERROR: could not delete security_group: %s', | ||||||||||||||||||||||||||||
| 870 | params => [$sg_id], | ||||||||||||||||||||||||||||
| 871 | regexp => qr/notfound|invalid|dependency/xsmi | ||||||||||||||||||||||||||||
| 872 | ); | ||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||
| 874 | 0 | ▶ | last if !$ec2->get_error || $ec2->get_error !~ /dependency/xsmi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ec2->get_error and $ec2->get_error =~ /dependency/imsx
MC/DC0%0/2
$ec2->get_error and $ec2->get_error =~ /dependency/imsx
$ec2->get_error
$ec2->get_error =~ /dependency/imsx
Truth table0%0/3
A and B
A= $ec2->get_errorB= $ec2->get_error =~ /dependency/imsx
| |||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||
| 876 | 0 | sleep 2; | |||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||
| 878 | 0 | $self->log_info('ec2: waiting for ENI to release security group...'); | |||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | 0 | delete $security_groups->{fargate}; | |||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||
| 885 | else { | ||||||||||||||||||||||||||||
| 886 | 0 | $self->log_warn( 'ec2: security group deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | 0 | return; | |||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | ######################################################################## | ||||||||||||||||||||||||||||
| 893 | 0 | ▶ | sub _delete_target_group { | ||||||||||||||||||||||||||
|
Subroutine
_delete_target_group: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 894 | ######################################################################## | ||||||||||||||||||||||||||||
| 895 | 0 | my ( $self, $confirm_all, $task_name ) = @_; | |||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||
| 897 | 0 | my ( $tasks, $dryrun ) = $self->common_args(qw(tasks dryrun)); | |||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||
| 899 | 0 | my $elbv2 = $self->fetch_elbv2; | |||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | 0 | my $target_group_arn = $tasks->{$task_name}->{target_group_arn}; | |||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | 0 | ▶ | if ( !$target_group_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 904 | 0 | $self->log_warn('elbv2: no target group defined in configuration...skipping target group deletion'); | |||||||||||||||||||||||||||
| 905 | 0 | return $FALSE; | |||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||
| 908 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'elbv2: delete target group for task: [%s]', $task_name ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 911 | 0 | $self->log_warn( 'elbv2: target group for task: [%s] will be removed...%s', $task_name, $dryrun ); | |||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 914 | 0 | $elbv2->delete_target_group($target_group_arn); | |||||||||||||||||||||||||||
| 915 | 0 | $elbv2->check_result( message => 'ERROR: could not delete target group: [%s]', params => [$target_group_arn] ); | |||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | 0 | delete $tasks->{$task_name}->{target_group_arn}; | |||||||||||||||||||||||||||
| 918 | 0 | delete $tasks->{$task_name}->{target_group_name}; | |||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||
| 921 | else { | ||||||||||||||||||||||||||||
| 922 | 0 | $self->log_warn( 'elbv2: target group deletion skipped...%s', $dryrun ); | |||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||
| 925 | 0 | return; | |||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | ######################################################################## | ||||||||||||||||||||||||||||
| 929 | 0 | ▶ | sub _delete_http { | ||||||||||||||||||||||||||
|
Subroutine
_delete_http: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||
| 930 | ######################################################################## | ||||||||||||||||||||||||||||
| 931 | 0 | my ( $self, $confirm_all, $task_name ) = @_; | |||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | 0 | my ( $config, $tasks, $dryrun, $security_groups ) = $self->common_args(qw(config tasks dryrun security_groups)); | |||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | 0 | my $alb_sg = $security_groups->{alb}->{group_id}; | |||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | 0 | my $alb_arn = $config->{alb}->{arn}; | |||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | 0 | ▶ | if ( !$alb_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 940 | 0 | $self->log_warn('elbv2: no ALB in config...skipping ALB teardown'); | |||||||||||||||||||||||||||
| 941 | 0 | return $FALSE; | |||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||
| 944 | 0 | my $target_group_arn = $tasks->{$task_name}->{target_group_arn}; | |||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||
| 946 | 0 | ▶ | if ( !$target_group_arn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 947 | 0 | $self->log_warn('elbv2: no target group in config...skipping ALB teardown'); | |||||||||||||||||||||||||||
| 948 | 0 | return $FALSE; | |||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | 0 | my $type = $tasks->{$task_name}->{type}; | |||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'elbv2: delete %s service?', $type ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | 0 | ▶ | if ( !$confirmed ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 956 | 0 | $self->log_warn( 'elbv2: skipping deletion of %s service', $task_name ); | |||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||
| 958 | 0 | return; | |||||||||||||||||||||||||||
| 959 | } | ||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||
| 961 | #################################################################### | ||||||||||||||||||||||||||||
| 962 | # -- remove ALB if it was provisioned by App::FargateStack | ||||||||||||||||||||||||||||
| 963 | #################################################################### | ||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||
| 965 | 0 | ▶ | if ( !$self->alb_exists($alb_arn) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 966 | 0 | delete $config->{alb}->{arn}; | |||||||||||||||||||||||||||
| 967 | 0 | $self->log_warn( 'elbv2: ALB: [%s] does not exists...skipping deletion', $alb_arn ); | |||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||
| 969 | 0 | return; | |||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | 0 | my $is_our_alb = $self->is_our_alb( $alb_arn, $target_group_arn ); | |||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||
| 974 | 0 | ▶ | if ( !$is_our_alb ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 975 | 0 | $self->log_warn('elbv2: ALB was not provisioned by App::FargateStack...only deleting listerner rules.'); | |||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||
| 977 | 0 | ▶ | my $confirmed = $confirm_all ? confirm( 'elbv2: delete listener rules on ALB: [%s]?', $alb_arn ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||
| 979 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 980 | 0 | $self->log_warn( 'elbv2: listener rules for ALB: [%s] will be deleted...%s', $alb_arn, $dryrun ); | |||||||||||||||||||||||||||
| 981 | 0 | $self->remove_listener_rules($alb_arn); | |||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||
| 983 | else { | ||||||||||||||||||||||||||||
| 984 | 0 | $self->log_warn('elbv2: skipping deletion of listener rules'); | |||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||
| 987 | 0 | return; | |||||||||||||||||||||||||||
| 988 | } | ||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||
| 990 | 0 | ▶ | $confirmed = $confirm_all ? confirm( 'elbv2: delete ALB: [%s]?', $alb_arn ) : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||
| 992 | 0 | ▶ | if ($confirmed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 993 | 0 | $self->log_warn( 'elbv2: ALB: [%s] and its listener rules will be deleted...%s', $alb_arn, $dryrun ); | |||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||
| 995 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 996 | 0 | my $ec2 = $self->fetch_ec2; | |||||||||||||||||||||||||||
| 997 | 0 | my $elbv2 = $self->fetch_elbv2; | |||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||
| 999 | 0 | $elbv2->delete_load_balancer($alb_arn); | |||||||||||||||||||||||||||
| 1000 | 0 | $elbv2->check_result( message => 'could not delete load balancer: [%s]', params => [$alb_arn] ); | |||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||
| 1002 | 0 | ▶ | if ( $self->wait_for_alb_delete() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1003 | 0 | $self->log_warn( 'elbv2: successfully deleted ALB: [%s]', $alb_arn ); | |||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||
| 1005 | 0 | delete $config->{alb}->{arn}; | |||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||
| 1007 | else { | ||||||||||||||||||||||||||||
| 1008 | 0 | log_die( $self, 'elbv2: deletion of ALB: [%s] may have failed or has not completed yet.', $alb_arn ); | |||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||
| 1011 | #################################################################### | ||||||||||||||||||||||||||||
| 1012 | # -- remove security group | ||||||||||||||||||||||||||||
| 1013 | #################################################################### | ||||||||||||||||||||||||||||
| 1014 | 0 | $self->log_warn( 'elbv2: security group for ALB on task: [%s] will be removed...%s', $task_name, $dryrun ); | |||||||||||||||||||||||||||
| 1015 | $ec2->revoke_security_group_ingress( | ||||||||||||||||||||||||||||
| 1016 | group_id => $config->{security_groups}->{fargate}->{group_id}, | ||||||||||||||||||||||||||||
| 1017 | source_group => $alb_sg, | ||||||||||||||||||||||||||||
| 1018 | port => $config->{alb}->{port}, | ||||||||||||||||||||||||||||
| 1019 | 0 | protocol => 'tcp', | |||||||||||||||||||||||||||
| 1020 | ); | ||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||
| 1022 | 0 | my $err = 'dependency'; | |||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | while ( $err =~ /dependency/xsmi ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1025 | 0 | $ec2->delete_security_group($alb_sg); | |||||||||||||||||||||||||||
| 1026 | 0 | sleep 2; | |||||||||||||||||||||||||||
| 1027 | 0 | $err = $ec2->get_error; | |||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||
| 1030 | $ec2->check_result( | ||||||||||||||||||||||||||||
| 1031 | 0 | message => 'ERROR: could not delete security group: [%s]', | |||||||||||||||||||||||||||
| 1032 | params => [$alb_sg], | ||||||||||||||||||||||||||||
| 1033 | regexp => qr/notfound/xsmi | ||||||||||||||||||||||||||||
| 1034 | ); | ||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||
| 1036 | 0 | delete $security_groups->{alb}; | |||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||
| 1039 | else { | ||||||||||||||||||||||||||||
| 1040 | 0 | $self->log_warn('elbv2: skipping deletion of ALB'); | |||||||||||||||||||||||||||
| 1041 | } | ||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||
| 1043 | 0 | return; | |||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | ######################################################################## | ||||||||||||||||||||||||||||
| 1047 | 0 | ▶ | sub alb_exists { | ||||||||||||||||||||||||||
|
Subroutine
alb_exists: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1048 | ######################################################################## | ||||||||||||||||||||||||||||
| 1049 | 0 | my ( $self, $alb_arn ) = @_; | |||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||
| 1051 | return | ||||||||||||||||||||||||||||
| 1052 | 0 | ▶ | if !$alb_arn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | 0 | my $elbv2 = $self->fetch_elbv2; | |||||||||||||||||||||||||||
| 1055 | 0 | $elbv2->describe_load_balancer($alb_arn); | |||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||
| 1057 | 0 | ▶ | return $elbv2->get_error =~ /notfound/xsmi ? $FALSE : $TRUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||
| 1060 | ######################################################################## | ||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | sub wait_for_alb_delete { | ||||||||||||||||||||||||||
|
Subroutine
wait_for_alb_delete: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1062 | ######################################################################## | ||||||||||||||||||||||||||||
| 1063 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||
| 1065 | 0 | my $alb_arn = $self->get_config->{alb}->{arn}; | |||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||
| 1067 | 0 | my $tries = $DEFAULT_ALB_MAX_TRIES; | |||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||
| 1069 | 0 | my $elbv2 = $self->fetch_elbv2; | |||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||
| 1071 | 0 | ▶ | while ( $tries-- > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1072 | 0 | my $result = $elbv2->describe_load_balancer($alb_arn); | |||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||
| 1074 | 0 | $self->log_debug( Dumper( [ result => $result ] ) ); | |||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||
| 1076 | 0 | ▶ | return $TRUE if !$result && $elbv2->get_error =~ /notfound/xsmi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $result and $elbv2->get_error =~ /notfound/imsx
MC/DC0%0/2
not $result and $elbv2->get_error =~ /notfound/imsx
not $result
$elbv2->get_error =~ /notfound/imsx
Truth table0%0/3
not(A) and B
A= not $resultB= $elbv2->get_error =~ /notfound/imsx
| |||||||||||||||||||||||||||||
| 1077 | 0 | sleep $DEFAULT_ALB_POLL_SLEEP_TIME; | |||||||||||||||||||||||||||
| 1078 | } | ||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||
| 1080 | 0 | return $FALSE; | |||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||
| 1083 | ######################################################################## | ||||||||||||||||||||||||||||
| 1084 | 0 | ▶ | sub is_our_alb { | ||||||||||||||||||||||||||
|
Subroutine
is_our_alb: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1085 | ######################################################################## | ||||||||||||||||||||||||||||
| 1086 | 0 | my ( $self, $alb_arn, $tg_arn ) = @_; | |||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||
| 1088 | 0 | my $elb = $self->get_elbv2; | |||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||
| 1090 | 0 | ▶ | croak "usage: is_our_alb(alb-arn, target-group-arn)\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$alb_arn and $tg_arn
MC/DC0%0/2
$alb_arn and $tg_arn
$alb_arn
$tg_arn
Truth table0%0/3
A and B
A= $alb_arnB= $tg_arn
| |||||||||||||||||||||||||||||
| 1091 | if !$alb_arn || !$tg_arn; | ||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||
| 1093 | 0 | my $tags = $elb->describe_tags( $alb_arn, 'TagDescriptions[].Tags[]' ); | |||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | 0 | ▶ | my ($ours) = grep { $_->{Key} eq 'CreatedBy' && $_->{Value} eq 'FargateStack' } @{$tags}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'Key'} eq 'CreatedBy' && $_->{'Value'} eq 'FargateStack'
MC/DC0%0/2
$_->{'Key'} eq 'CreatedBy' && $_->{'Value'} eq 'FargateStack'
$_->{'Key'} eq 'CreatedBy'
$_->{'Value'} eq 'FargateStack'
Truth table0%0/3
A && B
A= $_->{'Key'} eq 'CreatedBy'B= $_->{'Value'} eq 'FargateStack'
| |||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||
| 1097 | 0 | ▶ | return $TRUE | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1098 | if $ours; | ||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||
| 1100 | # get listener rules and see if our ALB is default by finding | ||||||||||||||||||||||||||||
| 1101 | # default and seeing if its target group (if any) is our target | ||||||||||||||||||||||||||||
| 1102 | # group... | ||||||||||||||||||||||||||||
| 1103 | 0 | my $result = $elb->describe_listeners( $alb_arn, 'Listeners[0]' ); | |||||||||||||||||||||||||||
| 1104 | 0 | $elb->check_result( message => 'ERROR: could not describe listeners for: [%s]', $alb_arn ); | |||||||||||||||||||||||||||
| 1105 | 0 | my $listener_arn = $result->{ListenerArn}; | |||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||
| 1107 | 0 | $result = $elb->describe_rules( $result->{ListenerArn}, 'Rules[]' ); | |||||||||||||||||||||||||||
| 1108 | 0 | $elb->check_result( message => 'ERROR: could not describe rule for listener: [%s]', $listener_arn ); | |||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||
| 1110 | 0 | my ($default) = grep { $_->{IsDefault} } @{$result}; | |||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||
| 1112 | 0 | my $default_tg_arn = $default->{Actions}->[0]->{TargetGroupArn}; | |||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | return $default_tg_arn && $default_tg_arn eq $tg_arn; | ||||||||||||||||||||||||||
|
Condition0%0/3
$default_tg_arn && $default_tg_arn eq $tg_arn
MC/DC0%0/2
$default_tg_arn && $default_tg_arn eq $tg_arn
$default_tg_arn
$default_tg_arn eq $tg_arn
Truth table0%0/3
A && B
A= $default_tg_arnB= $default_tg_arn eq $tg_arn
| |||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||
| 1117 | ######################################################################## | ||||||||||||||||||||||||||||
| 1118 | 0 | ▶ | sub remove_alias_record { | ||||||||||||||||||||||||||
|
Subroutine
remove_alias_record: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1119 | ######################################################################## | ||||||||||||||||||||||||||||
| 1120 | 0 | my ( $self, $alb_arn ) = @_; | |||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||
| 1122 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||
| 1124 | 0 | my $elb = $self->fetch_elbv2; | |||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||
| 1126 | 0 | my $domain = $config->{domain}; | |||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | 0 | my $route53 = $self->fetch_route53; | |||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | 0 | my $zone_id = $config->{route53}->{zone_id}; | |||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||
| 1132 | 0 | my $query = sprintf 'ResourceRecordSets[?Name == `%s.`]', $domain; | |||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||
| 1134 | 0 | my $resource_record_set = $route53->list_resource_record_sets( $zone_id, $query ); | |||||||||||||||||||||||||||
| 1135 | 0 | $route53->check_result( | |||||||||||||||||||||||||||
| 1136 | message => 'ERROR: could not list resource record sets in zone: [%s]', | ||||||||||||||||||||||||||||
| 1137 | params => [$zone_id], | ||||||||||||||||||||||||||||
| 1138 | regexp => | ||||||||||||||||||||||||||||
| 1139 | ); | ||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||
| 1141 | 0 | ▶ | if ( !@{$resource_record_set} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1142 | 0 | $self->log_warn( 'route53: alias record for: [%s]not found...skipping deletion', $domain ); | |||||||||||||||||||||||||||
| 1143 | 0 | return; | |||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||
| 1146 | 0 | my $change_batch = { | |||||||||||||||||||||||||||
| 1147 | ChangeBatch => { | ||||||||||||||||||||||||||||
| 1148 | Changes => [ | ||||||||||||||||||||||||||||
| 1149 | { Action => 'DELETE', | ||||||||||||||||||||||||||||
| 1150 | ResourceRecordSet => $resource_record_set->[0], | ||||||||||||||||||||||||||||
| 1151 | } | ||||||||||||||||||||||||||||
| 1152 | ] | ||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||
| 1154 | }; | ||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||
| 1156 | 0 | $route53->change_resource_record_sets( $zone_id, $change_batch ); | |||||||||||||||||||||||||||
| 1157 | 0 | $route53->check_result( | |||||||||||||||||||||||||||
| 1158 | message => 'ERROR: could not delete alias record for domain: [%s]', | ||||||||||||||||||||||||||||
| 1159 | params => [$domain], | ||||||||||||||||||||||||||||
| 1160 | regexp => qr/not\sfound/xsmi, | ||||||||||||||||||||||||||||
| 1161 | warn => $TRUE, | ||||||||||||||||||||||||||||
| 1162 | ); | ||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||
| 1164 | 0 | return; | |||||||||||||||||||||||||||
| 1165 | } | ||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||
| 1167 | ######################################################################## | ||||||||||||||||||||||||||||
| 1168 | 0 | ▶ | sub get_efs_sgs { | ||||||||||||||||||||||||||
|
Subroutine
get_efs_sgs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1169 | ######################################################################## | ||||||||||||||||||||||||||||
| 1170 | 0 | my ( $self, $efs_config ) = @_; | |||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||
| 1172 | 0 | my $ec2 = $self->get_ec2; | |||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | 0 | my $efs = $self->fetch_efs(); | |||||||||||||||||||||||||||
| 1175 | 0 | my $efs_id = $efs_config->{id}; | |||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||
| 1177 | 0 | my $eni_list = $efs->describe_mount_targets( $efs_id, 'MountTargets[].NetworkInterfaceId' ); | |||||||||||||||||||||||||||
| 1178 | 0 | $efs->check_result( message => 'ERROR: could not describe mount targets for: [%s]', $efs_id ); | |||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | 0 | my $sgs = $ec2->describe_network_interfaces( $eni_list, 'NetworkInterfaces[].Groups[].GroupId' ); | |||||||||||||||||||||||||||
| 1181 | 0 | $ec2->check_result( message => 'ERROR: could not describe network interfaces for: [%s]', join q{,}, @{$eni_list} ); | |||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||
| 1183 | 0 | $efs_config->{security_groups} = [ uniq @{$sgs} ]; | |||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||
| 1185 | 0 | return $efs_config->{security_groups}; | |||||||||||||||||||||||||||
| 1186 | } | ||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||
| 1188 | ######################################################################## | ||||||||||||||||||||||||||||
| 1189 | 0 | ▶ | sub is_efs_ingress_authorized { | ||||||||||||||||||||||||||
|
Subroutine
is_efs_ingress_authorized: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1190 | ######################################################################## | ||||||||||||||||||||||||||||
| 1191 | 0 | my ( $self, $efs_config ) = @_; | |||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||
| 1193 | 0 | my $fargate_sg = $self->get_config->{security_groups}->{fargate}->{group_id}; | |||||||||||||||||||||||||||
| 1194 | 0 | my $efs_sgs = $efs_config->{security_groups}; | |||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | 0 | my $ec2 = $self->fetch_ec2; | |||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | 0 | my $filters = sprintf 'Name=group-id,Values=%s', join q{,}, @{$efs_sgs}; | |||||||||||||||||||||||||||
| 1199 | 0 | my $query = sprintf 'SecurityGroupRules[?IsEgress == `false` && ReferencedGroupInfo.GroupId == `%s`]|[0]', $fargate_sg; | |||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||
| 1201 | 0 | my $ingress_rules = $ec2->describe_security_group_rules( | |||||||||||||||||||||||||||
| 1202 | filters => $filters, | ||||||||||||||||||||||||||||
| 1203 | query => $query | ||||||||||||||||||||||||||||
| 1204 | ); | ||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||
| 1206 | 0 | $ec2->check_result( message => 'ERROR: could not describe security group rules', join q{,}, @{$efs_sgs} ); | |||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||
| 1208 | return | ||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | if !$ingress_rules; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||
| 1211 | 0 | ▶ | return $ingress_rules->{FromPort} == $DEFAULT_EFS_PORT && $ingress_rules->{ToPort} == $DEFAULT_EFS_PORT; | ||||||||||||||||||||||||||
|
Condition0%0/3
$ingress_rules->{'FromPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT && $ingress_rules->{'ToPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT
MC/DC0%0/2
$ingress_rules->{'FromPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT && $ingress_rules->{'ToPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT
$ingress_rules->{'FromPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT
$ingress_rules->{'ToPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT
Truth table0%0/3
A && B
A= $ingress_rules->{'FromPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORTB= $ingress_rules->{'ToPort'} == $App::FargateStack::Builder::DEFAULT_EFS_PORT
| |||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||
| 1214 | ######################################################################## | ||||||||||||||||||||||||||||
| 1215 | 0 | ▶ | sub authorize_efs_ingress { | ||||||||||||||||||||||||||
|
Subroutine
authorize_efs_ingress: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1216 | ######################################################################## | ||||||||||||||||||||||||||||
| 1217 | 0 | my ( $self, $task_sg, $efs_config ) = @_; | |||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||
| 1219 | 0 | my $dryrun = $self->get_dryrun; | |||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||
| 1221 | 0 | ▶ | my $efs_sgs = $efs_config->{security_groups} // $self->get_efs_sgs($efs_config); | ||||||||||||||||||||||||||
|
Condition0%0/3
$efs_config->{"security_groups"} // $self->get_efs_sgs($efs_config)
MC/DC0%0/2
$efs_config->{"security_groups"} // $self->get_efs_sgs($efs_config)
$efs_config->{"security_groups"}
$self->get_efs_sgs($efs_config)
Truth table0%0/3
A // B
A= $efs_config->{"security_groups"}B= $self->get_efs_sgs($efs_config)
| |||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||
| 1223 | 0 | dmp efs_config => $efs_config; | |||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||
| 1225 | 0 | my $ec2 = $self->fetch_ec2; | |||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||
| 1227 | return | ||||||||||||||||||||||||||||
| 1228 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||
| 1230 | 0 | foreach my $efs_sg ( @{$efs_sgs} ) { | |||||||||||||||||||||||||||
| 1231 | 0 | $ec2->authorize_security_group_ingress( | |||||||||||||||||||||||||||
| 1232 | 'group_id' => $efs_sg, | ||||||||||||||||||||||||||||
| 1233 | 'protocol' => 'tcp', | ||||||||||||||||||||||||||||
| 1234 | 'port' => $DEFAULT_EFS_PORT, | ||||||||||||||||||||||||||||
| 1235 | 'source_group' => $task_sg, | ||||||||||||||||||||||||||||
| 1236 | ); | ||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||
| 1238 | last | ||||||||||||||||||||||||||||
| 1239 | 0 | ▶ | if !$ec2->check_result( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1240 | { message => 'ERROR: could not authorize ingress for: [%s] to EFS: [%s]', | ||||||||||||||||||||||||||||
| 1241 | params => [ $task_sg, $efs_sg ], | ||||||||||||||||||||||||||||
| 1242 | regexp => qr/already\sexists/xsmi | ||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||
| 1244 | ); # assume if one ingress rule exists on the sg, all exist? | ||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||
| 1247 | 0 | return; | |||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||
| 1250 | ######################################################################## | ||||||||||||||||||||||||||||
| 1251 | 0 | ▶ | sub revoke_efs_ingress { | ||||||||||||||||||||||||||
|
Subroutine
revoke_efs_ingress: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1252 | ######################################################################## | ||||||||||||||||||||||||||||
| 1253 | 0 | my ( $self, $task_sg, $efs_id ) = @_; | |||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||
| 1255 | 0 | my @efs_sgs = $self->get_efs_sgs($efs_id); | |||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||
| 1257 | 0 | my $ec2 = $self->get_ec2; | |||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||
| 1259 | 0 | foreach my $efs_sg (@efs_sgs) { | |||||||||||||||||||||||||||
| 1260 | 0 | my $result = $ec2->revoke_security_group_ingress( | |||||||||||||||||||||||||||
| 1261 | '--group-id' => $efs_sg, | ||||||||||||||||||||||||||||
| 1262 | '--protocol' => 'tcp', | ||||||||||||||||||||||||||||
| 1263 | '--port' => $DEFAULT_EFS_PORT, | ||||||||||||||||||||||||||||
| 1264 | '--source-group' => $task_sg, | ||||||||||||||||||||||||||||
| 1265 | ); | ||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||
| 1267 | 0 | ▶ | next if $result || $ec2->get_error =~ /notfound/xsmi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$result or $ec2->get_error =~ /notfound/imsx
MC/DC0%0/2
$result or $ec2->get_error =~ /notfound/imsx
$result
$ec2->get_error =~ /notfound/imsx
Truth table0%0/3
A or B
A= $resultB= $ec2->get_error =~ /notfound/imsx
| |||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||
| 1269 | 0 | croak sprintf "ERROR: could not revoke security group ingress for: [%s]\n%s", $efs_sg, $ec2->get_error; | |||||||||||||||||||||||||||
| 1270 | } | ||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||
| 1272 | 0 | return; | |||||||||||||||||||||||||||
| 1273 | } | ||||||||||||||||||||||||||||
| 1274 | |||||||||||||||||||||||||||||
| 1275 | 1 | 1; | |||||||||||||||||||||||||||