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.009';
4 3     3   2512 use Moo::Role;
  3         21  
  3         54  
5              
6             sub rate_limit {
7 3     3 0 25251 my ($self, %opts) = @_;
8 3   50     85 my $spec = $self->spec // {};
9             $spec->{rateLimit} = {
10             $opts{average} ? (average => $opts{average}) : (),
11             $opts{burst} ? (burst => $opts{burst}) : (),
12 3 50       71 $opts{period} ? (period => $opts{period}) : (),
    100          
    50          
13             };
14 3         105 $self->spec($spec);
15 3         120 return $self;
16             }
17              
18             sub basic_auth {
19 1     1 0 6337 my ($self, %opts) = @_;
20 1   50     29 my $spec = $self->spec // {};
21             $spec->{basicAuth} = {
22             $opts{secret} ? (secret => $opts{secret}) : (),
23 1 50       22 $opts{realm} ? (realm => $opts{realm}) : (),
    50          
24             };
25 1         25 $self->spec($spec);
26 1         54 return $self;
27             }
28              
29             sub strip_prefix {
30 1     1 0 4972 my ($self, @prefixes) = @_;
31 1   50     30 my $spec = $self->spec // {};
32             $spec->{stripPrefix} = {
33 1         17 prefixes => \@prefixes,
34             };
35 1         24 $self->spec($spec);
36 1         34 return $self;
37             }
38              
39             sub redirect_https {
40 1     1 0 4855 my ($self) = @_;
41 1   50     45 my $spec = $self->spec // {};
42             $spec->{redirectScheme} = {
43 1         19 scheme => 'https',
44             permanent => 1,
45             };
46 1         27 $self->spec($spec);
47 1         36 return $self;
48             }
49              
50             sub add_request_header {
51 2     2 0 6243 my ($self, $key, $value) = @_;
52 2   100     54 my $spec = $self->spec // {};
53 2   50     31 my $headers = $spec->{headers} //= {};
54 2   50     11 my $custom = $headers->{customRequestHeaders} //= {};
55 2         8 $custom->{$key} = $value;
56 2         48 $self->spec($spec);
57 2         67 return $self;
58             }
59              
60             sub add_response_header {
61 1     1 0 3 my ($self, $key, $value) = @_;
62 1   50     26 my $spec = $self->spec // {};
63 1   50     10 my $headers = $spec->{headers} //= {};
64 1   50     8 my $custom = $headers->{customResponseHeaders} //= {};
65 1         4 $custom->{$key} = $value;
66 1         24 $self->spec($spec);
67 1         28 return $self;
68             }
69              
70             1;
71              
72             __END__