| 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.020'; | |||||||||
| 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 perm | ||||||||||
| 100 | |||||||||||
| 101 | Perm | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||
| 104 | |||||||||||
| 105 | 9 | has perm => ( | |||||||||
| 106 | is => 'lazy', | ||||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | sub _build_perm { | ||||||||||
| 110 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_perm: not called CC=3 SCAR=24.8
| |||||||||||
| 111 | 0 | my $perm; | |||||||||
| 112 | 0 | for my $key ( keys %{$self} ) { | |||||||||
| 113 | 0 | ▶ | unless ( $key =~ /(?:name|etcd|cb|endpoint)$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | $perm->{$key} = $self->{$key}; | |||||||||
| 115 | } | ||||||||||
| 116 | } | ||||||||||
| 117 | 0 | return $perm; | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | =head2 grant | ||||||||||
| 121 | |||||||||||
| 122 | Grant permission to role | ||||||||||
| 123 | |||||||||||
| 124 | =cut | ||||||||||
| 125 | |||||||||||
| 126 | sub grant {; | ||||||||||
| 127 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
grant: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 128 | 0 | $self->{endpoint} = '/auth/role/grant'; | |||||||||
| 129 | 0 | $self->{json_args} = to_json( {name => $self->name, perm => $self->perm } ); | |||||||||
| 130 | 0 | $self->request; | |||||||||
| 131 | 0 | return $self; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | =head2 revoke | ||||||||||
| 135 | |||||||||||
| 136 | Revoke permission to role | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||
| 140 | sub revoke {; | ||||||||||
| 141 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
revoke: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 142 | 0 | $self->{endpoint} = '/auth/role/revoke'; | |||||||||
| 143 | 0 | $self->request; | |||||||||
| 144 | 0 | return $self; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | 9 | 1; | |||||||||