« lib/IO/K8s/ApiextensionsApiserver/Pkg/Apis/Apiextensions/V1/JSONSchemaPropsOrBool.pm
↑ Summary
lib/IO/K8s/Role/NetworkPolicy.pm »
| 1 | package IO::K8s::Role::CertManaged; | ||||||||||||||||||||||
| 2 | # ABSTRACT: Role for cert-manager certificate and issuer management | ||||||||||||||||||||||
| 3 | 16 | our $VERSION = '1.112'; | |||||||||||||||||||||
| 4 | 16 | ▶ | use Carp qw(croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | # Imports above `use Moo::Role` on purpose: Role::Tiny treats subs already in | ||||||||||||||||||||||
| 6 | # the package as not-methods, so their names stay off every consumer. A `use` | ||||||||||||||||||||||
| 7 | # below that line composes its exports onto all shipped classes (k118). | ||||||||||||||||||||||
| 8 | 16 | ▶ | use Moo::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | # The fluent setters below build the spec through IO::K8s::Role::SpecBuilder | ||||||||||||||||||||||
| 11 | # rather than by hand, so that role is a hard dependency of this one (k103). | ||||||||||||||||||||||
| 12 | # IO::K8s::Role::APIObject composes SpecBuilder for every top-level Kind, so | ||||||||||||||||||||||
| 13 | # these are satisfied for anything built with IO::K8s::APIObject; a class | ||||||||||||||||||||||
| 14 | # that composes this role without them now fails at composition time, | ||||||||||||||||||||||
| 15 | # naming the missing method, instead of at the first setter call. | ||||||||||||||||||||||
| 16 | 16 | requires qw( spec_push spec_set ); | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | # --- Certificate methods --- | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 4 | ▶ | sub for_domains { | ||||||||||||||||||||
|
Subroutine
for_domains: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 22 | 4 | my ($self, @domains) = @_; | |||||||||||||||||||||
| 23 | 4 | $self->spec_push('dnsNames', @domains); | |||||||||||||||||||||
| 24 | 4 | return $self; | |||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 3 | ▶ | sub with_issuer { | ||||||||||||||||||||
|
Subroutine
with_issuer: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||
| 29 | 3 | my ($self, $name, %opts) = @_; | |||||||||||||||||||||
| 30 | $self->spec_set('issuerRef', { | ||||||||||||||||||||||
| 31 | name => $name, | ||||||||||||||||||||||
| 32 | kind => $opts{kind} // 'Issuer', | ||||||||||||||||||||||
| 33 | 3 | ▶ | group => $opts{group} || 'cert-manager.io', | ||||||||||||||||||||
|
Condition50%2/4
$opts{"kind"} // "Issuer"
$opts{'group'} || 'cert-manager.io'
MC/DC0%0/1
$opts{"kind"} // "Issuer"
$opts{"kind"}
MC/DC0%0/1
$opts{'group'} || 'cert-manager.io'
$opts{'group'}
Truth table50%1/2
A
A= $opts{"kind"}
Truth table50%1/2
A
A= $opts{'group'}
| |||||||||||||||||||||||
| 34 | }); | ||||||||||||||||||||||
| 35 | 3 | return $self; | |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 3 | ▶ | sub store_in_secret { | ||||||||||||||||||||
|
Subroutine
store_in_secret: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 40 | 3 | my ($self, $secret_name) = @_; | |||||||||||||||||||||
| 41 | 3 | $self->spec_set('secretName', $secret_name); | |||||||||||||||||||||
| 42 | 3 | return $self; | |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 3 | ▶ | sub add_ip_san { | ||||||||||||||||||||
|
Subroutine
add_ip_san: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 47 | 3 | my ($self, @ips) = @_; | |||||||||||||||||||||
| 48 | 3 | require IO::K8s::Types::Net; | |||||||||||||||||||||
| 49 | 3 | for my $ip (@ips) { | |||||||||||||||||||||
| 50 | 4 | ▶ | croak "'$ip' is not a valid IP address" | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 51 | unless IO::K8s::Types::Net::IPAddress()->check($ip); | ||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | 2 | $self->spec_push('ipAddresses', @ips); | |||||||||||||||||||||
| 54 | 2 | return $self; | |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 3 | ▶ | sub renew_before { | ||||||||||||||||||||
|
Subroutine
renew_before: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||
| 59 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 60 | 3 | ▶ | if ($opts{days}) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 61 | 3 | $self->spec_set('renewBefore', ($opts{days} * 24) . 'h0m0s'); | |||||||||||||||||||||
| 62 | } elsif ($opts{hours}) { | ||||||||||||||||||||||
| 63 | 0 | $self->spec_set('renewBefore', $opts{hours} . 'h0m0s'); | |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||
| 65 | 3 | return $self; | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | # --- Issuer/ClusterIssuer methods --- | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 6 | ▶ | sub letsencrypt { | ||||||||||||||||||||
|
Subroutine
letsencrypt: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||
| 72 | 6 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 73 | 6 | ▶ | my $email = $opts{email} or croak 'email is required for letsencrypt'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 74 | 6 | ▶ | my $production = $opts{production} // 0; | ||||||||||||||||||||
|
Condition100%2/2
$opts{"production"} // 0
MC/DC100%1/1
$opts{"production"} // 0
$opts{"production"}
Truth table100%2/2
A
A= $opts{"production"}
| |||||||||||||||||||||||
| 75 | 6 | ▶ | my $server = $production | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 76 | ? 'https://acme-v02.api.letsencrypt.org/directory' | ||||||||||||||||||||||
| 77 | : 'https://acme-staging-v02.api.letsencrypt.org/directory'; | ||||||||||||||||||||||
| 78 | $self->spec_set('acme', { | ||||||||||||||||||||||
| 79 | email => $email, | ||||||||||||||||||||||
| 80 | server => $server, | ||||||||||||||||||||||
| 81 | 6 | ▶ | privateKeySecretRef => { name => $opts{secret} // 'letsencrypt-account-key' }, | ||||||||||||||||||||
|
Condition50%1/2
$opts{"secret"} // "letsencrypt-account-key"
MC/DC0%0/1
$opts{"secret"} // "letsencrypt-account-key"
$opts{"secret"}
Truth table50%1/2
A
A= $opts{"secret"}
| |||||||||||||||||||||||
| 82 | }); | ||||||||||||||||||||||
| 83 | 6 | return $self; | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | 2 | ▶ | sub self_signed { | ||||||||||||||||||||
|
Subroutine
self_signed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 88 | 2 | my ($self) = @_; | |||||||||||||||||||||
| 89 | 2 | $self->spec_set('selfSigned', {}); | |||||||||||||||||||||
| 90 | 2 | return $self; | |||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 3 | ▶ | sub ca { | ||||||||||||||||||||
|
Subroutine
ca: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 95 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 96 | $self->spec_set('ca', { | ||||||||||||||||||||||
| 97 | 3 | ▶ | secretName => $opts{secret} // croak('secret is required for ca'), | ||||||||||||||||||||
|
Condition100%2/2
$opts{"secret"} // croak("secret is required for ca")
MC/DC100%1/1
$opts{"secret"} // croak("secret is required for ca")
$opts{"secret"}
Truth table100%2/2
A
A= $opts{"secret"}
| |||||||||||||||||||||||
| 98 | }); | ||||||||||||||||||||||
| 99 | 2 | return $self; | |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 3 | ▶ | sub add_http01_solver { | ||||||||||||||||||||
|
Subroutine
add_http01_solver: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 104 | 3 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 105 | 3 | my $solver = { http01 => { ingress => {} } }; | |||||||||||||||||||||
| 106 | 3 | ▶ | $solver->{http01}{ingress}{class} = $opts{class} if $opts{class}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 107 | 3 | $self->spec_push('acme.solvers', $solver); | |||||||||||||||||||||
| 108 | 3 | return $self; | |||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | 2 | ▶ | sub add_dns01_solver { | ||||||||||||||||||||
|
Subroutine
add_dns01_solver: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||
| 113 | 2 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 114 | 2 | my %dns01; | |||||||||||||||||||||
| 115 | 2 | ▶ | if ($opts{provider} eq 'cloudflare') { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 116 | $dns01{cloudflare} = { | ||||||||||||||||||||||
| 117 | 2 | ▶ | $opts{secret} ? (apiTokenSecretRef => { name => $opts{secret}, key => $opts{key} // 'api-token' }) : (), | ||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$opts{"key"} // "api-token"
MC/DC0%0/1
$opts{"key"} // "api-token"
$opts{"key"}
Truth table50%1/2
A
A= $opts{"key"}
| |||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||
| 119 | } elsif ($opts{provider} eq 'route53') { | ||||||||||||||||||||||
| 120 | $dns01{route53} = { | ||||||||||||||||||||||
| 121 | 0 | ▶ | $opts{region} ? (region => $opts{region}) : (), | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||
| 124 | 0 | $dns01{$opts{provider}} = {}; | |||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||
| 126 | 2 | $self->spec_push('acme.solvers', { dns01 => \%dns01 }); | |||||||||||||||||||||
| 127 | 2 | return $self; | |||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||
| 129 | |||||||||||||||||||||||
| 130 | 16 | 1; | |||||||||||||||||||||
| 131 | |||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||