File Coverage

blib/lib/IO/K8s/Role/MiddlewareBuilder.pm
Criterion Covered Total %
statement 37 37 100.0
branch 6 10 60.0
condition 11 20 55.0
subroutine 7 7 100.0
pod 0 6 0.0
total 61 80 76.2


line stmt bran cond sub pod time code
1             package IO::K8s::Role::MiddlewareBuilder;
2             # ABSTRACT: Role for building Traefik middleware configuration
3             our $VERSION = '1.008';
4 3     3   2461 use Moo::Role;
  3         8  
  3         24  
5              
6             sub rate_limit {
7 3     3 0 15115 my ($self, %opts) = @_;
8 3   50     49 my $spec = $self->spec // {};
9             $spec->{rateLimit} = {
10             $opts{average} ? (average => $opts{average}) : (),
11             $opts{burst} ? (burst => $opts{burst}) : (),
12 3 50       39 $opts{period} ? (period => $opts{period}) : (),
    100          
    50          
13             };
14 3         36 $self->spec($spec);
15 3         63 return $self;
16             }
17              
18             sub basic_auth {
19 1     1 0 4504 my ($self, %opts) = @_;
20 1   50     14 my $spec = $self->spec // {};
21             $spec->{basicAuth} = {
22             $opts{secret} ? (secret => $opts{secret}) : (),
23 1 50       15 $opts{realm} ? (realm => $opts{realm}) : (),
    50          
24             };
25 1         12 $self->spec($spec);
26 1         18 return $self;
27             }
28              
29             sub strip_prefix {
30 1     1 0 3344 my ($self, @prefixes) = @_;
31 1   50     26 my $spec = $self->spec // {};
32             $spec->{stripPrefix} = {
33 1         16 prefixes => \@prefixes,
34             };
35 1         24 $self->spec($spec);
36 1         32 return $self;
37             }
38              
39             sub redirect_https {
40 1     1 0 3842 my ($self) = @_;
41 1   50     14 my $spec = $self->spec // {};
42             $spec->{redirectScheme} = {
43 1         10 scheme => 'https',
44             permanent => 1,
45             };
46 1         12 $self->spec($spec);
47 1         17 return $self;
48             }
49              
50             sub add_request_header {
51 2     2 0 4231 my ($self, $key, $value) = @_;
52 2   100     27 my $spec = $self->spec // {};
53 2   50     16 my $headers = $spec->{headers} //= {};
54 2   50     8 my $custom = $headers->{customRequestHeaders} //= {};
55 2         5 $custom->{$key} = $value;
56 2         22 $self->spec($spec);
57 2         33 return $self;
58             }
59              
60             sub add_response_header {
61 1     1 0 3 my ($self, $key, $value) = @_;
62 1   50     11 my $spec = $self->spec // {};
63 1   50     7 my $headers = $spec->{headers} //= {};
64 1   50     6 my $custom = $headers->{customResponseHeaders} //= {};
65 1         3 $custom->{$key} = $value;
66 1         11 $self->spec($spec);
67 1         14 return $self;
68             }
69              
70             1;
71              
72             __END__