FargateStack/Builder/Certificate.pm

filter: Statementstmt 39.2% 22 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 1 totaltotal 38.6% 29 / 75 CC 5 SCAR 20.3
CC
5
Cov
34%
build_certificate
20.0
__ANON__
6.0
BEGIN
1.0
CRAP 7.6
« ApplicationAutoscaling.pm ↑ Summary FargateStack/Constants.pm »
1 package App::FargateStack::Builder::Certificate;
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_certificate {
Subroutine build_certificate: not called CC=4 SCAR=30.0
Pod undocumented
16 ########################################################################
17 0 my ($self) = @_;
18  
19 0 my ( $config, $dryrun ) = $self->common_args(qw(config dryrun));
20  
21 0 my $domain = $config->{domain};
22  
23 0 my $acm = $self->fetch_acm( domain => $domain );
24  
25 0 my @all_certs = @{ $acm->list_certificates };
26  
27 0 my ($cert) = grep { $domain eq $_->{DomainName} } @all_certs;
28  
29 0 my $arn;
30  
31 0 ▶ if ($cert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cert) { } 0 0 0
32 0 my $status = $cert->{Status};
33  
34 0 $self->log_info( 'certificate: [%s] certificate exists, status: [%s]...skipping', $domain, $status );
35  
36 0 $arn = $cert->{CertificateArn};
37  
38 0 $self->inc_existing_resources( certificate => $arn );
39 }
40 else {
41 0 $self->log_warn( 'certificate: certificate for [%s] will be created...%s', $domain, $dryrun );
42  
43 $self->inc_required_resources(
44 0 ▶ certificate => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
45 0 ▶ return $self->get_config->{certficate_arn} // 'arn:???';
Condition0%0/2
$self->get_config->{"certficate_arn"} // "arn:???"
l!l
00
MC/DC0%0/1
$self->get_config->{"certficate_arn"} // "arn:???"
$self->get_config->{"certficate_arn"}
Truth table0%0/2
A
A= $self->get_config->{"certficate_arn"}
Aresult
11
00
46 }
47 0 );
48  
49 0 ▶ if ( !$dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dryrun) 0 0 0
50  
51 0 $arn = $acm->request_certificate();
52 0 $acm->check_result( message => 'ERROR: could not create certifcate for: [%s]', $domain );
53  
54 0 sleep $ACM_REQUEST_SLEEP_TIME;
55  
56 0 my $dns_record = $acm->describe_certificate( $arn, 'Certificate.DomainValidationOptions[0].ResourceRecord' );
57  
58 0 ▶ log_die( $self, 'ERROR: no DNS record found yet for %s', $arn )
Branch: 1 branch
BranchTrueFalseTotal
unless $dns_record 0 0 0
59 if !$dns_record;
60  
61 0 my ( $name, $type, $value ) = @{$dns_record}{qw(Name Type Value)};
62  
63 0 my $change_batch = {
64 ChangeBatch => {
65 Changes => [
66 { Action => 'UPSERT',
67 ResourceRecordSet => {
68 Name => $name,
69 Type => $type,
70 TTL => 300,
71 ResourceRecords => [ { Value => $value } ]
72 }
73 }
74 ]
75 }
76 };
77  
78 0 my $route53 = $self->fetch_route53();
79  
80 0 $route53->set_change_batch($change_batch);
81  
82 0 $route53->change_resource_record_sets;
83  
84 0 print {*STDERR} Dumper( [$route53] );
85  
86 0 $route53->check_result( message => 'ERROR: could not insert DNS record' );
87  
88 }
89 }
90  
91 0 $config->{certificate_arn} = $arn;
92  
93 0 return $cert;
94 }
95  
96 1 1;
« ApplicationAutoscaling.pm ↑ Summary FargateStack/Constants.pm »