| 1 | package App::FargateStack::CreateStack; | ||||||||||||||||||||||||||||||||||||||||||
| 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 dmp); | ||||||||||||||||||||||||||||||||||||||||
|
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 CLI::Simple::Constants qw(:booleans :chars); | ||||||||||||||||||||||||||||||||||||||||
|
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 YAML qw(Dump DumpFile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub cmd_create_stack { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_create_stack: not called CC=27 SCAR=66.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ( $app_name, @args ) = $self->get_args; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( lc $app_name !~ /\A[[:lower:]\d_-]+\z/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ( $app_name =~ /^(?:daemon|https?|scheduled|task):(.*?)$/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | unshift @args, $app_name; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $app_name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | carp sprintf "WARNING: no app name provided...using the task name: [%s]\n", $app_name; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | croak sprintf "ERROR: app names should only have a-z_-0-9 characters\n"; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $config_name = $self->get_config_name // "$app_name.yml"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_config_name // "$app_name.yml"
MC/DC0%0/1
$self->get_config_name // "$app_name.yml"
$self->get_config_name
Truth table0%0/2
A
A= $self->get_config_name
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->set_config_name($config_name); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $sts = $self->fetch_sts; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $account = $sts->get_caller_identity('Account'); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $sts->check_result( message => 'ERROR: could not determine account for profile: [%s]', $self->get_profile ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $config = { | |||||||||||||||||||||||||||||||||||||||||
| 44 | account => $account, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | profile => $self->get_profile, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | region => $self->get_region, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | app => { name => $app_name }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my %tasks; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | while ( my $tag = shift @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $tag =~ /^(daemon|task|scheduled|https?):/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $tasks{$tag} = []; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | while ( my $next_tag = shift @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $next_tag =~ /^(?:daemon|task|scheduled|https?):/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | unshift @args, $next_tag; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | push @{ $tasks{$tag} }, $next_tag; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | elsif ( !keys %tasks ) { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | croak "ERROR: start your task definition with daemon|task|scheduled|http|https\n"; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | foreach my $t ( keys %tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ( $type, $name ) = split /[:]/xsm, $t; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->log_info( 'create-stack: configuring: %s %s', $type, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my @options = @{ $tasks{$t} }; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $task = { type => $type eq 'scheduled' ? 'task' : $type }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $config->{tasks}->{$name} = $task; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ($image) = grep {/^image:/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | croak sprintf "ERROR: task [%s] does not have an image...every task must have an image\n", $name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | if !$image; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($image_name) = $image =~ /^image:(.*)$/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # If the user omitted a tag, you can optionally default to :latest | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # $image_name .= ':latest' if $image_name !~ /:[^\/]+$/; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ( $repo, $tag ) = split /:/xsm, $image_name, 2; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $tag //= 'latest'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tag //= "latest"
MC/DC0%0/1
$tag //= "latest"
$tag
Truth table0%0/2
A
A= $tag
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ( $image_name !~ m{/}xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | # ECR shorthand (repo[:tag]) in current account | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $ecr = $self->fetch_ecr; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $images = $ecr->describe_images( $repo, 'imageDetails' ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( !$images || !@{$images} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$images && @{$images;}
MC/DC0%0/2
$images && @{$images;}
$images
@{$images;}
Truth table0%0/3
A && B
A= $imagesB= @{$images;}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->log_warn( 'create-stack: %s not found in ECR...assuming public image', $image ); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $task->{image} = "$image_name:$tag"; # leave as-is; ECS will try public registries | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $uri = sprintf '%s.dkr.ecr.%s.amazonaws.com/%s:%s', $account, $self->get_region, $image_name, $tag; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $task->{image} = $uri; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # Fully-qualified external or cross-account reference; accept as-is | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $task->{image} = "$repo:$tag"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($schedule) = grep {/^schedule:/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $t =~ /^scheduled:/xsm || ( $t =~ /task:/sxm && $schedule ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$t =~ /^scheduled:/msx or $t =~ /task:/msx and $schedule
$t =~ /task:/msx and $schedule
MC/DC0%0/3
$t =~ /^scheduled:/msx or $t =~ /task:/msx and $schedule
$t =~ /^scheduled:/msx
$t =~ /task:/msx
$schedule
Truth table0%0/4
A or B and C
A= $t =~ /^scheduled:/msxB= $t =~ /task:/msxC= $schedule
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | croak "ERROR: scheduled tasks must have a schedule\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | if !$schedule; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $task->{schedule} = ( split /[:]/xsm, $schedule )[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $t =~ /^(https?):/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ($domain) = grep {/^domain:/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | croak "ERROR: HTTP and HTTPS services must have a domain\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | if !$domain; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $config->{domain} = ( split /[:]/xsm, $domain )[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # Environment | ||||||||||||||||||||||||||||||||||||||||||
| 133 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my @environment = grep {/^env(?:ironment)?:/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->parse_environment_option( | |||||||||||||||||||||||||||||||||||||||||
| 138 | config => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | tag => \@environment | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # WAF | ||||||||||||||||||||||||||||||||||||||||||
| 144 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($waf) = grep {/^waf:.*$/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($waf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | croak "ERROR: waf option is only available for https services:\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | if $t !~ /^https:/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->parse_waf_option( | |||||||||||||||||||||||||||||||||||||||||
| 152 | task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | config => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | tag => $waf | ||||||||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # Autoscaling | ||||||||||||||||||||||||||||||||||||||||||
| 160 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my ($autoscaling) = grep {/autoscaling:.*$/xsm} @options; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ($autoscaling) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | croak "ERROR: autoscaling option is only available for http and daemon services:\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | if $t !~ /^(?:https?|daemon):/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->parse_autoscaling_option( | |||||||||||||||||||||||||||||||||||||||||
| 168 | task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | config => $config, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | tag => $autoscaling | ||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->fetch_option_defaults; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | print {*STDOUT} Dump($config); | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ( $self->get_update ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | DumpFile( $config_name, $config ); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub parse_environment_option { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_environment_option: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my ( $task, $environment ) = @args{qw(task tag)}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | foreach ( @{$environment} ) { | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my ( $key, $value ) = split /\s*=\s*/xsm, ( split /:/xsm )[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $task->{environment} = { $key => $value }; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub parse_autoscaling_option { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_autoscaling_option: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ( $config, $task, $autoscaling ) = @args{qw(config task tag)}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | my $autoscaling_config = $task->{autoscaling} = { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | min_capacity => $DEFAULT_AUTOSCALING_MIN_CAPACITY, | |||||||||||||||||||||||||||||||||||||||||
| 211 | max_capacity => $DEFAULT_AUTOSCALING_MAX_CAPACITY, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | scale_out_cooldown => $DEFAULT_AUTOSCALING_SCALE_OUT_COOLDOWN, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | scale_in_cooldown => $DEFAULT_AUTOSCALING_SCALE_IN_COOLDOWN, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ($metric) = $autoscaling =~ /:([^=]+)/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | croak "ERROR: requests can only be used with http services\n" | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if $metric eq 'requests' && $task->{type} !~ /^http/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$metric eq "requests" and not $task->{"type"} =~ /^http/msx
MC/DC0%0/2
$metric eq "requests" and not $task->{"type"} =~ /^http/msx
$metric eq "requests"
not $task->{"type"} =~ /^http/msx
Truth table0%0/3
A and not(B)
A= $metric eq "requests"B= not $task->{"type"} =~ /^http/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | croak "ERROR: metric must be cpu or requests\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | if $metric !~ /^cpu|requests/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my ($metric_value) = $autoscaling =~ /=(.*)$/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( !$metric_value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $metric_value = $metric eq 'cpu' ? $DEFAULT_CPU_SCALING_LEVEL : $DEFAULT_REQUESTS_SCALING_LEVEL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # TBD: check for sane values | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $autoscaling_config->{$metric} = $metric_value; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub parse_waf_option { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_waf_option: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my ( $config, $task, $waf ) = @args{qw(config task tag)}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $config->{alb}->{waf} = { enabled => 'true' }; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($rule_list) = reverse split /:/xsm, $waf; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my @rules; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ( $rule_list =~ /^(?:enabled|true|default)$/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | push @rules, 'default'; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | @rules = split /,/xsm, $rule_list; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if (@rules) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $config->{alb}->{waf}->{managed_rules} = \@rules; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub resolve_image_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_image_name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my ( $self, $image_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | return $image_name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | if $image_name =~ m{/}xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # ECR shorthand (repo[:tag]) in current account | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ( $repo, $tag ) = split /:/xsm, $image_name, 2; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $tag //= 'latest'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tag //= "latest"
MC/DC0%0/1
$tag //= "latest"
$tag
Truth table0%0/2
A
A= $tag
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $ecr = $self->fetch_ecr; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $images = $ecr->describe_images( $repo, 'imageDetails' ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | return $image_name | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if !$images || !@{$images}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$images and @{$images;}
MC/DC0%0/2
$images and @{$images;}
$images
@{$images;}
Truth table0%0/3
A and B
A= $imagesB= @{$images;}
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return sprintf '%s.dkr.ecr.%s.amazonaws.com/%s:%s', $self->get_account, $self->get_region, $image_name, $tag; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||