FargateStack/Builder/LogGroup.pm

filter: Statementstmt 31.8% 22 / 69 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 2 totaltotal 23.9% 29 / 121 CC 15 SCAR 43.9
CC
15
Cov
22%
build_log_group
156.0
add_log_group_policy
12.0
__ANON__
6.0
CRAP 80.3
« FargateStack/Init.pm ↑ Summary FargateStack/Builder/EFS.pm »
1 package App::FargateStack::Builder::LogGroup;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use App::FargateStack::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 ########################################################################
15 0 ▶sub build_log_group {
Subroutine build_log_group: not called CC=12 SCAR=50.5
Pod undocumented
16 ########################################################################
17 0 my ($self) = @_;
18  
19 0 my ( $config, $tasks, $dryrun ) = $self->common_args(qw(config tasks dryrun));
20  
21 0 ▶ $config->{log_group} //= {};
Condition0%0/2
$config->{"log_group"} //= {}
l!l
00
MC/DC0%0/1
$config->{"log_group"} //= {}
$config->{"log_group"}
Truth table0%0/2
A
A= $config->{"log_group"}
Aresult
11
00
22 0 ▶ $config->{log_group}->{name} //= $self->create_default('log-group');
Condition0%0/3
$config->{"log_group"}{"name"} //= $self->create_default("log-group")
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"log_group"}{"name"} //= $self->create_default("log-group")
$config->{"log_group"}{"name"} $self->create_default("log-group")
Truth table0%0/3
A //= B
A= $config->{"log_group"}{"name"}B= $self->create_default("log-group")
ABresult
1X1
011
000
23  
24 0 my $logs = $self->fetch_logs;
25  
26 0 my $log_group = $logs->log_group_exists( $config->{log_group}->{name} );
27  
28 0 ▶ if ($log_group) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log_group) 0 0 0
29 0 my ( $arn, $name, $retention_days ) = @{$log_group}{qw(logGroupArn logGroupName retentionInDays)};
30  
31 0 $config->{log_group}->{name} = $name; # just in case
32 0 $config->{log_group}->{arn} = $arn;
33  
34 0 $self->log_info( 'logs: [%s] exists...%s', $name, 'skipping' );
35  
36 0 $self->inc_existing_resources( log_group => $arn );
37  
38 0 ▶ if ( exists $config->{log_group}->{retention_days} && $config->{log_group}->{retention_days} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{'log_group'}{'retention_days'} and $config->{'log_group'}{'retention_days'}) { } 0 0 0
Condition0%0/3
exists $config->{"log_group"}{"retention_days"} and $config->{"log_group"}{"retention_days"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $config->{"log_group"}{"retention_days"} and $config->{"log_group"}{"retention_days"}
exists $config->{"log_group"}{"retention_days"} $config->{"log_group"}{"retention_days"}
Truth table0%0/3
A and B
A= exists $config->{"log_group"}{"retention_days"}B= $config->{"log_group"}{"retention_days"}
ABresult
0X0
100
111
39 0 ▶ if ( $retention_days != $config->{log_group}->{retention_days} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retention_days != $config->{"log_group"}{"retention_days"}) 0 0 0
40 0 $self->log_warn( 'logs: [%s] retention policy has changed...will be updated...%s', $name, $dryrun );
41 0 $self->inc_required_resources( logs => sprintf 'update retention days to %s', $config->{log_group}->{retention_days} );
42 0 ▶ if ( !$dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dryrun) 0 0 0
43 0 $logs->put_retention_policy( $name, $config->{log_group}->{retention_days} );
44 }
45 }
46 }
47 else {
48 0 $self->log_error('logs: missing log retention policy. Logs will be stored indefinitely!');
49  
50 0 ▶ if ($retention_days) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retention_days) 0 0 0
51 0 $self->log_error( 'logs: retention policy for [%s] will be deleted...%s', $name, $dryrun );
52 0 $self->inc_required_resources( logs => sprintf 'delete retention policy' );
53 0 ▶ if ( !$dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dryrun) 0 0 0
54 0 $logs->delete_retention_policy($name);
55 }
56 }
57 }
58  
59 0 return;
60 }
61  
62 0 my $log_group_name = $config->{log_group}->{name};
63  
64 0 $self->log_warn( 'logs: [%s] will be created...%s', $log_group_name, $dryrun );
65  
66 $self->inc_required_resources(
67 0 ▶ log_group => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
68 0 my ($dryrun) = @_;
69 0 ▶ return $dryrun ? 'arn:???:' . $log_group_name : $config->{log_group}->{arn};
Branch: 1 branch
BranchTrueFalseTotal
$dryrun ? : 0 0 0
70 }
71 0 );
72  
73 return
74 0 ▶ if $dryrun;
Branch: 1 branch
BranchTrueFalseTotal
if $dryrun 0 0 0
75  
76 0 $self->log_warn( 'logs: creating [%s]...', $log_group_name );
77  
78 0 my $result = $logs->create_log_group($log_group_name);
79 0 $logs->check_result( message => 'ERROR: could not create group: [%s]', $log_group_name );
80  
81 0 $config->{log_group}->{arn} = $result->{logGroupArn};
82 0 $config->{log_group}->{name} = ( split /:/xsm, $result->{logGroupArn} )[-1];
83  
84 0 ▶ my $retention_days = $config->{log_group}->{retention_days} //= $DEFAULT_LOG_RETENTION_DAYS;
Condition0%0/3
$config->{"log_group"}{"retention_days"} //= $App::FargateStack::Builder::LogGroup::DEFAULT_LOG_RETENTION_DAYS
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"log_group"}{"retention_days"} //= $App::FargateStack::Builder::LogGroup::DEFAULT_LOG_RETENTION_DAYS
$config->{"log_group"}{"retention_days"} $App::FargateStack::Builder::LogGroup::DEFAULT_LOG_RETENTION_DAYS
Truth table0%0/3
A //= B
A= $config->{"log_group"}{"retention_days"}B= $App::FargateStack::Builder::LogGroup::DEFAULT_LOG_RETENTION_DAYS
ABresult
1X1
011
000
85 0 $config->{log_group}->{retention_days} = $retention_days;
86  
87 0 $self->log_warn( 'logs: setting log retention days to [%s] for [%s]', $retention_days, $log_group_name );
88 0 $logs->put_retention_policy( $log_group_name, $retention_days );
89  
90 0 $logs->check_result( message => 'ERROR: could not set retention policy for: [%s]', $log_group_name );
91  
92 0 return $TRUE;
93 }
94  
95 ########################################################################
96 0 ▶sub add_log_group_policy {
Subroutine add_log_group_policy: not called CC=3 SCAR=24.8
Pod undocumented
97 ########################################################################
98 0 my ($self) = @_;
99  
100 0 ▶ my $log_group = $self->get_config->{log_group} // {};
Condition0%0/2
$self->get_config->{"log_group"} // {}
l!l
00
MC/DC0%0/1
$self->get_config->{"log_group"} // {}
$self->get_config->{"log_group"}
Truth table0%0/2
A
A= $self->get_config->{"log_group"}
Aresult
11
00
101  
102 0 ▶ my $arn = $log_group->{arn} // q{};
Condition0%0/2
$log_group->{"arn"} // ""
l!l
00
MC/DC0%0/1
$log_group->{"arn"} // ""
$log_group->{"arn"}
Truth table0%0/2
A
A= $log_group->{"arn"}
Aresult
11
00
103  
104 return {
105 0 Effect => 'Allow',
106 Action => [qw(logs:CreateLogStream logs:PutLogEvents logs:CreateLogGroup)],
107 Resource => [ $arn, $arn . ':log-stream:*' ],
108 };
109 }
110  
111 1 1;
« FargateStack/Init.pm ↑ Summary FargateStack/Builder/EFS.pm »