| 1 | package App::FargateStack::Builder::SecurityGroup; | ||||||||||||||||||||||||||||
| 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::Events; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use App::FargateStack::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use App::FargateStack::Builder::Utils qw(log_die dmp); | ||||||||||||||||||||||||||
|
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_security_group { | ||||||||||||||||||||||||||
|
Subroutine
build_security_group: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||
| 19 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | my ( $config, $security_groups, $dryrun ) = $self->common_args(qw(config security_groups dryrun)); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $ec2 = $self->get_ec2; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $security_groups //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$security_groups //= {}
MC/DC0%0/1
$security_groups //= {}
$security_groups
Truth table0%0/2
A
A= $security_groups
| |||||||||||||||||||||||||||||
| 26 | 0 | $config->{security_groups} = $security_groups; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $default_security_group_name = $self->create_default('security-group'); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $security_group_name = $security_groups->{fargate}->{group_name} // $default_security_group_name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$security_groups->{"fargate"}{"group_name"} // $default_security_group_name
MC/DC0%0/2
$security_groups->{"fargate"}{"group_name"} // $default_security_group_name
$security_groups->{"fargate"}{"group_name"}
$default_security_group_name
Truth table0%0/3
A // B
A= $security_groups->{"fargate"}{"group_name"}B= $default_security_group_name
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $security_group_id = $security_groups->{fargate}->{group_id}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | $security_groups->{fargate}->{group_name} = $security_group_name; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | $self->log_trace( | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 0 | return Dumper( | |||||||||||||||||||||||||||
| 39 | [ security_group_name => $security_group_name, | ||||||||||||||||||||||||||||
| 40 | security_group_id => $security_group_id | ||||||||||||||||||||||||||||
| 41 | ] | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( !$self->get_cache || !$security_group_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->get_cache and $security_group_id
MC/DC0%0/2
$self->get_cache and $security_group_id
$self->get_cache
$security_group_id
Truth table0%0/3
A and B
A= $self->get_cacheB= $security_group_id
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($security_group) = $ec2->describe_security_group($security_group_name); | |||||||||||||||||||||||||||
| 48 | 0 | $ec2->check_result( message => 'ERROR: could not describe security group: [%s]', $security_group_name ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $self->log_debug( Dumper( [ 'security-group:' => $security_group ] ) ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( !$security_group ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->log_warn( 'security-group: [%s] will be created...%s', $security_group_name, $dryrun ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->inc_required_resources( security_groups => [$security_group_name] ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | my $description = sprintf 'Security group for %s Fargate tasks', $config->{app}->{name}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $security_group_id = $ec2->create_security_group( $security_group_name, $description ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | log_die( $self, "ERROR: could not create security group:%s\n%s", $security_group_name, $ec2->get_error ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | if !$security_group_id; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $security_groups->{fargate}->{group_id} = $security_group_id; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # authorize ingress when/if we have an ALB | ||||||||||||||||||||||||||||
| 68 | 0 | $self->log_info( 'security-group: [%s] id: [%s] created', $security_group_name, $security_group_id ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||
| 74 | 0 | $security_groups->{fargate}->{group_id} = $security_group->{GroupId}; | |||||||||||||||||||||||||||
| 75 | 0 | $security_group_id = $security_group->{GroupId}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $self->log_info( 'security-group: [%s] exists...%s', $security_group_name, $self->get_cache || 'skipping' ); | ||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||
| 80 | 0 | $self->inc_existing_resources( security_groups => [$security_group_id] ); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | 1; | |||||||||||||||||||||||||||