| 1 | package App::FargateStack::Builder::Events; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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::Builder::Utils qw(log_die); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::FargateStack::Constants; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Compare; | ||||||||||||||||||||||||||||||||||||||||||||
|
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 JSON; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub build_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_events: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ( $config, $dryrun, $cluster, $tasks ) = $self->common_args(qw(config dryrun cluster tasks)); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my @events = grep { $tasks->{$_}->{type} eq 'task' && $tasks->{$_}->{schedule} } keys %{$tasks}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$tasks->{$_}{'type'} eq 'task' && $tasks->{$_}{'schedule'}
MC/DC0%0/2
$tasks->{$_}{'type'} eq 'task' && $tasks->{$_}{'schedule'}
$tasks->{$_}{'type'} eq 'task'
$tasks->{$_}{'schedule'}
Truth table0%0/3
A && B
A= $tasks->{$_}{'type'} eq 'task'B= $tasks->{$_}{'schedule'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ( !@events ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $self->log_info('events: no events to build'); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->log_info( 'events: [%d] event(s) to build', scalar @events ); | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->log_info('events: constructing IAM role for events...'); | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->build_events_iam_role(@events); # task names | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | foreach my $task_name (@events) { | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->log_info( 'events: building event for: [%s]', $task_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $task = $tasks->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # ok to be undef, as App::Events will provide default | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $event_bus_name = $task->{event_bus_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $event = $self->fetch_events; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $schedule = $task->{schedule}; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( !$schedule ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->log_warn( 'events: no schedule for task: [%s]...skipping', $task_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $self->log_info( 'events: found a schedule...validating schedule: [%s]', $schedule ); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $valid_schedule = $event->validate_schedule($schedule); | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | croak sprintf "ERROR: invalid schedule expression: %s\nSee: %s", $schedule, $EVENT_SCHEDULER_TYPE_URL | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | if !$valid_schedule; | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $rule_name = sprintf '%s-schedule', $task_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( $valid_schedule ne $schedule ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->log_warn( sprintf 'events: [%s] schedule modified [%s] automatically for you...', $schedule, $valid_schedule ); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $task->{schedule} = $valid_schedule; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $schedule = $valid_schedule; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $self->log_info( 'events: checking if rule [%s] exists or schedule [%s] changed', $rule_name, $schedule ); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $exists = $event->rule_exists( $rule_name, $schedule ); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $rule_exists = $exists ? q{} : 'does not '; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $schedule_changed = $exists == -1 ? q {} : 'not '; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $level = $rule_exists ? 'warn' : 'info'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $level = $schedule_changed ? 'info' : 'error'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $level = "log_$level"; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->$level( 'events: rule [%s] %sexists and schedule [%s] has %schanged', | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | $rule_name, $rule_exists, $schedule, $schedule_changed ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $exists == -1 || $self->taskdef_has_changed($task_name) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$exists == -1 or $self->taskdef_has_changed($task_name)
MC/DC0%0/2
$exists == -1 or $self->taskdef_has_changed($task_name)
$exists == -1
$self->taskdef_has_changed($task_name)
Truth table0%0/3
A or B
A= $exists == -1B= $self->taskdef_has_changed($task_name)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->log_error( 'events: attempting to delete rule in case target does not exist [%s]...%s', $rule_name, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $result = $event->delete_rule($rule_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $event->check_result( | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | message => 'could not delete rule: [%s]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | params => [$rule_name], | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | regexp => qr/has\stargets/xmsi | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $action = !$exists ? 'created' : 'replaced'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( !$exists || ( $exists == -1 || $self->taskdef_has_changed($task_name) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $exists or ($exists == -1 or $self->taskdef_has_changed($task_name))
$exists == -1 or $self->taskdef_has_changed($task_name)
MC/DC0%0/3
not $exists or ($exists == -1 or $self->taskdef_has_changed($task_name))
not $exists
$exists == -1
$self->taskdef_has_changed($task_name)
Truth table0%0/4
not(A) or B or C
A= not $existsB= $exists == -1C= $self->taskdef_has_changed($task_name)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->inc_required_resources( 'events:rule' => [$rule_name] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->get_logger->warn( sprintf 'events: [%s] rule will be %s...%s', $rule_name, $action, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->log_warn( sprintf 'events: [%s] rule will be %s...%s', $rule_name, $action, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $event->put_rule( rule_name => $rule_name, schedule => $schedule, state => $TRUE ); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $event->check_result( message => 'ERROR: could not create rule [%s]', $rule_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->get_logger->warn( sprintf 'events: [%s] rule %s successfully', $rule_name, $action ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->get_logger->info( sprintf 'events: rule [%s] exists...skipping', $rule_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->inc_existing_resources( 'events:rule' => $rule_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->create_event_target($task_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub create_event_target { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_event_target: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ( $config, $dryrun, $tasks ) = $self->common_args(qw(config dryrun tasks)); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $region = $self->get_region; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $account = $self->get_account; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $task = $tasks->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $events_role = $config->{events_role}; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $task_definition_arn = $task->{arn} // $EMPTY; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"arn"} // $App::FargateStack::Builder::Events::EMPTY
MC/DC0%0/2
$task->{"arn"} // $App::FargateStack::Builder::Events::EMPTY
$task->{"arn"}
$App::FargateStack::Builder::Events::EMPTY
Truth table0%0/3
A // B
A= $task->{"arn"}B= $App::FargateStack::Builder::Events::EMPTY
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my @subnets = sort @{ $self->get_subnets->{private} // $self->get_subnets->{public} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->get_subnets->{"private"} // $self->get_subnets->{"public"}
MC/DC0%0/2
$self->get_subnets->{"private"} // $self->get_subnets->{"public"}
$self->get_subnets->{"private"}
$self->get_subnets->{"public"}
Truth table0%0/3
A // B
A= $self->get_subnets->{"private"}B= $self->get_subnets->{"public"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $security_group = $config->{security_groups}->{fargate}->{group_id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $tags = $self->build_run_tags( $task_name => $task ); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | my $target = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { Id => $self->create_default( 'rule-id', $task_name ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | Arn => $config->{cluster}->{arn}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | RoleArn => $events_role->{arn}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | EcsParameters => { | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | Tags => $tags, | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | TaskDefinitionArn => $task_definition_arn, | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | TaskCount => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | LaunchType => 'FARGATE', | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | Group => 'schedule:' . $task_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | EnableECSManagedTags => JSON::true, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | EnableExecuteCommand => JSON::false, | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | PropagateTags => 'TASK_DEFINITION', | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | NetworkConfiguration => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | awsvpcConfiguration => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | Subnets => [ $subnets[0] ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | SecurityGroups => [$security_group], | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | AssignPublicIp => 'DISABLED' | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $rule_name = $self->create_default( 'rule-name', $task_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $event = $self->fetch_events; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $current_target = $event->target_exists($rule_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $replace_target = $current_target ? $TRUE : $FALSE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # compare $target vs $current_target | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ( $current_target && !Compare( $target->[0], $current_target ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$current_target and not Compare($target->[0], $current_target)
MC/DC0%0/2
$current_target and not Compare($target->[0], $current_target)
$current_target
not Compare($target->[0], $current_target)
Truth table0%0/3
A and not(B)
A= $current_targetB= not Compare($target->[0], $current_target)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->display_diffs( $current_target, $target->[0], { style => 'Table', title => 'rule target differs' } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $replace_target = $TRUE; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | $self->log_trace( | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return Dumper( | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | [ current_target => $current_target, | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | target => $target, | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | task_definition_arn => $task_definition_arn, | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | replace_target => $replace_target, | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my $ecs_parameters = $current_target->{EcsParameters} // {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$current_target->{"EcsParameters"} // {}
MC/DC0%0/1
$current_target->{"EcsParameters"} // {}
$current_target->{"EcsParameters"}
Truth table0%0/2
A
A= $current_target->{"EcsParameters"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | my $current_task_definition_arn = $ecs_parameters->{TaskDefinitionArn} // $EMPTY; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ecs_parameters->{"TaskDefinitionArn"} // $App::FargateStack::Builder::Events::EMPTY
MC/DC0%0/2
$ecs_parameters->{"TaskDefinitionArn"} // $App::FargateStack::Builder::Events::EMPTY
$ecs_parameters->{"TaskDefinitionArn"}
$App::FargateStack::Builder::Events::EMPTY
Truth table0%0/3
A // B
A= $ecs_parameters->{"TaskDefinitionArn"}B= $App::FargateStack::Builder::Events::EMPTY
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ( !$replace_target && $current_task_definition_arn && $current_task_definition_arn eq $task_definition_arn ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
not $replace_target and $current_task_definition_arn and $current_task_definition_arn eq $task_definition_arn
not $replace_target and $current_task_definition_arn
MC/DC0%0/3
not $replace_target and $current_task_definition_arn and $current_task_definition_arn eq $task_definition_arn
not $replace_target
$current_task_definition_arn
$current_task_definition_arn eq $task_definition_arn
Truth table0%0/4
not(A) and B and C
A= not $replace_targetB= $current_task_definition_arnC= $current_task_definition_arn eq $task_definition_arn
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->log_info( sprintf 'events: [%s] target exists...skipping', $task_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->inc_existing_resources( 'events:target' => [$task_name] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ▶ | elsif ( $current_task_definition_arn && $current_task_definition_arn eq $task_definition_arn ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$current_task_definition_arn and $current_task_definition_arn eq $task_definition_arn
MC/DC0%0/2
$current_task_definition_arn and $current_task_definition_arn eq $task_definition_arn
$current_task_definition_arn
$current_task_definition_arn eq $task_definition_arn
Truth table0%0/3
A and B
A= $current_task_definition_arnB= $current_task_definition_arn eq $task_definition_arn
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $replace_target = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->log_warn( sprintf 'events: [%s] task ARNs differ [%s] <=> [%s]', | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | $task_name, $current_task_definition_arn, $task_definition_arn ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my $action = $current_target ? 'replaced' : 'created'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $self->log_warn( sprintf 'events: target [%s] will be %s...%s', $task_name, $action, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->inc_required_resources( 'events:target' => [$task_name] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($current_target) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->log_warn( 'events: deleting target for rule [%s]...', $rule_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $event->remove_targets( $rule_name, $self->create_default( 'rule-id', $task_name ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $self->log_warn( 'events: creating target for rule [%s]...', $rule_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $result = $event->put_targets( $rule_name, $target ); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $event->check_result( | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | message => 'ERROR: could not create target [%s] for rule [%s]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | params => [ to_json( $target, { pretty => $TRUE } ), $rule_name ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub build_events_iam_role { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_events_iam_role: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ( $config, $dryrun ) = $self->common_args(qw(config dryrun)); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $iam = $self->fetch_iam; | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $role_config = $config->{events_role} // {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"events_role"} // {}
MC/DC0%0/1
$config->{"events_role"} // {}
$config->{"events_role"}
Truth table0%0/2
A
A= $config->{"events_role"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my ( $role_name, $role_arn ) = $self->create_events_role(); | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $policy_name = $self->create_default( 'policy-name', 'events' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | @{$role_config}{qw(name arn policy_name)} = ( $role_name, $role_arn, $policy_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $policy = $iam->get_role_policy( $role_name, $policy_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my @statement = $self->add_events_policy(); | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $role_policy = { | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | Version => $IAM_POLICY_VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | Statement => \@statement, | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ( $policy && Compare( $policy, $role_policy ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$policy and Compare($policy, $role_policy)
MC/DC0%0/2
$policy and Compare($policy, $role_policy)
$policy
Compare($policy, $role_policy)
Truth table0%0/3
A and B
A= $policyB= Compare($policy, $role_policy)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $self->log_info( 'iam:role-policy: policy [%s] for [%s] exists...%s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_cache || 'skipping'
MC/DC0%0/1
$self->get_cache || 'skipping'
$self->get_cache
Truth table0%0/2
A
A= $self->get_cache
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $policy_name, $role_name, $self->get_cache || 'skipping' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $self->inc_existing_resources( 'iam:role-policy' => [$policy_name] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ($policy) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $self->display_diffs( $policy, $role_policy, { title => 'event policy has changed' } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | $self->log_warn( | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | 'iam:role-policy: policy [%s] will be %s for [%s]...%s', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | $policy_name, ( $policy ? 'updated' : 'created' ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $role_name, $dryrun | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->inc_required_resources( 'iam:policy' => [$policy_name] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $iam->put_role_policy( $role_name, $policy_name, $role_policy ); | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $iam->check_result( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | message => 'ERROR: could not %s policy [%s] for [%s]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | params => [ ( $policy ? 'update' : 'create' ), $policy_name, $role_name ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | $self->log_warn( 'iam:role-policy: policy [%s] %s successfully for [%s]...', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $policy_name, ( $policy ? 'updated' : 'created' ), $role_name ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | sub update_rule_state { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_rule_state: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ( $self, $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my ( $config, $tasks, $dryrun ) = $self->common_args(qw(config tasks dryrun)); | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my ($task_name) = $self->get_args; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ( !$task_name ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ( $task_name, $err ) = grep { defined $tasks->{$_}->{schedule} } keys %{$tasks}; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | croak sprintf "%s %s-scheduled-task task-name\n", $ENV{SCRIPT_NAME}, $state ? 'enable' : 'disable' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not $task_name or $err
MC/DC0%0/2
not $task_name or $err
not $task_name
$err
Truth table0%0/3
not(A) or B
A= not $task_nameB= $err
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | if !$task_name || $err; | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $rule_name = sprintf '%s-schedule', $task_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | require App::Events; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $event = App::Events->new( $self->get_global_options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $result = $event->describe_rule( $rule_name, '{state: State, schedule: ScheduleExpression}' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | log_die( $self, "could not describe rule: [%s]\n%s", $rule_name, $event->get_error ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | if !$result; | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $self->log_warn( 'events: current state: [%s] for rule [%s]...will be updated do [%s]...%s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | $result->{state}, $rule_name, ( $state ? 'ENABLED' : 'DISABLED' ), $dryrun ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if $dryrun; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $result = $state ? $event->enable_rule($rule_name) : $event->disable_rule($rule_name); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | log_die( $self, "could not update rule: [%s]\n%s", $rule_name, $event->get_error ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $result and $event->get_error
MC/DC0%0/2
not $result and $event->get_error
not $result
$event->get_error
Truth table0%0/3
not(A) and B
A= not $resultB= $event->get_error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | if !$result && $event->get_error; | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub create_events_role { return shift->create_role( @_, 'events' ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_events_role: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub add_events_policy { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_events_policy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my @events = $self->has_events; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $region = $self->get_region; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $account = $self->get_account; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $cluster_name = $self->get_config->{cluster}->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $role_arn = $self->get_config->{role}->{arn}; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | my @policy_statement = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | { Effect => 'Allow', | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | Action => 'ecs:RunTask', | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | Resource => [ map { sprintf $TASK_DEFINITION_ARN_TEMPLATE, $region, $account, $_ } @events ], | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | Condition => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ArnLike => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 'ecs:cluster' => sprintf $CLUSTER_ARN_TEMPLATE, | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | $region, $account, $cluster_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | { Effect => 'Allow', | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | Action => 'iam:PassRole', | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Resource => [$role_arn], | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | { 'Sid' => 'TagLaunchedTasks', | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 'Effect' => 'Allow', | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 'Action' => 'ecs:TagResource', | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 'Resource' => sprintf 'arn:aws:ecs:%s:%s:task/%s/*', | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | $region, $account, $cluster_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return @policy_statement; | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub has_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_events: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my ( $config, $tasks ) = $self->common_args(qw(config tasks)); | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my ($schedule) = grep { $tasks->{$_}->{schedule} } keys %{$tasks}; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return $schedule; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub fetch_events { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_events: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | require App::Events; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my $events = $self->get_events; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | return $events | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | if $events; | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $events = App::Events->new( $self->get_global_options ); | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $self->set_events($events); | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | return $events; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub build_run_tags { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_run_tags: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my ( $self, $task_name, $task ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | my %tags = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | %{ $task->{tags} // {} }, # user-specified tags | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$task->{"tags"} // {}
MC/DC0%0/1
$task->{"tags"} // {}
$task->{"tags"}
Truth table0%0/2
A
A= $task->{"tags"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 'App::FargateStack:Schedule' => $task_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 'App::FargateStack:Type' => 'cron', | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my @tags = map { ( { Key => $_, Value => $tags{$_} } ) } sort keys %tags; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | return \@tags; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||