| 1 | package Mail::TLSRPT::Policy; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TLSRPT policy object | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | our $VERSION = '2.20261104'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Mail::TLSRPT::Pragmas; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Mail::TLSRPT::Failure; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | has policy_type => (is => 'rw', isa => Enum[qw( tlsa sts no-policy-found )], required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | has policy_string => (is => 'rw', isa => ArrayRef, required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | has policy_domain => (is => 'rw', isa => Str, required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | has policy_mx_host => (is => 'rw', isa => Str, required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | has total_successful_session_count => (is => 'rw', isa => Int, required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | has total_failure_session_count => (is => 'rw', isa => Int, required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | has failures => (is => 'rw', isa => ArrayRef, required => 0, lazy => 1, builder => sub{return []} ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
_build_failures: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | sub new_from_data($class,$data) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_data: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | my @failures; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | foreach my $failure ( $data->{'failure-details'}->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | push @failures, Mail::TLSRPT::Failure->new_from_data($failure); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | policy_type => $data->{policy}->{'policy-type'}, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | policy_string => $data->{policy}->{'policy-string'} // [], | ||||||||||||||||||||||||||||||||||||||||||
| 25 | policy_domain => $data->{policy}->{'policy-domain'}, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | policy_mx_host => $data->{policy}->{'mx-host'} // '', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | total_successful_session_count => $data->{summary}->{'total-successful-session-count'} // 0, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | total_failure_session_count => $data->{summary}->{'total-failure-session-count'} // 0, | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
$data->{"policy"}{"policy-string"} // []
$data->{"policy"}{"mx-host"} // ""
$data->{"summary"}{"total-successful-session-count"} // 0
$data->{"summary"}{"total-failure-session-count"} // 0
MC/DC100%1/1
$data->{"policy"}{"policy-string"} // []
$data->{"policy"}{"policy-string"}
MC/DC100%1/1
$data->{"policy"}{"mx-host"} // ""
$data->{"policy"}{"mx-host"}
MC/DC0%0/1
$data->{"summary"}{"total-successful-session-count"} // 0
$data->{"summary"}{"total-successful-session-count"}
MC/DC0%0/1
$data->{"summary"}{"total-failure-session-count"} // 0
$data->{"summary"}{"total-failure-session-count"}
Truth table100%2/2
A
A= $data->{"policy"}{"policy-string"}
Truth table100%2/2
A
A= $data->{"policy"}{"mx-host"}
Truth table50%1/2
A
A= $data->{"summary"}{"total-successful-session-count"}
Truth table50%1/2
A
A= $data->{"summary"}{"total-failure-session-count"}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | failures => \@failures, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | sub as_struct($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_struct: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | my @failures = map {$_->as_struct} $self->failures->@*; | |||||||||||||||||||||||||||||||||||||||||
| 37 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | policy => { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 'policy-type' => $self->policy_type, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'policy-string' => $self->policy_string, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'policy-domain' => $self->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'mx-host' => $self->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | summary => { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 'total-successful-session-count' => $self->total_successful_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 'total-failure-session-count' => $self->total_failure_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | scalar $self->failures->@* ? ( 'failure_details' => \@failures ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub as_string($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | return join( "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 'Policy:', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ' Type: '.$self->policy_type, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ' String: '. join('; ',$self->policy_string->@*), | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ' Domain: '.$self->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ' MX-Host: '.$self->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ' Successful-Session-Count: '.$self->total_successful_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ' Failure-Session-Count: '.$self->total_failure_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | map { $_->as_string } $self->failures->@*, | |||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub _register_prometheus($self,$prometheus) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_prometheus: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | $prometheus->declare('tlsrpt_sessions_total', help=>'TLSRPT tls sessions', type=>'counter' ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub process_prometheus($self,$report,$prometheus) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_prometheus: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $self->_register_prometheus($prometheus); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $prometheus->add('tlsrpt_sessions_total',$self->total_successful_session_count,{ | |||||||||||||||||||||||||||||||||||||||||
| 74 | result=>'successful', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | organization_name=>$report->organization_name, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | policy_type=>$self->policy_type, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | policy_domain=>$self->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | policy_mx_host=>$self->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $prometheus->add('tlsrpt_sessions_total',$self->total_failure_session_count,{ | |||||||||||||||||||||||||||||||||||||||||
| 81 | result=>'failure', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | organization_name=>$report->organization_name, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | policy_type=>$self->policy_type, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | policy_domain=>$self->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | policy_mx_host=>$self->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | Mail::TLSRPT::Failure->_register_prometheus($prometheus) if ! scalar $self->failures->@*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | foreach my $failure ( $self->failures->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | $failure->process_prometheus($self,$report,$prometheus); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub _csv_headers($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_csv_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | 'policy type', | |||||||||||||||||||||||||||||||||||||||||
| 96 | 'policy string', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 'policy domain', | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 'policy mx host', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 'total successful session count', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 'total failure session count', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | sub _csv_fragment($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_csv_fragment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $self->policy_type, | |||||||||||||||||||||||||||||||||||||||||
| 107 | join('; ',$self->policy_string->@*), | ||||||||||||||||||||||||||||||||||||||||||
| 108 | $self->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | $self->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | $self->total_successful_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | $self->total_failure_session_count, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||