Etcd/Auth/RolePermission.pm

filter: Statementstmt 64.0% 41 / 64 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 10 / 15 Podpod 100% 2 / 2 totaltotal 62.3% 53 / 85 CC 4 SCAR 16.9
CC
4
Cov
60%
_build_perm
20.0
__ANON__
2.0
__ANON__
2.0
CRAP 5.4
« Etcd/KV/Op.pm ↑ Summary Etcd/Maintenance.pm »
1 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Net::Etcd::Auth::RolePermission;
3  
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Types::Standard qw(Str Int Bool HashRef ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 with 'Net::Etcd::Role::Actions';
15  
16 9 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 Net::Etcd::Auth::RolePermission
21  
22 =cut
23  
24 9 our $VERSION = '0.022';
25  
26 =head1 DESCRIPTION
27  
28 Permission
29  
30  
31 =head2 endpoint
32  
33 =cut
34  
35 9 has endpoint => (
36 is => 'ro',
37 isa => Str,
38 );
39  
40 =head2 name
41  
42 name of role
43  
44 =cut
45  
46 9 has name => (
47 is => 'ro',
48 isa => Str,
49 );
50  
51 =head2 role
52  
53 name of role
54 * only used in revoke, use name for grant... not my idea.
55  
56 =cut
57  
58 9 has role => (
59 is => 'ro',
60 isa => Str,
61 );
62  
63 =head2 key
64  
65 name of key
66  
67 =cut
68  
69 has key => (
70 is => 'ro',
71 isa => Str,
72 required => 1,
73 0 ▶ coerce => sub { return encode_base64( $_[0], '' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 9 );
75  
76 =head2 range_end
77  
78 End of key range
79  
80 =cut
81  
82 has range_end => (
83 is => 'ro',
84 isa => Str,
85 0 ▶ coerce => sub { return encode_base64( $_[0], '' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 9 );
87  
88 =head2 permType
89  
90 valid options are READ, WRITE, and READWRITE
91  
92 =cut
93  
94 9 has permType =>(
95 is => 'ro',
96 isa => Str,
97 );
98  
99 =head2 prefix
100  
101 set to true to grant a prefix permission, C<range_end> will be ignored.
102  
103 =cut
104  
105 9 has prefix =>(
106 is => 'ro',
107 isa => Str,
108 );
109  
110 =head2 perm
111  
112 Perm
113  
114 =cut
115  
116 9 has perm => (
117 is => 'lazy',
118 );
119  
120 0 ▶sub _build_perm {
Subroutine _build_perm: not called CC=4 SCAR=30.0
121 0 my ($self) = @_;
122 0 my $perm;
123 0 ▶ if ($self->{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"prefix"}) 0 0 0
124 0 my $key = decode_base64($self->{key});
125 0 my $key_last_char = chr(ord(substr($key, -1)) + 0x1);
126 0 my $range_end_str = substr($key, 0, (length($key) - 1)) . $key_last_char;
127 0 $self->{range_end} = encode_base64( $range_end_str, '' );
128 }
129 0 for my $key ( keys %{$self} ) {
130 0 ▶ unless ( $key =~ /(?:prefix|name|etcd|cb|endpoint)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key =~ /(?:prefix|name|etcd|cb|endpoint)$/) 0 0 0
131 0 $perm->{$key} = $self->{$key};
132 }
133 }
134 0 return $perm;
135 }
136  
137 =head2 grant
138  
139 Grant permission to role
140  
141 =cut
142  
143 0 ▶sub grant {;
Subroutine grant: not called CC=1 SCAR=6.9
Pod documented
144 0 my ($self) = @_;
145 0 $self->{endpoint} = '/auth/role/grant';
146 0 $self->{json_args} = to_json( {name => $self->name, perm => $self->perm } );
147 0 $self->request;
148 0 return $self;
149 }
150  
151 =head2 revoke
152  
153 Revoke permission to role
154  
155 =cut
156  
157 0 ▶sub revoke {;
Subroutine revoke: not called CC=1 SCAR=6.9
Pod documented
158 0 my ($self) = @_;
159 0 $self->{endpoint} = '/auth/role/revoke';
160 0 $self->request;
161 0 return $self;
162 }
163  
164 9 1;
« Etcd/KV/Op.pm ↑ Summary Etcd/Maintenance.pm »