| 1 | package Example::Comb::Mailer; | ||||||||||
| 2 | # ABSTRACT: Example Comb: an SMTP relay, replaced by its stub in the examples | ||||||||||
| 3 | |||||||||||
| 4 | # The real mailer relays through a mail provider, whose credentials are a | ||||||||||
| 5 | # Secret the Comb does not create. check says what is missing, which makes | ||||||||||
| 6 | # the Comb NeedsConfig instead of deploying something that cannot work. | ||||||||||
| 7 | # In the examples it never gets that far: they build its stub, | ||||||||||
| 8 | # Example::Comb::Mailer::Stub, found by the default stub_class. | ||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | extends 'Kubernetes::Comb'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Future; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub endpoints { { name => 'smtp', port => 25 } } | ||||||||
|
Subroutine
endpoints: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 17 | |||||||||||
| 18 | # The Secret with the relay credentials, next to the Comb. | ||||||||||
| 19 | 1 | ▶ | sub relay_secret { shift->name.'-relay' } | ||||||||
|
Subroutine
relay_secret: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub check { | ||||||||
|
Subroutine
check: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 22 | 0 | my ( $self ) = @_; | |||||||||
| 23 | 0 | ▶ | my @missing = defined $self->config->{relay_host} ? () : ('config.relay_host, the provider to relay through'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | my $secret = $self->relay_secret; | |||||||||
| 25 | # Any failure counts as missing here; a real class would tell a 404 from | ||||||||||
| 26 | # a failing API server and fail the Future for the latter. | ||||||||||
| 27 | return $self->k8s->get( 'Secret', $secret, namespace => $self->namespace )->then( | ||||||||||
| 28 | 0 | ▶ | sub { Future->done(@missing) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | ▶ | sub { Future->done( @missing, 'Secret '.$secret.' with the keys username and password' ) } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | 0 | ); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | sub manifests { | ||||||||
|
Subroutine
manifests: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | 1 | my ( $self ) = @_; | |||||||||
| 35 | 1 | my $name = $self->name; | |||||||||
| 36 | 1 | my $secret = $self->relay_secret; | |||||||||
| 37 | 1 | my %app = ( app => $name ); | |||||||||
| 38 | return ( | ||||||||||
| 39 | { | ||||||||||
| 40 | apiVersion => 'apps/v1', | ||||||||||
| 41 | kind => 'Deployment', | ||||||||||
| 42 | metadata => { name => $name }, | ||||||||||
| 43 | spec => { | ||||||||||
| 44 | replicas => 1, | ||||||||||
| 45 | selector => { matchLabels => {%app} }, | ||||||||||
| 46 | template => { | ||||||||||
| 47 | metadata => { labels => {%app} }, | ||||||||||
| 48 | spec => { containers => [ { | ||||||||||
| 49 | name => 'postfix', | ||||||||||
| 50 | image => 'boky/postfix', | ||||||||||
| 51 | env => [ | ||||||||||
| 52 | { name => 'RELAYHOST', value => $self->config->{relay_host} }, | ||||||||||
| 53 | { name => 'ALLOW_EMPTY_SENDER_DOMAINS', value => 'true' }, | ||||||||||
| 54 | 1 | map { +{ | |||||||||
| 55 | 2 | name => 'RELAYHOST_'.uc($_), | |||||||||
| 56 | valueFrom => { secretKeyRef => { name => $secret, key => $_ } } | ||||||||||
| 57 | } } qw( username password ) | ||||||||||
| 58 | ], | ||||||||||
| 59 | ports => [ { name => 'smtp', containerPort => 587 } ] | ||||||||||
| 60 | } ] } | ||||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | }, | ||||||||||
| 64 | { | ||||||||||
| 65 | apiVersion => 'v1', | ||||||||||
| 66 | kind => 'Service', | ||||||||||
| 67 | metadata => { name => $name }, | ||||||||||
| 68 | spec => { | ||||||||||
| 69 | selector => {%app}, | ||||||||||
| 70 | ports => [ { name => 'smtp', port => 25, targetPort => 587 } ] | ||||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | ); | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | 1; | |||||||||