| 1 | package PlugAuth::Client; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 42 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 42 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 42 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 42 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 42 | ▶ | use Clustericious::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: PlugAuth Client | ||||||||||||||||||||
| 10 | 42 | our $VERSION = '0.39'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 42 | route welcome => 'GET', '/'; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 42 | route auth => 'GET', '/auth'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 42 | route_doc authz => "user action resource"; | |||||||||||||||||||
| 20 | sub authz | ||||||||||||||||||||
| 21 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
authz: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 22 | 4 | my($self, $user, $action, $resource) = @_; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 4 | my $url = Mojo::URL->new( $self->server_url ); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 4 | ▶ | $resource = "/$resource" unless $resource =~ m{^/}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 4 | $url->path("/authz/user/$user/$action$resource"); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 4 | $self->_doit('GET', $url); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 42 | route user => 'GET', '/user'; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 42 | route create_user => 'POST', '/user', \("--user username --password password"); | |||||||||||||||||||
| 38 | 42 | route_args create_user => [ | |||||||||||||||||||
| 39 | { name => 'user', type => '=s', required => 1, modifies_payload => 'hash' }, | ||||||||||||||||||||
| 40 | { name => 'password', type => '=s', required => 1, modifies_payload => 'hash' }, | ||||||||||||||||||||
| 41 | { name => 'groups', type => '=s', required => 0, modifies_payload => 'hash' }, | ||||||||||||||||||||
| 42 | ]; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 42 | route delete_user => 'DELETE', '/user', \("user"); | |||||||||||||||||||
| 46 | 42 | route_args delete_user => [ | |||||||||||||||||||
| 47 | { name => 'user', type => '=s', required => 1, modifies_url => 'append' }, | ||||||||||||||||||||
| 48 | ]; | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 42 | route groups => 'GET', '/groups', \("user"); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 42 | route_doc change_password => 'username password'; | |||||||||||||||||||
| 55 | sub change_password | ||||||||||||||||||||
| 56 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
change_password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 57 | 1 | my($self, $user, $password) = @_; | |||||||||||||||||||
| 58 | 1 | my $url = Mojo::URL->new( $self->server_url ); | |||||||||||||||||||
| 59 | 1 | $url->path("/user/$user"); | |||||||||||||||||||
| 60 | 1 | $self->_doit('POST', $url, { password => $password }); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 42 | route group => 'GET', '/group'; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 42 | route users => 'GET', '/users', \("group"); | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 42 | route create_group => 'POST', '/group', \("--group group --users user1,user2,..."); | |||||||||||||||||||
| 71 | 42 | route_args create_group => [ | |||||||||||||||||||
| 72 | { name => 'group', type => '=s', required => 1, modifies_payload => 'hash' }, | ||||||||||||||||||||
| 73 | { name => 'users', type => '=s', required => 1, modifies_payload => 'hash' }, | ||||||||||||||||||||
| 74 | ]; | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 42 | route_doc 'update_group' => 'group --users user1,user2,...'; | |||||||||||||||||||
| 78 | 42 | route_args update_group => [ | |||||||||||||||||||
| 79 | { name => 'group', type => '=s', required => 1, modifies_url => 'append', 'positional' => 'one' }, | ||||||||||||||||||||
| 80 | { name => 'users', type => '=s', required => 1 }, | ||||||||||||||||||||
| 81 | ]; | ||||||||||||||||||||
| 82 | sub update_group | ||||||||||||||||||||
| 83 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
update_group: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||
| 85 | 0 | my $group = shift; | |||||||||||||||||||
| 86 | 0 | ▶ | my $args = ref($_[0]) eq 'HASH' ? $_[0] : {@_}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | LOGDIE "group needed for update" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | unless $group; | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $url = Mojo::URL->new( $self->server_url ); | |||||||||||||||||||
| 92 | 0 | $url->path("/group/$group"); | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | TRACE("updating $group ", $url->to_string); | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | $self->_doit('POST', $url, { users => $args->{users} // $args->{'--users'} }); | ||||||||||||||||||
|
Condition0%0/3
$args->{"users"} // $args->{"--users"}
MC/DC0%0/2
$args->{"users"} // $args->{"--users"}
$args->{"users"}
$args->{"--users"}
Truth table0%0/3
A // B
A= $args->{"users"}B= $args->{"--users"}
| |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 42 | route delete_group => 'DELETE', '/group', \("group"); | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 42 | route 'group_add_user' => 'POST' => '/group'; | |||||||||||||||||||
| 104 | 42 | route_args 'group_add_user' => [ | |||||||||||||||||||
| 105 | { name => 'group', type => '=s', modifies_url => 'append', 'positional' => 'one' }, | ||||||||||||||||||||
| 106 | { name => 'user', type => '=s', modifies_url => 'append', 'positional' => 'one' }, | ||||||||||||||||||||
| 107 | ]; | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 42 | route 'group_delete_user' => 'DELETE' => '/group'; | |||||||||||||||||||
| 111 | 42 | route_args 'group_delete_user' => [ | |||||||||||||||||||
| 112 | { name => 'group', type => '=s', modifies_url => 'append', 'positional' => 'one' }, | ||||||||||||||||||||
| 113 | { name => 'user', type => '=s', modifies_url => 'append', 'positional' => 'one' }, | ||||||||||||||||||||
| 114 | ]; | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 42 | route 'grant' => 'POST' => '/grant'; | |||||||||||||||||||
| 118 | 42 | route_args 'grant' => [ | |||||||||||||||||||
| 119 | { name => 'user', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 120 | { name => 'action', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 121 | { name => 'resource', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 122 | ]; | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 42 | route 'revoke' => 'DELETE' => '/grant'; | |||||||||||||||||||
| 126 | 42 | route_args 'revoke' => [ | |||||||||||||||||||
| 127 | { name => 'user', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 128 | { name => 'action', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 129 | { name => 'resource', type => '=s', modifies_url => 'append', positional => 'one' }, | ||||||||||||||||||||
| 130 | ]; | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 42 | route granted => 'GET', '/grant'; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 42 | route actions => 'GET', '/actions'; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 42 | route host_tag => 'GET', '/host', \("host tag"); | |||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 42 | route resources => 'GET', '/authz/resources', \("user action resource_regex"); | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub _remove_prefixes | ||||||||||||||||||||
| 146 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
_remove_prefixes: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 147 | 1 | my @in = sort @_; | |||||||||||||||||||
| 148 | 1 | my @out; | |||||||||||||||||||
| 149 | 1 | ▶ | while(my $item = shift @in) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | { | ||||||||||||||||||||
| 151 | 2 | @in = grep { substr($_, 0, length $item) ne $item } @in; | |||||||||||||||||||
| 152 | 2 | push @out, $item; | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | 1 | @out; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 42 | route_doc action_resources => "user"; | |||||||||||||||||||
| 158 | sub action_resources | ||||||||||||||||||||
| 159 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
action_resources: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 160 | 0 | my($self, $user) = @_; | |||||||||||||||||||
| 161 | 0 | my %table; | |||||||||||||||||||
| 162 | 0 | foreach my $action (@{ $self->actions }) | |||||||||||||||||||
| 163 | { | ||||||||||||||||||||
| 164 | 0 | my $resources = $self->resources($user, $action, '/'); | |||||||||||||||||||
| 165 | 0 | ▶ | $table{$action} = [_remove_prefixes(@$resources)] if @$resources > 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | 0 | \%table; | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 42 | route_doc action_resource => 'audit'; | |||||||||||||||||||
| 172 | sub audit | ||||||||||||||||||||
| 173 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
audit: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 174 | 0 | my($self, $year, $month, $day) = @_; | |||||||||||||||||||
| 175 | 0 | my $uri; | |||||||||||||||||||
| 176 | 0 | ▶ | if(defined $day) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 177 | { | ||||||||||||||||||||
| 178 | 0 | $uri = join('/', '', 'audit', $year, sprintf("%02d", $month), sprintf("%02d", $day)); | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | else | ||||||||||||||||||||
| 181 | { | ||||||||||||||||||||
| 182 | # TODO: Clustericious::Client doesn't handle 302 correctly | ||||||||||||||||||||
| 183 | 0 | $uri = join('/', '', 'audit', 'today'); | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | 0 | $self->_doit(GET => $uri); | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 42 | 1; | |||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||