FargateStack/Init.pm

filter: Statementstmt 15.5% 38 / 244 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 68 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 42.8% 12 / 28 Podpod 0.0% 0 / 2 totaltotal 10.8% 50 / 461 CC 66 SCAR 47.3
CC
66
Cov
10%
_init_route53
272.0
init
210.0
_init_tasks
132.0
CRAP 112.9
« Events.pm ↑ Summary FargateStack/Builder/LogGroup.pm »
1 package App::FargateStack::Init;
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(jmespath_mapping toCamelCase log_die dmp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use English qw(no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::Util qw(any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use YAML qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '1.0.50';
20  
21 ########################################################################
22 0 ▶sub init {
Subroutine init: not called CC=14 SCAR=53.5
Pod undocumented
23 ########################################################################
24 0 my ($self) = @_;
25  
26 0 ▶ if ( $self->get_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_version) 0 0 0
27 0 $self->set__command('version');
28 0 return $TRUE;
29 }
30  
31 0 my $command = $self->command;
32  
33 0 ▶ if ( $self->get_config ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_config) 0 0 0
34 0 $self->set_config_name( $self->get_config );
35 }
36  
37 0 ▶ if ( $self->get_history ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_history) 0 0 0
38 0 $self->fetch_option_defaults;
39 }
40  
41 0 my $cmd_spec = $self->commands->{$command};
42  
43 0 ▶ my $cmd_options = reftype($cmd_spec) eq 'ARRAY' ? $cmd_spec->[2] // {} : {};
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($cmd_spec) eq 'ARRAY' ? : 0 0 0
Condition0%0/2
$cmd_spec->[2] // {}
l!l
00
MC/DC0%0/1
$cmd_spec->[2] // {}
$cmd_spec->[2]
Truth table0%0/2
A
A= $cmd_spec->[2]
Aresult
11
00
44  
45 0 my ( $skip_init, $skip_config ) = @{$cmd_options}{qw(skip_init skip_config)};
46  
47 0 ▶ my $config = $skip_config ? {} : $self->_init_config;
Branch: 1 branch
BranchTrueFalseTotal
$skip_config ? : 0 0 0
48  
49 0 $self->set_config($config);
50  
51 0 $self->_init_defaults($config);
52  
53 return
54 0 ▶ if $skip_init;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_init 0 0 0
55  
56 0 my $dryrun = $self->get_dryrun;
57 0 ▶ $self->set_dryrun( $dryrun ? '(dryrun)' : $EMPTY );
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
58  
59 0 ▶ log_die( $self, 'ERROR: when applying changes --no-update is not allowed' )
Branch: 1 branch
BranchTrueFalseTotal
if not $dryrun || $self->get_update and $command eq "apply" 0 0 0
Condition0%0/6
not $dryrun || $self->get_update and $command eq "apply"
!ll&&!rl&&r
000
$dryrun || $self->get_update
l!l&&r!l&&!r
000
MC/DC0%0/3
not $dryrun || $self->get_update and $command eq "apply"
$dryrun $self->get_update $command eq "apply"
Truth table0%0/4
not(A || B) and C
A= $dryrunB= $self->get_updateC= $command eq "apply"
ABCresult
1XX0
01X0
0000
0011
60 if !$dryrun && !$self->get_update && $command eq 'apply';
61  
62 0 $self->section_break;
63  
64 0 $self->log_info( '%s %s (c) Copyright 2025 TBC Development Group, LLC', ref $self, $VERSION );
65 0 $self->section_break;
66  
67 0 $self->_init_account;
68  
69 0 my $vpc_id = $config->{vpc_id};
70  
71 0 my $ec2 = $self->_init_ec2( $vpc_id, %{ $self->get_global_options } );
72  
73 0 ▶ if ( !$vpc_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vpc_id) 0 0 0
74 0 $vpc_id = $ec2->get_vpc_id;
75 0 $config->{vpc_id} = $vpc_id;
76 }
77  
78 0 $config->{subnets} = $ec2->get_subnets;
79  
80 0 $self->fetch_ecs->set_ec2($ec2);
81  
82 0 my $elb = $self->fetch_elbv2( vpc_id => $vpc_id, ec2 => $ec2 );
83  
84 # this will determine if we have an http service defined, configure
85 # the ALB if it is not set explicitly and check on required parameters
86 0 $self->_init_tasks();
87  
88 0 $self->_init_route53();
89  
90 0 ▶ $self->get_logger->trace( sub { return Dumper( [ config => $config ] ); } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
91  
92 0 $self->show_config;
93  
94 # only install die handler for apply - this makes sure we record any
95 # provisioned resources
96 0 ▶ if ( $self->command =~ /^(?:apply|destroy|delete-)$/xsmi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->command =~ /^(?:apply|destroy|delete-)$/imsx) 0 0 0
97 0 ▶ $SIG{__DIE__} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
98 0 my $msg = shift;
99  
100 0 ▶ if ($EXCEPTIONS_BEING_CAUGHT) { # eval
Branch: 1 branch
BranchTrueFalseTotal
if ($App::FargateStack::Init::EXCEPTIONS_BEING_CAUGHT) 0 0 0
101 0 warn $msg;
102 0 return;
103 }
104  
105 # if config exists...we have removed last_updated and id
106 0 ▶ if ( $config && $config->{config_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config and $config->{"config_name"}) 0 0 0
Condition0%0/3
$config and $config->{"config_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$config and $config->{"config_name"}
$config $config->{"config_name"}
Truth table0%0/3
A and B
A= $configB= $config->{"config_name"}
ABresult
0X0
100
111
107 0 warn sprintf "Unclean shutdown - writing config file to [%s]\n", $config->{config_name};
108 0 eval { YAML::DumpFile( $config->{config_name}, $config ); }
109 }
110  
111 0 die $msg;
112 0 };
113 }
114  
115 0 return $TRUE;
116 }
117  
118 ########################################################################
119 0 ▶sub _init_ec2 {
Subroutine _init_ec2: not called CC=9 SCAR=45.0
120 ########################################################################
121 0 my ($self) = @_;
122  
123 0 my $config = $self->get_config;
124  
125 0 my $subnets = $config->{subnets};
126  
127 my %options = (
128 vpc_id => $config->{vpc_id},
129 ( $self->get_cache && $subnets ) ? ( subnets => $subnets ) : (),
130 0 ▶ %{ $self->get_global_options },
Branch: 1 branch
BranchTrueFalseTotal
$self->get_cache && $subnets ? : 0 0 0
Condition0%0/3
$self->get_cache and $subnets
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_cache and $subnets
$self->get_cache $subnets
Truth table0%0/3
A and B
A= $self->get_cacheB= $subnets
ABresult
0X0
100
111
131 );
132  
133 0 ▶ $self->log_trace( sub { return Dumper( [ options => \%options ] ); } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
134  
135 0 ▶ if ( $subnets && $self->get_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subnets and $self->get_cache) { } 0 0 0
Condition0%0/3
$subnets and $self->get_cache
!ll&&!rl&&r
000
MC/DC0%0/2
$subnets and $self->get_cache
$subnets $self->get_cache
Truth table0%0/3
A and B
A= $subnetsB= $self->get_cache
ABresult
0X0
100
111
136 0 $self->log_debug( 'init-ec2: reading subnets from config...%s', $self->get_cache );
137 }
138 else {
139 0 $self->log_debug('init-ec2: configuring VPC and subnets...');
140 }
141  
142 0 my $ec2 = $self->fetch_ec2(%options);
143  
144 0 $subnets = $ec2->get_subnets;
145  
146 0 ▶ $self->log_trace( sub { return Dumper( [ subnets => $subnets ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
147  
148 0 $self->set_subnets($subnets);
149  
150 # make sure we have at least 2 subnets
151 0 foreach (qw(private public)) {
152 0 my $subnets = $subnets->{$_};
153 0 $self->log_debug( 'init-ec2: %d %s subnets detected.', scalar( @{$subnets} ), $_ );
154 0 ▶ next if $subnets && @{$subnets} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $subnets and @{$subnets;} > 1 0 0 0
Condition0%0/3
$subnets and @{$subnets;} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$subnets and @{$subnets;} > 1
$subnets @{$subnets;} > 1
Truth table0%0/3
A and B
A= $subnetsB= @{$subnets;} > 1
ABresult
0X0
100
111
155  
156 0 log_die( $self, 'ERROR: you must specify at least 2 %s subnets', $_ );
157 }
158  
159 0 $config->{vpc_id} = $ec2->get_vpc_id;
160  
161 # if we find subnets in the config...always validate in case they
162 # got changed...
163 0 ▶ if ($subnets) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subnets) { } 0 0 0
164 0 $self->log_info('init-ec2: validating subnets...');
165 0 $ec2->validate_subnets($subnets); # this will croak if any are not invalid
166 }
167 else {
168 0 my $subnets = $ec2->get_subnets;
169 0 $self->set_subnets($subnets);
170 0 $config->{subnets} = $subnets;
171 }
172  
173 0 ▶ $self->log_debug( sub { return Dumper( [ subnets => $subnets ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
174  
175 0 return $ec2;
176 }
177  
178 ########################################################################
179 0 ▶sub _init_config {
Subroutine _init_config: not called CC=5 SCAR=34.0
180 ########################################################################
181 0 my ($self) = @_;
182  
183 0 ▶ my $config_file = $self->get_config_name // $ENV{FARGATE_STACK_CONFIG} // 'fargate-stack.yml';
Condition0%0/5
($self->get_config_name // $ENV{"FARGATE_STACK_CONFIG"}) // "fargate-stack.yml"
l!l
00
$self->get_config_name // $ENV{"FARGATE_STACK_CONFIG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($self->get_config_name // $ENV{"FARGATE_STACK_CONFIG"}) // "fargate-stack.yml"
$self->get_config_name $ENV{"FARGATE_STACK_CONFIG"}
Truth table0%0/3
A // B
A= $self->get_config_nameB= $ENV{"FARGATE_STACK_CONFIG"}
ABresult
1X1
011
000
184  
185 0 ▶ croak sprintf "ERROR: %s not found or is unreadable\n", $config_file
Branch: 1 branch
BranchTrueFalseTotal
unless -s $config_file and -r $config_file 0 0 0
Condition0%0/3
-s $config_file and -r $config_file
!ll&&!rl&&r
000
MC/DC0%0/2
-s $config_file and -r $config_file
-s $config_file -r $config_file
Truth table0%0/3
A and B
A= -s $config_fileB= -r $config_file
ABresult
0X0
100
111
186 if !-s $config_file || !-r $config_file;
187  
188 0 my $config = LoadFile($config_file);
189  
190 0 $config->{config_name} = $config_file;
191  
192 0 $self->set_config($config);
193  
194 0 return $config;
195 }
196  
197 ########################################################################
198 0 ▶sub _init_tasks {
Subroutine _init_tasks: not called CC=11 SCAR=48.8
199 ########################################################################
200 0 my ($self) = @_;
201  
202 0 my $config = $self->get_config;
203  
204 0 my $tasks = $config->{tasks};
205  
206 ######################################################################
207 # check: must have at least 1 task defined
208 ######################################################################
209 0 ▶ log_die( $self, "ERROR: no tasks defined in config\n" )
Branch: 1 branch
BranchTrueFalseTotal
unless $tasks 0 0 0
210 if !$tasks;
211  
212 ######################################################################
213 # check: can only have 1 http service
214 ######################################################################
215 my ( $http_service, $error )
216 0 ▶ = grep { $tasks->{$_}->{type} && $tasks->{$_}->{type} =~ /^http/xsm } keys %{$tasks};
Condition0%0/3
$tasks->{$_}{'type'} && $tasks->{$_}{'type'} =~ /^http/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$tasks->{$_}{'type'} && $tasks->{$_}{'type'} =~ /^http/msx
$tasks->{$_}{'type'} $tasks->{$_}{'type'} =~ /^http/msx
Truth table0%0/3
A && B
A= $tasks->{$_}{'type'}B= $tasks->{$_}{'type'} =~ /^http/msx
ABresult
0X0
100
111
217  
218 0 ▶ log_die( $self, 'ERROR: only one http service is permitted' )
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
219 if $error;
220  
221 0 $self->set_http($http_service);
222  
223 ######################################################################
224 # check: if http service defined must have 2 private subnets
225 ######################################################################
226 0 ▶ if ($http_service) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_service) 0 0 0
227  
228 # check to make sure we have private subnets, we're not going to
229 # allow placing tasks in public subnets for HTTP services
230 0 ▶ if ( !$config->{subnets}->{private} || !@{ $config->{subnets}->{private} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"subnets"}{"private"} and @{$config->{"subnets"}{"private"};}) 0 0 0
Condition0%0/3
$config->{"subnets"}{"private"} and @{$config->{"subnets"}{"private"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"subnets"}{"private"} and @{$config->{"subnets"}{"private"};}
$config->{"subnets"}{"private"} @{$config->{"subnets"}{"private"};}
Truth table0%0/3
A and B
A= $config->{"subnets"}{"private"}B= @{$config->{"subnets"}{"private"};}
ABresult
0X0
100
111
231  
232 0 my $err_msg = <<'END_OF_ERROR';
233 ERROR: With a load balancer configured, tasks must run in private
234 subnets. Provide at least two private subnets in different AZs, or
235 remove the load balancer from this service.
236 END_OF_ERROR
237 0 log_die( $self, $err_msg );
238 }
239  
240 0 $self->configure_alb();
241  
242 log_die( $self, "ERROR: when provisioning an http task, domain is required\n" )
243 0 ▶ if !$config->{domain};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"domain"} 0 0 0
244 }
245  
246 ######################################################################
247 # check: must have a valid image defined for each task
248 ######################################################################
249 0 ▶ my @images = map { $tasks->{$_}->{image} // () } keys %{$tasks};
Condition0%0/3
$tasks->{$_}{"image"} // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$tasks->{$_}{"image"} // ()
$tasks->{$_}{"image"} ()
Truth table0%0/3
A // B
A= $tasks->{$_}{"image"}B= ()
ABresult
1X1
011
000
250  
251 0 ▶ if ( @images != scalar keys %{$tasks} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@images != scalar keys %{$tasks;}) 0 0 0
252 $self->log_error( 'ERROR: every task must have an image. You have %d task but only %d images',
253 0 scalar(@images), scalar keys %{$tasks} );
254 }
255  
256 0 ▶ if ( $self->get_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_cache) 0 0 0
257 0 $self->log_info( 'init-tasks: skipping images validation...%s', $self->get_cache );
258 0 return;
259 }
260  
261 0 $self->log_info('init-tasks: validating images...');
262  
263 0 my $ecr = $self->fetch_ecr();
264  
265 0 $ecr->validate_images(@images);
266  
267 0 return;
268 }
269  
270 ########################################################################
271 0 ▶sub _init_account {
Subroutine _init_account: not called CC=3 SCAR=24.8
272 ########################################################################
273 0 my ($self) = @_;
274  
275 0 my $config = $self->get_config;
276  
277 0 ▶ if ( $config->{account} && $self->get_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"account"} and $self->get_cache) 0 0 0
Condition0%0/3
$config->{"account"} and $self->get_cache
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"account"} and $self->get_cache
$config->{"account"} $self->get_cache
Truth table0%0/3
A and B
A= $config->{"account"}B= $self->get_cache
ABresult
0X0
100
111
278 0 $self->log_info( 'init-account: reading account value from config...%s', $self->get_cache );
279 0 $self->set_account( $config->{account} );
280 0 return;
281 }
282  
283 0 my $sts = $self->fetch_sts();
284  
285 0 $self->log_info('init-account: determining AWS account value...');
286  
287 0 my $result = $sts->get_caller_identity;
288 0 $sts->check_result( message => 'ERROR: could not determine account for profile:[%s]', $self->get_profile );
289  
290 0 $config->{account} = $result->{Account};
291 0 $self->log_info( 'init-account: AWS account: [%s]...', $config->{account} );
292  
293 0 $self->set_account( $config->{account} );
294  
295 0 return;
296 }
297  
298 ########################################################################
299 0 ▶sub default_region {
Subroutine default_region: not called CC=4 SCAR=30.0
Pod undocumented
300 ########################################################################
301 0 my ( $self, $region ) = @_;
302  
303 0 ▶ $region //= $self->get_region // $ENV{AWS_DEFAULT_REGION} // 'us-east-1';
Condition0%0/7
$region //= ($self->get_region // $ENV{"AWS_DEFAULT_REGION"}) // "us-east-1"
l!l
00
($self->get_region // $ENV{"AWS_DEFAULT_REGION"}) // "us-east-1"
l!l
00
$self->get_region // $ENV{"AWS_DEFAULT_REGION"}
l!l&&r!l&&!r
000
MC/DC0%0/1
$region //= ($self->get_region // $ENV{"AWS_DEFAULT_REGION"}) // "us-east-1"
$region
Truth table0%0/2
A
A= $region
Aresult
11
00
304 0 $self->set_region($region);
305  
306 0 return $region;
307 }
308  
309 ########################################################################
310 0 ▶sub _init_defaults {
Subroutine _init_defaults: not called CC=8 SCAR=42.8
311 ########################################################################
312 0 my ( $self, $config ) = @_;
313  
314 0 my $last_updated = delete $config->{last_updated};
315 0 delete $config->{id};
316  
317 0 $config->{region} = $self->default_region( $config->{region} );
318  
319 0 my $profile = $self->get_profile;
320 0 my $profile_source = 'command line';
321  
322 0 ▶ if ( !$profile && $config->{profile} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $profile and $config->{'profile'}) { } 0 0 0
elsif (not $profile and $ENV{'AWS_PROFILE'}) { } 0 0 0
Condition0%0/3
not $profile and $config->{"profile"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $profile and $config->{"profile"}
not $profile $config->{"profile"}
Truth table0%0/3
not(A) and B
A= not $profileB= $config->{"profile"}
ABresult
0X0
100
111
323 0 $profile = $config->{profile};
324 0 $profile_source = 'config';
325 }
326 ▶ elsif ( !$profile && $ENV{AWS_PROFILE} ) {
Condition0%0/3
not $profile and $ENV{"AWS_PROFILE"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $profile and $ENV{"AWS_PROFILE"}
not $profile $ENV{"AWS_PROFILE"}
Truth table0%0/3
not(A) and B
A= not $profileB= $ENV{"AWS_PROFILE"}
ABresult
0X0
100
111
327 0 $profile = $ENV{AWS_PROFILE};
328 0 $profile_source = 'environment';
329 }
330  
331 0 ▶ if ( !$profile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($profile) 0 0 0
332 0 $profile = 'default';
333 0 $profile_source = 'default';
334 }
335  
336 0 $self->set_profile($profile);
337 0 $config->{profile} = $profile;
338  
339 0 $self->set_profile_source($profile_source);
340  
341 0 my %global_options = (
342 profile => $self->get_profile,
343 region => $self->get_region,
344 logger => $self->get_logger,
345 log_level => $self->get_log_level,
346 unlink => $self->get_unlink,
347 );
348  
349 0 $self->set_global_options( \%global_options );
350  
351 0 my $cache = $self->get_cache;
352 0 ▶ $self->set_cache( $cache && $last_updated ? '(cached)' : $EMPTY );
Branch: 1 branch
BranchTrueFalseTotal
$cache && $last_updated ? : 0 0 0
Condition0%0/3
$cache and $last_updated
!ll&&!rl&&r
000
MC/DC0%0/2
$cache and $last_updated
$cache $last_updated
Truth table0%0/3
A and B
A= $cacheB= $last_updated
ABresult
0X0
100
111
353  
354 0 return;
355 }
356  
357 ########################################################################
358 0 ▶sub _init_route53 {
Subroutine _init_route53: not called CC=16 SCAR=56.1
359 ########################################################################
360 0 my ($self) = @_;
361  
362 0 my $command = $self->command;
363  
364 0 my @route53_commands = qw(apply plan list-zones delete-http-service);
365  
366 return
367 0 ▶ if none { $command eq $_ } @route53_commands;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $command eq $_; } , @route53_commands) 0 0 0
368  
369 0 my $config = $self->get_config;
370  
371 0 ▶ $self->log_trace( sub { return Dumper( [ alb => $config->{alb}, $self->get_http ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
372  
373 0 my ( $route53_config, $domain ) = @{$config}{qw(route53 domain)};
374  
375 0 ▶ if ( !$route53_config ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($route53_config) 0 0 0
376 0 $route53_config = {};
377 0 $config->{route53} = $route53_config;
378 }
379  
380 0 ▶ if ( $self->get_route53_profile ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_route53_profile) { } 0 0 0
elsif ($self->get_dns_profile) { } 0 0 0
381 0 $route53_config->{profile} = $self->get_route53_profile;
382 }
383 elsif ( $self->get_dns_profile ) {
384 0 $route53_config->{profile} = $self->get_route53_profile;
385 }
386 else {
387 0 ▶ $route53_config->{profile} //= $self->get_profile;
Condition0%0/3
$route53_config->{"profile"} //= $self->get_profile
l!l&&r!l&&!r
000
MC/DC0%0/2
$route53_config->{"profile"} //= $self->get_profile
$route53_config->{"profile"} $self->get_profile
Truth table0%0/3
A //= B
A= $route53_config->{"profile"}B= $self->get_profile
ABresult
1X1
011
000
388 }
389  
390 0 my ( $zone_id, $profile ) = @{$route53_config}{qw(zone_id profile)};
391  
392 $self->log_debug(
393 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
394 0 return Dumper(
395 [ route53_profile => $profile,
396 cli => $self->get_route53_profile
397 ]
398 );
399 }
400 0 );
401  
402 0 my $route53 = $self->fetch_route53(
403 hosted_zone_id => $zone_id,
404 elb => $self->get_elbv2,
405 profile => $profile,
406 );
407  
408 return
409 0 ▶ if !$self->get_http && $command =~ /apply|plan|list-zones/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->get_http and $command =~ /apply|plan|list-zones/msx 0 0 0
Condition0%0/3
not $self->get_http and $command =~ /apply|plan|list-zones/msx
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->get_http and $command =~ /apply|plan|list-zones/msx
not $self->get_http $command =~ /apply|plan|list-zones/msx
Truth table0%0/3
not(A) and B
A= not $self->get_httpB= $command =~ /apply|plan|list-zones/msx
ABresult
0X0
100
111
410  
411 0 my $alb_type = $config->{alb}->{type};
412  
413 0 ▶ if ( !$zone_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zone_id) 0 0 0
414 0 ▶ my $zone_type = $self->is_https ? 'public' : 'private';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_https ? : 0 0 0
415  
416 0 ▶ $self->log_warn( 'init-route53: zone_id is required when creating a task of type: [%s]',
Branch: 1 branch
BranchTrueFalseTotal
$self->is_https ? : 0 0 0
417 $self->is_https ? 'https' : 'http' );
418  
419 0 $self->log_warn( 'init-route53: ...attempting to find a [%s] hosted zone', $zone_type );
420  
421 0 my $hosted_zone = $route53->find_hosted_zone( $domain, $zone_type );
422 0 $self->benchmark('route53');
423  
424 log_die( $self, 'init-route53: ERROR: no hosted zone of type [%s] found in this account for domain: [%s]',
425 $zone_type, $domain )
426 0 ▶ if !$hosted_zone || !@{$hosted_zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $hosted_zone and @{$hosted_zone;} 0 0 0
Condition0%0/3
$hosted_zone and @{$hosted_zone;}
!ll&&!rl&&r
000
MC/DC0%0/2
$hosted_zone and @{$hosted_zone;}
$hosted_zone @{$hosted_zone;}
Truth table0%0/3
A and B
A= $hosted_zoneB= @{$hosted_zone;}
ABresult
0X0
100
111
427  
428 0 $zone_id = basename( $hosted_zone->[0]->{Id} );
429 0 $route53_config->{zone_id} = $zone_id;
430  
431 0 return;
432 }
433  
434 return
435 0 ▶ if $self->get_cache;
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_cache 0 0 0
436  
437 0 $self->log_info( 'init-route53: validating hosted zone id: [%s]...', $zone_id );
438  
439 0 my $zone = eval { return $route53->validate_hosted_zone( zone_id => $zone_id, domain => $domain, alb_type => $alb_type, ); };
440  
441 0 my $err = $EVAL_ERROR;
442  
443 0 ▶ if ( $zone && !$err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone and not $err) 0 0 0
Condition0%0/3
$zone and not $err
!ll&&!rl&&r
000
MC/DC0%0/2
$zone and not $err
$zone not $err
Truth table0%0/3
A and not(B)
A= $zoneB= not $err
ABresult
0X0
100
111
444 0 $self->log_info( 'init-route53: hosted zone id: [%s/%s]', $zone->{Id}, $zone->{Name} );
445 0 return;
446 }
447  
448 # output a helpful table of hosted zones for this domain
449 0 $self->log_warn( "\n" . $self->display_hosted_zones($domain) );
450  
451 0 ($err) = split /\n/, $err;
452  
453 0 log_die( $self, $err );
454  
455 0 return;
456 }
457  
458 1 1;
« Events.pm ↑ Summary FargateStack/Builder/LogGroup.pm »