line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
51
|
use utf8; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
56
|
|
2
|
|
|
|
|
|
|
package Net::Etcd::Auth::RolePermission; |
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
282
|
use strict; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
142
|
|
5
|
9
|
|
|
9
|
|
30
|
use warnings; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
176
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
54
|
use Moo; |
|
9
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
45
|
|
8
|
9
|
|
|
9
|
|
2034
|
use Types::Standard qw(Str Int Bool HashRef ArrayRef); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
73
|
|
9
|
9
|
|
|
9
|
|
6979
|
use MIME::Base64; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
385
|
|
10
|
9
|
|
|
9
|
|
51
|
use Carp; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
445
|
|
11
|
9
|
|
|
9
|
|
42
|
use JSON; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
61
|
|
12
|
9
|
|
|
9
|
|
924
|
use Data::Dumper; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
396
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Net::Etcd::Role::Actions'; |
15
|
|
|
|
|
|
|
|
16
|
9
|
|
|
9
|
|
47
|
use namespace::clean; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
37
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Net::Etcd::Auth::RolePermission |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.022'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Permission |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 endpoint |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has endpoint => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => Str, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 name |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
name of role |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
coerce => sub { return encode_base64( $_[0], '' ) }, |
74
|
|
|
|
|
|
|
); |
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
|
|
|
|
|
|
|
coerce => sub { return encode_base64( $_[0], '' ) }, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 permType |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
valid options are READ, WRITE, and READWRITE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
has permType =>( |
95
|
|
|
|
|
|
|
is => 'ro', |
96
|
|
|
|
|
|
|
isa => Str, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 prefix |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
set to true to grant a prefix permission, C will be ignored. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
has prefix =>( |
106
|
|
|
|
|
|
|
is => 'ro', |
107
|
|
|
|
|
|
|
isa => Str, |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 perm |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Perm |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has perm => ( |
117
|
|
|
|
|
|
|
is => 'lazy', |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _build_perm { |
121
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
122
|
0
|
|
|
|
|
|
my $perm; |
123
|
0
|
0
|
|
|
|
|
if ($self->{prefix}) { |
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} ) { |
|
0
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
unless ( $key =~ /(?:prefix|name|etcd|cb|endpoint)$/ ) { |
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
|
|
|
|
|
|
|
sub grant {; |
144
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub revoke {; |
158
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
159
|
0
|
|
|
|
|
|
$self->{endpoint} = '/auth/role/revoke'; |
160
|
0
|
|
|
|
|
|
$self->request; |
161
|
0
|
|
|
|
|
|
return $self; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |