Authentik/API.pm

filter: Statementstmt 97.1% 436 / 449 Branchbran 87.5% 133 / 152 Conditioncond 65.7% 50 / 76 MC/DCmcdc 36.1% 17 / 47 Subroutinesub 93.8% 137 / 146 Podpod 100% 95 / 95 totaltotal 89.9% 868 / 965 CC 107 SCAR 13.5
CC
107
Cov
91%
resolve_f
18.0
_paged_f
8.6
ensure_binding_f
8.0
CRAP 3.8
« Authentik/OIDC.pm ↑ Summary Authentik.pm »
1 package Net::Async::Authentik::API;
2  
3 # ABSTRACT: authentik REST API v3, asynchronously, with idempotent ensure methods
4  
5 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 with 'Net::Async::Authentik::Role::HTTP';
7 8 with 'WWW::Authentik::Role::HTTP';
8 8 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Types::Standard qw( Int Object Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use URI::Escape qw( uri_escape_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use WWW::Authentik::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use WWW::Authentik::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 our $VERSION = '0.001';
18  
19  
20 8 has base_url => ( is => 'ro', isa => Str, required => 1 );
21  
22  
23 8 has token => ( is => 'ro', isa => Str, predicate => 'has_token' );
24  
25  
26 8 has http => ( is => 'ro', isa => Object, required => 1 );
27  
28  
29 8 has page_size => ( is => 'ro', isa => Int, default => 100 );
30  
31  
32 24 ▶sub diff_class { 'WWW::Authentik::Diff' }
Subroutine diff_class: called CC=1 SCAR=0.0
Pod documented
33  
34  
35 75 ▶sub resolvable_fields { WWW::Authentik::API->resolvable_fields }
Subroutine resolvable_fields: called CC=1 SCAR=0.0
Pod documented
36 14 ▶sub uuid_pattern { WWW::Authentik::API->uuid_pattern }
Subroutine uuid_pattern: called CC=1 SCAR=0.0
Pod documented
37 1 ▶sub integer_pattern { WWW::Authentik::API->integer_pattern }
Subroutine integer_pattern: called CC=1 SCAR=0.0
Pod documented
38  
39  
40 #### transport
41  
42 266 ▶sub api_url { $_[0]->base_url.'/api/v3' }
Subroutine api_url: called CC=1 SCAR=0.0
Pod documented
43  
44  
45 267 ▶sub call_f {
Subroutine call_f: called CC=5 SCAR=16.1
Pod documented
46 267 my ( $self, $method, $path, $body ) = @_;
47 267 ▶ return $self->fail_validation( __PACKAGE__.' needs an API token' ) unless $self->has_token && length $self->token;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_token and length $self->token 2 265 267
Condition66%2/3
$self->has_token and length $self->token
!ll&&!rl&&r
20265
MC/DC50%1/2
$self->has_token and length $self->token
$self->has_token length $self->token
Truth table66%2/3
A and B
A= $self->has_tokenB= length $self->token
ABresult
0X0
100
111
48 265 ▶ $path = '/'.$path unless $path =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[\A/] 1 264 265
49 265 ▶ my %arg = defined $body ? ( json => $body ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 71 194 265
50 265 return $self->send_request_f( $method, $self->api_url.$path, %arg, bearer => $self->token );
51 }
52  
53  
54 238 ▶async sub _data_f { return ( await $_[0]->call_f( @_[ 1 .. $#_ ] ) )->{data} }
Subroutine _data_f: called CC=1 SCAR=0.0
55 23 ▶async sub _done_f { await $_[0]->call_f( @_[ 1 .. $#_ ] ); return 1 }
Subroutine _done_f: called CC=1 SCAR=0.0
56  
57 713 ▶sub _esc { uri_escape_utf8( $_[1] ) }
Subroutine _esc: called CC=1 SCAR=0.0
58  
59 107 ▶sub _query {
Subroutine _query: called CC=2 SCAR=6.9
60 107 my ( $self, %query ) = @_;
61 107 ▶ return '' unless %query;
Branch: 1 branch
BranchTrueFalseTotal
unless %query 1 106 107
62 306 return '?'.join '&', map { $self->_esc($_).'='.$self->_esc( $query{$_} ) }
63 106 grep { defined $query{$_} } sort keys %query;
64 }
65  
66 100 ▶async sub _paged_f {
Subroutine _paged_f: called CC=8 SCAR=21.5
67 100 my ( $self, $path, %query ) = @_;
68 100 ▶ my $page_size = delete $query{page_size} // $self->page_size;
Condition33%1/3
delete $query{"page_size"} // $self->page_size
l!l&&r!l&&!r
01000
MC/DC0%0/2
delete $query{"page_size"} // $self->page_size
delete $query{"page_size"} $self->page_size
Truth table33%1/3
A // B
A= delete $query{"page_size"}B= $self->page_size
ABresult
1X1
011
000
69 100 my ( @all, %seen );
70 100 my $page = 1;
71 # a broken answer whose next points at a page already fetched would loop
72 # for ever; %seen is the floor under that
73 100 ▶ while ( defined $page && $page > 0 && !$seen{$page}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $page and $page > 0 and not $seen{$page}++) 104 100 204
Condition83%5/6
defined $page and $page > 0 and not $seen{$page}++
!ll&&!rl&&r
982104
defined $page and $page > 0
!ll&&!rl&&r
098106
MC/DC66%2/3
defined $page and $page > 0 and not $seen{$page}++
defined $page $page > 0 not $seen{$page}++
Truth table75%3/4
A and B and not(C)
A= defined $pageB= $page > 0C= not $seen{$page}++
ABCresult
0XX0
10X0
1100
1111
74 104 my $data = await $self->_data_f( GET => $path.$self->_query( %query, page => $page, page_size => $page_size ) );
75 104 ▶ last unless ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 104 104
76 104 ▶ push @all, @{ $data->{results} || [] };
Condition50%1/2
$data->{'results'} || []
l!l
1040
MC/DC0%0/1
$data->{'results'} || []
$data->{'results'}
Truth table50%1/2
A
A= $data->{'results'}
Aresult
11
00
77 104 ▶ $page = ref $data->{pagination} eq 'HASH' ? $data->{pagination}{next} : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{'pagination'} eq 'HASH' ? : 104 0 104
78 }
79 100 return \@all;
80 8 }
81  
82 69 ▶sub _find_one {
Subroutine _find_one: called CC=2 SCAR=7.4
83 69 my ( $self, $list, $key, $value ) = @_;
84 69 ▶ my ( $found ) = grep { defined $_->{$key} && $_->{$key} eq $value } @$list;
Condition33%1/3
defined $_->{$key} && $_->{$key} eq $value
!ll&&!rl&&r
0050
MC/DC0%0/2
defined $_->{$key} && $_->{$key} eq $value
defined $_->{$key} $_->{$key} eq $value
Truth table33%1/3
A && B
A= defined $_->{$key}B= $_->{$key} eq $value
ABresult
0X0
100
111
85 69 return $found;
86 }
87  
88 # a finder called with nothing would otherwise fetch every object and compare
89 # each one against undef, warning once per row and finding nothing
90 124 ▶sub _need {
Subroutine _need: called CC=3 SCAR=11.0
91 124 my ( $self, $what, $value ) = @_;
92 124 ▶ return defined $value && length $value ? undef : $self->fail_validation( $what.' is needed' );
Branch: 1 branch
BranchTrueFalseTotal
defined $value && length $value ? : 105 19 124
Condition100%3/3
defined $value and length $value
!ll&&!rl&&r
109105
MC/DC100%2/2
defined $value and length $value
defined $value length $value
Truth table100%3/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
93 }
94  
95 39 ▶async sub _detail_f {
Subroutine _detail_f: called CC=6 SCAR=18.0
96 39 my ( $self, $path ) = @_;
97 39 my ( $object, $failed );
98 39 ▶ eval { $object = await $self->_data_f( GET => $path ); 1 } or $failed = $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $object = <custom op await>; 1 } } or $failed = $@ 29 10 39
99 # an answer with no body is not a failure, and $@ is empty there: telling
100 # the two apart on the truth of $object would die with the empty string
101 39 ▶ return $object unless defined $failed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $failed 29 10 39
102 10 ▶ return undef if blessed $failed && $failed->isa('WWW::Authentik::Error::API') && $failed->is_not_found;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($failed) and $failed->isa("WWW::Authentik::Error::API") and $failed->is_not_found 9 1 10
Condition66%4/6
builtin::blessed($failed) and $failed->isa("WWW::Authentik::Error::API") and $failed->is_not_found
!ll&&!rl&&r
109
builtin::blessed($failed) and $failed->isa("WWW::Authentik::Error::API")
!ll&&!rl&&r
019
MC/DC33%1/3
builtin::blessed($failed) and $failed->isa("WWW::Authentik::Error::API") and $failed->is_not_found
builtin::blessed($failed) $failed->isa("WWW::Authentik::Error::API") $failed->is_not_found
Truth table50%2/4
A and B and C
A= builtin::blessed($failed)B= $failed->isa("WWW::Authentik::Error::API")C= $failed->is_not_found
ABCresult
0XX0
10X0
1100
1111
103 1 die $failed;
104 8 }
105  
106 #### instance
107  
108 3 ▶sub version_f { $_[0]->_data_f( GET => '/admin/version/' ) }
Subroutine version_f: called CC=1 SCAR=0.0
Pod documented
109 1 ▶sub config_f { $_[0]->_data_f( GET => '/root/config/' ) }
Subroutine config_f: called CC=1 SCAR=0.0
Pod documented
110 2 ▶sub settings_f { $_[0]->_data_f( GET => '/admin/settings/' ) }
Subroutine settings_f: called CC=1 SCAR=0.0
Pod documented
111 5 ▶sub me_f { $_[0]->_data_f( GET => '/core/users/me/' ) }
Subroutine me_f: called CC=1 SCAR=0.0
Pod documented
112  
113  
114 #### users
115  
116 19 ▶sub list_users_f { my ( $self, %q ) = @_; $self->_paged_f( '/core/users/', %q ) }
Subroutine list_users_f: called CC=1 SCAR=0.0
Pod documented
117 3 ▶sub get_user_f { $_[0]->_data_f( GET => '/core/users/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_user_f: called CC=1 SCAR=0.0
Pod documented
118 10 ▶sub create_user_f { $_[0]->_data_f( POST => '/core/users/', $_[1] ) }
Subroutine create_user_f: called CC=1 SCAR=0.0
Pod documented
119 2 ▶sub update_user_f { $_[0]->_data_f( PATCH => '/core/users/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_user_f: called CC=1 SCAR=0.0
Pod documented
120 5 ▶sub delete_user_f { $_[0]->_done_f( DELETE => '/core/users/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_user_f: called CC=1 SCAR=0.0
Pod documented
121  
122 16 ▶async sub find_user_f {
Subroutine find_user_f: called CC=2 SCAR=6.9
Pod documented
123 16 my ( $self, $username ) = @_;
124 16 ▶ if ( my $bad = $self->_need( 'find_user: a username', $username ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_user: a username", $username)) 3 13 16
125 13 return $self->_find_one( await( $self->list_users_f( username => $username ) ), 'username', $username );
126 8 }
127  
128 2 ▶sub set_password_f {
Subroutine set_password_f: called CC=1 SCAR=0.0
Pod documented
129 2 my ( $self, $pk, $password ) = @_;
130 2 return $self->_done_f( POST => '/core/users/'.$self->_esc($pk).'/set_password/', { password => $password } );
131 }
132  
133 2 ▶sub create_service_account_f {
Subroutine create_service_account_f: called CC=4 SCAR=14.3
Pod documented
134 2 my ( $self, %arg ) = @_;
135 2 ▶ return $self->fail_validation('create_service_account needs a name') unless defined $arg{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"name"} 1 1 2
136 return $self->_data_f( POST => '/core/users/service_account/',
137 { name => $arg{name}, create_group => $arg{create_group} ? \1 : \0,
138 1 ▶ exists $arg{expiring} ? ( expiring => $arg{expiring} ) : () } );
Branch: 2 branches
BranchTrueFalseTotal
$arg{'create_group'} ? : 0 1 1
exists $arg{'expiring'} ? : 0 1 1
139 }
140  
141 1 ▶sub list_authenticators_f {
Subroutine list_authenticators_f: called CC=1 SCAR=0.0
Pod documented
142 1 my ( $self, $pk ) = @_;
143 1 return $self->_data_f( GET => '/authenticators/admin/all/'.$self->_query( user => $pk ) );
144 }
145  
146  
147 #### groups
148  
149 17 ▶sub list_groups_f { my ( $self, %q ) = @_; $self->_paged_f( '/core/groups/', %q ) }
Subroutine list_groups_f: called CC=1 SCAR=0.0
Pod documented
150 3 ▶sub get_group_f { $_[0]->_data_f( GET => '/core/groups/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_group_f: called CC=1 SCAR=0.0
Pod documented
151 6 ▶sub create_group_f { $_[0]->_data_f( POST => '/core/groups/', $_[1] ) }
Subroutine create_group_f: called CC=1 SCAR=0.0
Pod documented
152 2 ▶sub update_group_f { $_[0]->_data_f( PATCH => '/core/groups/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_group_f: called CC=1 SCAR=0.0
Pod documented
153 1 ▶sub delete_group_f { $_[0]->_done_f( DELETE => '/core/groups/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_group_f: called CC=1 SCAR=0.0
Pod documented
154  
155 19 ▶async sub find_group_f {
Subroutine find_group_f: called CC=2 SCAR=6.9
Pod documented
156 19 my ( $self, $name ) = @_;
157 19 ▶ if ( my $bad = $self->_need( 'find_group: a name', $name ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_group: a name", $name)) 2 17 19
158 17 return $self->_find_one( await( $self->list_groups_f( name => $name ) ), 'name', $name );
159 8 }
160  
161 1 ▶sub add_user_to_group_f {
Subroutine add_user_to_group_f: called CC=1 SCAR=0.0
Pod documented
162 1 my ( $self, $uuid, $pk ) = @_;
163 1 return $self->_done_f( POST => '/core/groups/'.$self->_esc($uuid).'/add_user/', { pk => $pk } );
164 }
165  
166 2 ▶sub remove_user_from_group_f {
Subroutine remove_user_from_group_f: called CC=1 SCAR=0.0
Pod documented
167 2 my ( $self, $uuid, $pk ) = @_;
168 2 return $self->_done_f( POST => '/core/groups/'.$self->_esc($uuid).'/remove_user/', { pk => $pk } );
169 }
170  
171  
172 #### tokens
173  
174 0 ▶sub list_tokens_f { my ( $self, %q ) = @_; $self->_paged_f( '/core/tokens/', %q ) }
Subroutine list_tokens_f: not called CC=1 SCAR=6.9
Pod documented
175 0 ▶sub get_token_f { $_[0]->_data_f( GET => '/core/tokens/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_token_f: not called CC=1 SCAR=6.9
Pod documented
176 4 ▶sub create_token_f { $_[0]->_data_f( POST => '/core/tokens/', $_[1] ) }
Subroutine create_token_f: called CC=1 SCAR=0.0
Pod documented
177 1 ▶sub update_token_f { $_[0]->_data_f( PATCH => '/core/tokens/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_token_f: called CC=1 SCAR=0.0
Pod documented
178 2 ▶sub delete_token_f { $_[0]->_done_f( DELETE => '/core/tokens/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_token_f: called CC=1 SCAR=0.0
Pod documented
179  
180 8 ▶sub find_token_f {
Subroutine find_token_f: called CC=2 SCAR=7.1
Pod documented
181 8 my ( $self, $identifier ) = @_;
182 8 ▶ return $self->_need( 'find_token: an identifier', $identifier )
Condition66%2/3
$self->_need('find_token: an identifier', $identifier) || $self->_detail_f('/core/tokens/' . $self->_esc($identifier) . '/')
l!l&&r!l&&!r
260
MC/DC0%0/2
$self->_need('find_token: an identifier', $identifier) || $self->_detail_f('/core/tokens/' . $self->_esc($identifier) . '/')
$self->_need('find_token: an identifier', $identifier) $self->_detail_f('/core/tokens/' . $self->_esc($identifier) . '/')
Truth table66%2/3
A || B
A= $self->_need('find_token: an identifier', $identifier)B= $self->_detail_f('/core/tokens/' . $self->_esc($identifier) . '/')
ABresult
1X1
011
000
183 || $self->_detail_f( '/core/tokens/'.$self->_esc($identifier).'/' );
184 }
185  
186 4 ▶sub view_token_key_f { $_[0]->_data_f( GET => '/core/tokens/'.$_[0]->_esc( $_[1] ).'/view_key/' ) }
Subroutine view_token_key_f: called CC=1 SCAR=0.0
Pod documented
187  
188 2 ▶sub set_token_key_f {
Subroutine set_token_key_f: called CC=1 SCAR=0.0
Pod documented
189 2 my ( $self, $identifier, $key ) = @_;
190 2 return $self->_done_f( POST => '/core/tokens/'.$self->_esc($identifier).'/set_key/', { key => $key } );
191 }
192  
193  
194 #### applications
195  
196 0 ▶sub list_applications_f { my ( $self, %q ) = @_; $self->_paged_f( '/core/applications/', %q ) }
Subroutine list_applications_f: not called CC=1 SCAR=6.9
Pod documented
197 3 ▶sub create_application_f { $_[0]->_data_f( POST => '/core/applications/', $_[1] ) }
Subroutine create_application_f: called CC=1 SCAR=0.0
Pod documented
198 1 ▶sub update_application_f { $_[0]->_data_f( PATCH => '/core/applications/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_application_f: called CC=1 SCAR=0.0
Pod documented
199 1 ▶sub delete_application_f { $_[0]->_done_f( DELETE => '/core/applications/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_application_f: called CC=1 SCAR=0.0
Pod documented
200  
201 8 ▶sub find_application_f {
Subroutine find_application_f: called CC=2 SCAR=7.1
Pod documented
202 8 my ( $self, $slug ) = @_;
203 8 ▶ return $self->_need( 'find_application: a slug', $slug )
Condition66%2/3
$self->_need('find_application: a slug', $slug) || $self->_detail_f('/core/applications/' . $self->_esc($slug) . '/')
l!l&&r!l&&!r
260
MC/DC0%0/2
$self->_need('find_application: a slug', $slug) || $self->_detail_f('/core/applications/' . $self->_esc($slug) . '/')
$self->_need('find_application: a slug', $slug) $self->_detail_f('/core/applications/' . $self->_esc($slug) . '/')
Truth table66%2/3
A || B
A= $self->_need('find_application: a slug', $slug)B= $self->_detail_f('/core/applications/' . $self->_esc($slug) . '/')
ABresult
1X1
011
000
204 || $self->_detail_f( '/core/applications/'.$self->_esc($slug).'/' );
205 }
206  
207 1 ▶sub check_access_f {
Subroutine check_access_f: called CC=2 SCAR=7.2
Pod documented
208 1 my ( $self, $slug, %opt ) = @_;
209 return $self->_data_f( GET => '/core/applications/'.$self->_esc($slug).'/check_access/'
210 1 ▶ .$self->_query( defined $opt{for_user} ? ( for_user => $opt{for_user} ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'for_user'} ? : 0 1 1
211 }
212  
213  
214 #### oauth2 providers
215  
216 12 ▶sub list_oauth2_providers_f { my ( $self, %q ) = @_; $self->_paged_f( '/providers/oauth2/', %q ) }
Subroutine list_oauth2_providers_f: called CC=1 SCAR=0.0
Pod documented
217 1 ▶sub get_oauth2_provider_f { $_[0]->_data_f( GET => '/providers/oauth2/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_oauth2_provider_f: called CC=1 SCAR=0.0
Pod documented
218 3 ▶sub create_oauth2_provider_f { $_[0]->_data_f( POST => '/providers/oauth2/', $_[1] ) }
Subroutine create_oauth2_provider_f: called CC=1 SCAR=0.0
Pod documented
219 4 ▶sub update_oauth2_provider_f { $_[0]->_data_f( PATCH => '/providers/oauth2/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_oauth2_provider_f: called CC=1 SCAR=0.0
Pod documented
220 1 ▶sub delete_oauth2_provider_f { $_[0]->_done_f( DELETE => '/providers/oauth2/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_oauth2_provider_f: called CC=1 SCAR=0.0
Pod documented
221  
222 14 ▶async sub find_oauth2_provider_f {
Subroutine find_oauth2_provider_f: called CC=2 SCAR=6.9
Pod documented
223 14 my ( $self, $name ) = @_;
224 14 ▶ if ( my $bad = $self->_need( 'find_oauth2_provider: a name', $name ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_oauth2_provider: a name", $name)) 2 12 14
225 12 return $self->_find_one( await( $self->list_oauth2_providers_f( name => $name ) ), 'name', $name );
226 8 }
227  
228 1 ▶sub provider_setup_urls_f { $_[0]->_data_f( GET => '/providers/oauth2/'.$_[0]->_esc( $_[1] ).'/setup_urls/' ) }
Subroutine provider_setup_urls_f: called CC=1 SCAR=0.0
Pod documented
229  
230 1 ▶sub preview_user_f {
Subroutine preview_user_f: called CC=2 SCAR=7.2
Pod documented
231 1 my ( $self, $pk, $user_pk ) = @_;
232 1 ▶ return $self->_data_f( GET => '/providers/oauth2/'.$self->_esc($pk).'/preview_user/'
Branch: 1 branch
BranchTrueFalseTotal
defined $user_pk ? : 1 0 1
233 .$self->_query( defined $user_pk ? ( for_user => $user_pk ) : () ) );
234 }
235  
236  
237 #### scope mappings
238  
239 22 ▶sub list_scope_mappings_f { my ( $self, %q ) = @_; $self->_paged_f( '/propertymappings/provider/scope/', %q ) }
Subroutine list_scope_mappings_f: called CC=1 SCAR=0.0
Pod documented
240 0 ▶sub get_scope_mapping_f { $_[0]->_data_f( GET => '/propertymappings/provider/scope/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_scope_mapping_f: not called CC=1 SCAR=6.9
Pod documented
241 2 ▶sub create_scope_mapping_f { $_[0]->_data_f( POST => '/propertymappings/provider/scope/', $_[1] ) }
Subroutine create_scope_mapping_f: called CC=1 SCAR=0.0
Pod documented
242 1 ▶sub update_scope_mapping_f { $_[0]->_data_f( PATCH => '/propertymappings/provider/scope/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_scope_mapping_f: called CC=1 SCAR=0.0
Pod documented
243 1 ▶sub delete_scope_mapping_f { $_[0]->_done_f( DELETE => '/propertymappings/provider/scope/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_scope_mapping_f: called CC=1 SCAR=0.0
Pod documented
244  
245 5 ▶async sub find_scope_mapping_f {
Subroutine find_scope_mapping_f: called CC=2 SCAR=6.9
Pod documented
246 5 my ( $self, $name ) = @_;
247 5 ▶ if ( my $bad = $self->_need( 'find_scope_mapping: a name', $name ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_scope_mapping: a name", $name)) 2 3 5
248 3 return $self->_find_one( await( $self->list_scope_mappings_f( name => $name ) ), 'name', $name );
249 8 }
250  
251 11 ▶async sub find_scope_mappings_by_scope_f {
Subroutine find_scope_mappings_by_scope_f: called CC=3 SCAR=11.0
Pod documented
252 11 my ( $self, @scopes ) = @_;
253 11 my @found;
254 11 for my $scope (@scopes) {
255 18 my ( $mapping ) = @{ await $self->list_scope_mappings_f( scope_name => $scope ) };
256 18 ▶ die $self->validation_error_class->new( message => 'no scope mapping for the scope "'.$scope.'"' )
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping 2 16 18
257 unless $mapping;
258 16 push @found, $mapping;
259 }
260 9 return \@found;
261 8 }
262  
263 1 ▶sub test_property_mapping_f {
Subroutine test_property_mapping_f: called CC=1 SCAR=0.0
Pod documented
264 1 my ( $self, $uuid, %arg ) = @_;
265 1 return $self->_data_f( POST => '/propertymappings/all/'.$self->_esc($uuid).'/test/', { %arg } );
266 }
267  
268  
269 #### flows
270  
271 0 ▶sub list_flows_f { my ( $self, %q ) = @_; $self->_paged_f( '/flows/instances/', %q ) }
Subroutine list_flows_f: not called CC=1 SCAR=6.9
Pod documented
272 3 ▶sub create_flow_f { $_[0]->_data_f( POST => '/flows/instances/', $_[1] ) }
Subroutine create_flow_f: called CC=1 SCAR=0.0
Pod documented
273 1 ▶sub update_flow_f { $_[0]->_data_f( PATCH => '/flows/instances/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_flow_f: called CC=1 SCAR=0.0
Pod documented
274 2 ▶sub delete_flow_f { $_[0]->_done_f( DELETE => '/flows/instances/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_flow_f: called CC=1 SCAR=0.0
Pod documented
275  
276 29 ▶sub find_flow_f {
Subroutine find_flow_f: called CC=2 SCAR=7.1
Pod documented
277 29 my ( $self, $slug ) = @_;
278 29 ▶ return $self->_need( 'find_flow: a slug', $slug )
Condition66%2/3
$self->_need('find_flow: a slug', $slug) || $self->_detail_f('/flows/instances/' . $self->_esc($slug) . '/')
l!l&&r!l&&!r
2270
MC/DC0%0/2
$self->_need('find_flow: a slug', $slug) || $self->_detail_f('/flows/instances/' . $self->_esc($slug) . '/')
$self->_need('find_flow: a slug', $slug) $self->_detail_f('/flows/instances/' . $self->_esc($slug) . '/')
Truth table66%2/3
A || B
A= $self->_need('find_flow: a slug', $slug)B= $self->_detail_f('/flows/instances/' . $self->_esc($slug) . '/')
ABresult
1X1
011
000
279 || $self->_detail_f( '/flows/instances/'.$self->_esc($slug).'/' );
280 }
281  
282 1 ▶async sub export_flow_f {
Subroutine export_flow_f: called CC=1 SCAR=0.0
Pod documented
283 1 my ( $self, $slug ) = @_;
284 1 return ( await $self->call_f( GET => '/flows/instances/'.$self->_esc($slug).'/export/' ) )->{content};
285 8 }
286  
287  
288 #### stages
289  
290 1 ▶sub stage_types_f { $_[0]->_data_f( GET => '/stages/all/types/' ) }
Subroutine stage_types_f: called CC=1 SCAR=0.0
Pod documented
291 14 ▶sub list_stages_f { my ( $self, %q ) = @_; $self->_paged_f( '/stages/all/', %q ) }
Subroutine list_stages_f: called CC=1 SCAR=0.0
Pod documented
292  
293 16 ▶async sub find_stage_f {
Subroutine find_stage_f: called CC=2 SCAR=6.9
Pod documented
294 16 my ( $self, $name ) = @_;
295 16 ▶ if ( my $bad = $self->_need( 'find_stage: a name', $name ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_stage: a name", $name)) 2 14 16
296 14 return $self->_find_one( await( $self->list_stages_f( name => $name ) ), 'name', $name );
297 8 }
298  
299 24 ▶sub _stage_path {
Subroutine _stage_path: called CC=4 SCAR=13.9
300 24 my ( $self, $type ) = @_;
301 24 ▶ return ( undef, $self->fail_validation('a stage type is needed, for example password or authenticator/validate') )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 1 23 24
Condition66%2/3
defined $type and length $type
!ll&&!rl&&r
1023
MC/DC50%1/2
defined $type and length $type
defined $type length $type
Truth table66%2/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
302 unless defined $type && length $type;
303 23 ▶ return ( undef, $self->fail_validation('/stages/all/ can only be read: name the stage type, for example password') )
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "all" 3 20 23
304 if $type eq 'all';
305 20 $type =~ s{\A/}{};
306 20 $type =~ s{/\z}{};
307 20 return ( '/stages/'.$type.'/', undef );
308 }
309  
310 5 ▶sub get_stage_f {
Subroutine get_stage_f: called CC=2 SCAR=7.0
Pod documented
311 5 my ( $self, $type, $uuid ) = @_;
312 5 my ( $path, $bad ) = $self->_stage_path($type);
313 5 ▶ return $bad || $self->_data_f( GET => $path.$self->_esc($uuid).'/' );
Condition66%2/3
$bad || $self->_data_f('GET', $path . $self->_esc($uuid) . '/')
l!l&&r!l&&!r
140
MC/DC0%0/2
$bad || $self->_data_f('GET', $path . $self->_esc($uuid) . '/')
$bad $self->_data_f('GET', $path . $self->_esc($uuid) . '/')
Truth table66%2/3
A || B
A= $badB= $self->_data_f('GET', $path . $self->_esc($uuid) . '/')
ABresult
1X1
011
000
314 }
315  
316 6 ▶sub create_stage_f {
Subroutine create_stage_f: called CC=2 SCAR=7.6
Pod documented
317 6 my ( $self, $type, $rep ) = @_;
318 6 my ( $path, $bad ) = $self->_stage_path($type);
319 6 ▶ return $bad || $self->_data_f( POST => $path, $rep );
Condition33%1/3
$bad || $self->_data_f('POST', $path, $rep)
l!l&&r!l&&!r
060
MC/DC0%0/2
$bad || $self->_data_f('POST', $path, $rep)
$bad $self->_data_f('POST', $path, $rep)
Truth table33%1/3
A || B
A= $badB= $self->_data_f('POST', $path, $rep)
ABresult
1X1
011
000
320 }
321  
322 3 ▶sub update_stage_f {
Subroutine update_stage_f: called CC=2 SCAR=7.0
Pod documented
323 3 my ( $self, $type, $uuid, $rep ) = @_;
324 3 my ( $path, $bad ) = $self->_stage_path($type);
325 3 ▶ return $bad || $self->_data_f( PATCH => $path.$self->_esc($uuid).'/', $rep );
Condition66%2/3
$bad || $self->_data_f('PATCH', $path . $self->_esc($uuid) . '/', $rep)
l!l&&r!l&&!r
120
MC/DC0%0/2
$bad || $self->_data_f('PATCH', $path . $self->_esc($uuid) . '/', $rep)
$bad $self->_data_f('PATCH', $path . $self->_esc($uuid) . '/', $rep)
Truth table66%2/3
A || B
A= $badB= $self->_data_f('PATCH', $path . $self->_esc($uuid) . '/', $rep)
ABresult
1X1
011
000
326 }
327  
328 1 ▶sub delete_stage_f {
Subroutine delete_stage_f: called CC=2 SCAR=7.6
Pod documented
329 1 my ( $self, $type, $uuid ) = @_;
330 1 my ( $path, $bad ) = $self->_stage_path($type);
331 1 ▶ return $bad || $self->_done_f( DELETE => $path.$self->_esc($uuid).'/' );
Condition33%1/3
$bad || $self->_done_f('DELETE', $path . $self->_esc($uuid) . '/')
l!l&&r!l&&!r
010
MC/DC0%0/2
$bad || $self->_done_f('DELETE', $path . $self->_esc($uuid) . '/')
$bad $self->_done_f('DELETE', $path . $self->_esc($uuid) . '/')
Truth table33%1/3
A || B
A= $badB= $self->_done_f('DELETE', $path . $self->_esc($uuid) . '/')
ABresult
1X1
011
000
332 }
333  
334  
335 #### flow stage bindings
336  
337 9 ▶async sub list_bindings_f {
Subroutine list_bindings_f: called CC=3 SCAR=11.0
Pod documented
338 9 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
339 9 ▶ return await $_[0]->fail_validation('list_bindings_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 8 9
340 8 my ( $self ) = @_;
341 8 my %q = %$pairs;
342 # authentik wants the flow's UUID in target and answers a slug with a field
343 # error, so flow => $slug is the readable way in
344 8 ▶ $q{target} = await $self->_flow_pk_f( delete $q{flow} ) if defined $q{flow};
Branch: 1 branch
BranchTrueFalseTotal
if defined $q{"flow"} 3 5 8
345 7 return await $self->_paged_f( '/flows/bindings/', %q );
346 8 }
347  
348 3 ▶async sub _flow_pk_f {
Subroutine _flow_pk_f: called CC=3 SCAR=11.0
349 3 my ( $self, $flow ) = @_;
350 3 ▶ return $flow if $flow =~ $self->uuid_pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $flow =~ $self->uuid_pattern 1 2 3
351 2 my $found = await $self->find_flow_f($flow);
352 2 ▶ die $self->validation_error_class->new( message => 'no flow "'.$flow.'"' ) unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 1 2
353 1 return $found->{pk};
354 8 }
355  
356 0 ▶sub get_binding_f { $_[0]->_data_f( GET => '/flows/bindings/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_binding_f: not called CC=1 SCAR=6.9
Pod documented
357 4 ▶sub create_binding_f { $_[0]->_data_f( POST => '/flows/bindings/', $_[1] ) }
Subroutine create_binding_f: called CC=1 SCAR=0.0
Pod documented
358 2 ▶sub update_binding_f { $_[0]->_data_f( PATCH => '/flows/bindings/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_binding_f: called CC=1 SCAR=0.0
Pod documented
359 1 ▶sub delete_binding_f { $_[0]->_done_f( DELETE => '/flows/bindings/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_binding_f: called CC=1 SCAR=0.0
Pod documented
360  
361  
362 #### brands, certificates, blueprints
363  
364 2 ▶sub list_brands_f { my ( $self, %q ) = @_; $self->_paged_f( '/core/brands/', %q ) }
Subroutine list_brands_f: called CC=1 SCAR=0.0
Pod documented
365 1 ▶sub current_brand_f { $_[0]->_data_f( GET => '/core/brands/current/' ) }
Subroutine current_brand_f: called CC=1 SCAR=0.0
Pod documented
366 1 ▶sub update_brand_f { $_[0]->_data_f( PATCH => '/core/brands/'.$_[0]->_esc( $_[1] ).'/', $_[2] ) }
Subroutine update_brand_f: called CC=1 SCAR=0.0
Pod documented
367  
368 7 ▶sub list_certificates_f { my ( $self, %q ) = @_; $self->_paged_f( '/crypto/certificatekeypairs/', %q ) }
Subroutine list_certificates_f: called CC=1 SCAR=0.0
Pod documented
369  
370 9 ▶async sub find_certificate_f {
Subroutine find_certificate_f: called CC=2 SCAR=6.9
Pod documented
371 9 my ( $self, $name ) = @_;
372 9 ▶ if ( my $bad = $self->_need( 'find_certificate: a name', $name ) ) { return await $bad }
Branch: 1 branch
BranchTrueFalseTotal
if (my $bad = $self->_need("find_certificate: a name", $name)) 2 7 9
373 7 return $self->_find_one( await( $self->list_certificates_f( name => $name ) ), 'name', $name );
374 8 }
375  
376 0 ▶sub list_blueprints_f { my ( $self, %q ) = @_; $self->_paged_f( '/managed/blueprints/', %q ) }
Subroutine list_blueprints_f: not called CC=1 SCAR=6.9
Pod documented
377 1 ▶sub get_blueprint_f { $_[0]->_data_f( GET => '/managed/blueprints/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine get_blueprint_f: called CC=1 SCAR=0.0
Pod documented
378 1 ▶sub create_blueprint_f { $_[0]->_data_f( POST => '/managed/blueprints/', $_[1] ) }
Subroutine create_blueprint_f: called CC=1 SCAR=0.0
Pod documented
379 1 ▶sub apply_blueprint_f { $_[0]->_data_f( POST => '/managed/blueprints/'.$_[0]->_esc( $_[1] ).'/apply/', {} ) }
Subroutine apply_blueprint_f: called CC=1 SCAR=0.0
Pod documented
380 1 ▶sub delete_blueprint_f { $_[0]->_done_f( DELETE => '/managed/blueprints/'.$_[0]->_esc( $_[1] ).'/' ) }
Subroutine delete_blueprint_f: called CC=1 SCAR=0.0
Pod documented
381  
382  
383 #### resolve
384  
385 72 ▶async sub resolve_f {
Subroutine resolve_f: called CC=18 SCAR=28.9
Pod documented
386 72 my ( $self, $rep ) = @_;
387 72 my %out = %$rep;
388 72 my $fields = $self->resolvable_fields;
389 72 ▶ if ( exists $out{scopes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $out{"scopes"}) 11 61 72
390 die $self->validation_error_class->new( message => 'give either scopes or property_mappings, not both' )
391 11 ▶ if exists $out{property_mappings} || exists $out{property_mapping_names};
Branch: 1 branch
BranchTrueFalseTotal
if exists $out{"property_mappings"} or exists $out{"property_mapping_names"} 1 10 11
Condition66%2/3
exists $out{"property_mappings"} or exists $out{"property_mapping_names"}
l!l&&r!l&&!r
1010
MC/DC50%1/2
exists $out{"property_mappings"} or exists $out{"property_mapping_names"}
exists $out{"property_mappings"} exists $out{"property_mapping_names"}
Truth table66%2/3
A or B
A= exists $out{"property_mappings"}B= exists $out{"property_mapping_names"}
ABresult
1X1
011
000
392 10 my $scopes = delete $out{scopes};
393 # an undef here is a mistake in the caller, and a costly one: taking it
394 # for an empty list would strip every mapping off the provider
395 10 ▶ die $self->validation_error_class->new( message => 'scopes is undef: give a list of scope names, '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scopes 2 8 10
396 .'or an empty list to take every mapping away' )
397 unless defined $scopes;
398 8 ▶ die $self->validation_error_class->new( message => 'scopes takes a list of scope names' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $scopes eq "ARRAY" 1 7 8
399 unless ref $scopes eq 'ARRAY';
400 7 $out{property_mappings} = [ map { $_->{pk} } @{ await $self->find_scope_mappings_by_scope_f(@$scopes) } ];
401 }
402 67 for my $field ( sort keys %$fields ) {
403 785 my $spec = $fields->{$field};
404 785 my $forced = exists $out{ $spec->{force} };
405 die $self->validation_error_class->new( message => 'give either '.$field.' or '.$spec->{force}.', not both' )
406 785 ▶ if $forced && exists $out{$field};
Branch: 1 branch
BranchTrueFalseTotal
if $forced and exists $out{$field} 1 784 785
Condition100%3/3
$forced and exists $out{$field}
!ll&&!rl&&r
759251
MC/DC100%2/2
$forced and exists $out{$field}
$forced exists $out{$field}
Truth table100%3/3
A and B
A= $forcedB= exists $out{$field}
ABresult
0X0
100
111
407 784 ▶ next unless $forced || exists $out{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless $forced or exists $out{$field} 737 47 784
Condition100%3/3
$forced or exists $out{$field}
l!l&&r!l&&!r
2522737
MC/DC100%2/2
$forced or exists $out{$field}
$forced exists $out{$field}
Truth table100%3/3
A or B
A= $forcedB= exists $out{$field}
ABresult
1X1
011
000
408 47 ▶ my $value = $forced ? delete $out{ $spec->{force} } : $out{$field};
Branch: 1 branch
BranchTrueFalseTotal
$forced ? : 25 22 47
409 # the forced form says "look this name up", so an undef there is a
410 # mistake, not a wish to leave the field alone
411 47 ▶ die $self->validation_error_class->new( message => $spec->{force}.' is undef: give a name to look up, '
Branch: 1 branch
BranchTrueFalseTotal
if $forced and not defined $value 1 46 47
Condition100%3/3
$forced and not defined $value
!ll&&!rl&&r
22241
MC/DC100%2/2
$forced and not defined $value
$forced not defined $value
Truth table100%3/3
A and not(B)
A= $forcedB= not defined $value
ABresult
0X0
100
111
412 .'or '.$field.' to set the identifier itself' )
413 if $forced && !defined $value;
414 46 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 44 46
415 44 ▶ if ( $spec->{list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'list'}) { } 16 28 44
416 # a for loop with a lexical, not a statement modifier: await needs one
417 16 my @resolved;
418 16 ▶ for my $one ( @{ ref $value eq 'ARRAY' ? $value : [$value] } ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 16 0 16
419 22 push @resolved, await $self->_resolve_one_f( $field, $spec, $one, $forced );
420 }
421 15 $out{$field} = \@resolved;
422 }
423 else {
424 28 $out{$field} = await $self->_resolve_one_f( $field, $spec, $value, $forced );
425 }
426 }
427 61 return \%out;
428 8 }
429  
430 50 ▶async sub _resolve_one_f {
Subroutine _resolve_one_f: called CC=5 SCAR=16.1
431 50 my ( $self, $field, $spec, $value, $forced ) = @_;
432 die $self->validation_error_class->new( message => 'cannot set '.$field.': expected '.$spec->{what}
433 50 ▶ .' as a name or an identifier, got a '.lc( ref $value ).' reference' )
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 1 49 50
434 if ref $value;
435 49 ▶ return $value if !$forced && $value =~ $spec->{raw};
Branch: 1 branch
BranchTrueFalseTotal
if not $forced and $value =~ /$spec->{"raw"}/ 20 29 49
Condition100%3/3
not $forced and $value =~ /$spec->{"raw"}/
!ll&&!rl&&r
24520
MC/DC100%2/2
not $forced and $value =~ /$spec->{"raw"}/
not $forced $value =~ /$spec->{"raw"}/
Truth table100%3/3
not(A) and B
A= not $forcedB= $value =~ /$spec->{"raw"}/
ABresult
0X0
100
111
436 29 my $find = $spec->{find}.'_f';
437 29 my $found = await $self->$find($value);
438 29 ▶ die $self->validation_error_class->new( message => 'cannot set '.$field.': no '.$spec->{what}.' named "'.$value.'"' )
Branch: 1 branch
BranchTrueFalseTotal
unless $found 3 26 29
439 unless $found;
440 26 return $found->{pk};
441 8 }
442  
443  
444 #### ensure
445  
446 41 ▶async sub _ensure_f {
Subroutine _ensure_f: called CC=4 SCAR=13.9
447 41 my ( $self, %arg ) = @_;
448 41 my $current = await $arg{find}->();
449 40 ▶ unless ($current) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current) 17 23 40
450 17 my $object = await $arg{create}->();
451 15 ▶ await $arg{after_create}->($object) if $arg{after_create};
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"after_create"} 4 11 15
452 15 return { object => $object, changed => 'created' };
453 }
454 23 my $changes = $self->diff_class->changes( $current, $arg{wanted} );
455 23 ▶ return { object => $current, changed => '' } unless %$changes;
Branch: 1 branch
BranchTrueFalseTotal
unless %$changes 15 8 23
456 8 return { object => await $arg{update}->( $current, $changes ), changed => 'updated' };
457 8 }
458  
459 9 ▶async sub ensure_user_f {
Subroutine ensure_user_f: called CC=3 SCAR=11.0
Pod documented
460 9 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
461 9 ▶ return await $_[0]->fail_validation('ensure_user_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 8 9
462 8 my ( $self ) = @_;
463 8 my %rep = %$pairs;
464 8 ▶ return await $self->fail_validation('ensure_user needs a username') unless defined $rep{username};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"username"} 2 6 8
465 6 my $wanted = await $self->resolve_f( \%rep );
466 6 my $password = delete $wanted->{password};
467 return await $self->_ensure_f(
468 wanted => $wanted,
469 6 ▶ find => sub { $self->find_user_f( $rep{username} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
470 2 ▶ create => sub { $self->create_user_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
471 # a password is set when the user is created and never again, so running
472 # a setup twice does not reset it; call set_password_f to change one
473 2 ▶ after_create => sub { defined $password ? $self->set_password_f( $_[0]{pk}, $password ) : Future->done },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $password ? : 1 1 2
474 1 ▶ update => sub { $self->update_user_f( $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
475 6 );
476 8 }
477  
478 9 ▶async sub ensure_group_f {
Subroutine ensure_group_f: called CC=3 SCAR=11.0
Pod documented
479 9 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
480 9 ▶ return await $_[0]->fail_validation('ensure_group_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 9 9
481 9 my ( $self ) = @_;
482 9 my %rep = %$pairs;
483 9 ▶ return await $self->fail_validation('ensure_group needs a name') unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 1 8 9
484 8 my $wanted = await $self->resolve_f( \%rep );
485 return await $self->_ensure_f(
486 wanted => $wanted,
487 8 ▶ find => sub { $self->find_group_f( $rep{name} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
488 3 ▶ create => sub { $self->create_group_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
489 1 ▶ update => sub { $self->update_group_f( $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
490 8 );
491 8 }
492  
493 7 ▶async sub ensure_token_f {
Subroutine ensure_token_f: called CC=4 SCAR=13.9
Pod documented
494 7 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
495 7 ▶ return await $_[0]->fail_validation('ensure_token_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 7 7
496 7 my ( $self ) = @_;
497 7 my %rep = %$pairs;
498 7 ▶ return await $self->fail_validation('ensure_token needs an identifier') unless defined $rep{identifier};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"identifier"} 1 6 7
499 # authentik ignores expires and sets it from default_token_duration, so a
500 # wanted value could never be reached and would report updated for ever
501 return await $self->fail_validation( 'ensure_token cannot set expires: authentik ignores it and '
502 .'sets the expiry from the instance setting default_token_duration. Use expiring to say whether it expires at all.' )
503 6 ▶ if exists $rep{expires};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rep{"expires"} 2 4 6
504 4 my $wanted = await $self->resolve_f( \%rep );
505 4 my $key = delete $wanted->{key};
506 return await $self->_ensure_f(
507 wanted => $wanted,
508 4 ▶ find => sub { $self->find_token_f( $rep{identifier} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
509 2 ▶ create => sub { $self->create_token_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
510 # like a password: the key is put on the token when it is created
511 2 ▶ after_create => sub { defined $key ? $self->set_token_key_f( $rep{identifier}, $key ) : Future->done },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 1 1 2
512 0 ▶ update => sub { $self->update_token_f( $rep{identifier}, $_[1] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
513 4 );
514 8 }
515  
516 4 ▶async sub ensure_application_f {
Subroutine ensure_application_f: called CC=3 SCAR=11.0
Pod documented
517 4 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
518 4 ▶ return await $_[0]->fail_validation('ensure_application_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 4 4
519 4 my ( $self ) = @_;
520 4 my %rep = %$pairs;
521 4 ▶ return await $self->fail_validation('ensure_application needs a slug') unless defined $rep{slug};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"slug"} 1 3 4
522 3 my $wanted = await $self->resolve_f( \%rep );
523 return await $self->_ensure_f(
524 wanted => $wanted,
525 3 ▶ find => sub { $self->find_application_f( $rep{slug} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
526 1 ▶ create => sub { $self->create_application_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
527 1 ▶ update => sub { $self->update_application_f( $rep{slug}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
528 3 );
529 8 }
530  
531 5 ▶async sub ensure_oauth2_provider_f {
Subroutine ensure_oauth2_provider_f: called CC=3 SCAR=11.1
Pod documented
532 5 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
533 5 ▶ return await $_[0]->fail_validation('ensure_oauth2_provider_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 5 5
534 5 my ( $self ) = @_;
535 5 my %rep = %$pairs;
536 5 ▶ return await $self->fail_validation('ensure_oauth2_provider needs a name') unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 0 5 5
537 5 my $wanted = await $self->resolve_f( \%rep );
538 return await $self->_ensure_f(
539 wanted => $wanted,
540 5 ▶ find => sub { $self->find_oauth2_provider_f( $rep{name} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
541 2 ▶ create => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
542 # authentik defaults grant_types to an empty list, and a provider with
543 # an empty list answers every token request with invalid_grant. Which
544 # grants were meant is not something this client guesses.
545 return $self->fail_validation( 'ensure_oauth2_provider needs grant_types to create a provider: '
546 .'authentik would store an empty list, and such a provider answers every token request with invalid_grant' )
547 2 ▶ unless ref $wanted->{grant_types} eq 'ARRAY' && @{ $wanted->{grant_types} };
Branch: 1 branch
BranchTrueFalseTotal
unless ref $wanted->{"grant_types"} eq "ARRAY" and @{$wanted->{"grant_types"};} 1 1 2
Condition66%2/3
ref $wanted->{"grant_types"} eq "ARRAY" and @{$wanted->{"grant_types"};}
!ll&&!rl&&r
101
MC/DC50%1/2
ref $wanted->{"grant_types"} eq "ARRAY" and @{$wanted->{"grant_types"};}
ref $wanted->{"grant_types"} eq "ARRAY" @{$wanted->{"grant_types"};}
Truth table66%2/3
A and B
A= ref $wanted->{"grant_types"} eq "ARRAY"B= @{$wanted->{"grant_types"};}
ABresult
0X0
100
111
548 1 return $self->create_oauth2_provider_f($wanted);
549 },
550 2 ▶ update => sub { $self->update_oauth2_provider_f( $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
551 5 );
552 8 }
553  
554 2 ▶async sub ensure_scope_mapping_f {
Subroutine ensure_scope_mapping_f: called CC=3 SCAR=11.2
Pod documented
555 2 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
556 2 ▶ return await $_[0]->fail_validation('ensure_scope_mapping_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
557 2 my ( $self ) = @_;
558 2 my %rep = %$pairs;
559 2 ▶ return await $self->fail_validation('ensure_scope_mapping needs a name') unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 0 2 2
560 2 my $wanted = await $self->resolve_f( \%rep );
561 return await $self->_ensure_f(
562 wanted => $wanted,
563 2 ▶ find => sub { $self->find_scope_mapping_f( $rep{name} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
564 1 ▶ create => sub { $self->create_scope_mapping_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
565 0 ▶ update => sub { $self->update_scope_mapping_f( $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
566 2 );
567 8 }
568  
569 3 ▶async sub ensure_flow_f {
Subroutine ensure_flow_f: called CC=3 SCAR=11.1
Pod documented
570 3 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
571 3 ▶ return await $_[0]->fail_validation('ensure_flow_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 3 3
572 3 my ( $self ) = @_;
573 3 my %rep = %$pairs;
574 3 ▶ return await $self->fail_validation('ensure_flow needs a slug') unless defined $rep{slug};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"slug"} 0 3 3
575 3 my $wanted = await $self->resolve_f( \%rep );
576 return await $self->_ensure_f(
577 wanted => $wanted,
578 3 ▶ find => sub { $self->find_flow_f( $rep{slug} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
579 1 ▶ create => sub { $self->create_flow_f($wanted) },
Subroutine __ANON__: called CC=1 SCAR=0.0
580 1 ▶ update => sub { $self->update_flow_f( $rep{slug}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
581 3 );
582 8 }
583  
584 11 ▶async sub ensure_stage_f {
Subroutine ensure_stage_f: called CC=4 SCAR=14.0
Pod documented
585 11 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 2, @_ );
586 11 ▶ return await $_[0]->fail_validation('ensure_stage_f: the arguments after the first 1 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 10 11
587 10 my ( $self, $type ) = @_;
588 10 my %rep = %$pairs;
589 10 ▶ return await $self->fail_validation('ensure_stage needs a name') unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 1 9 10
590 9 my ( $path, $bad ) = $self->_stage_path($type);
591 9 ▶ return await $bad if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 2 7 9
592 7 my $wanted = await $self->resolve_f( \%rep );
593 return await $self->_ensure_f(
594 wanted => $wanted,
595 7 ▶ find => sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
596 7 ▶ my $find = async sub {
Subroutine __ANON__: called CC=7 SCAR=20.6
597 7 my $stage = await $self->find_stage_f( $rep{name} );
598 7 ▶ return undef unless $stage;
Branch: 1 branch
BranchTrueFalseTotal
unless $stage 4 3 7
599 # a stage name is unique across all types, so a name that belongs to
600 # another type is a clash, not something to create or update
601 3 my $whole = eval { await $self->get_stage_f( $type, $stage->{pk} ) };
602 3 my $error = $@;
603 3 ▶ return $whole if $whole;
Branch: 1 branch
BranchTrueFalseTotal
if $whole 2 1 3
604 1 ▶ die $error unless blessed $error && $error->isa('WWW::Authentik::Error::API') && $error->is_not_found;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($error) and $error->isa("WWW::Authentik::Error::API") and $error->is_not_found 0 1 1
Condition33%2/6
builtin::blessed($error) and $error->isa("WWW::Authentik::Error::API") and $error->is_not_found
!ll&&!rl&&r
001
builtin::blessed($error) and $error->isa("WWW::Authentik::Error::API")
!ll&&!rl&&r
001
MC/DC0%0/3
builtin::blessed($error) and $error->isa("WWW::Authentik::Error::API") and $error->is_not_found
builtin::blessed($error) $error->isa("WWW::Authentik::Error::API") $error->is_not_found
Truth table25%1/4
A and B and C
A= builtin::blessed($error)B= $error->isa("WWW::Authentik::Error::API")C= $error->is_not_found
ABCresult
0XX0
10X0
1100
1111
605 die $self->validation_error_class->new( message => 'ensure_stage: there already is a stage named "'
606 1 ▶ .$rep{name}.'", but not of the type '.$type.' ('.( $stage->{component} // 'unknown component' ).'). '
Condition50%1/2
$stage->{"component"} // "unknown component"
l!l
01
MC/DC0%0/1
$stage->{"component"} // "unknown component"
$stage->{"component"}
Truth table50%1/2
A
A= $stage->{"component"}
Aresult
11
00
607 .'Stage names are unique across all types in authentik.' );
608 7 };
609 7 return $find->();
610 },
611 4 ▶ create => sub { $self->create_stage_f( $type, $wanted ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
612 1 ▶ update => sub { $self->update_stage_f( $type, $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
613 7 );
614 8 }
615  
616 9 ▶async sub ensure_binding_f {
Subroutine ensure_binding_f: called CC=8 SCAR=20.8
Pod documented
617 9 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
618 9 ▶ return await $_[0]->fail_validation('ensure_binding_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 8 9
619 8 my ( $self ) = @_;
620 8 my %arg = %$pairs;
621 8 for my $needed (qw( flow stage order )) {
622 24 ▶ return await $self->fail_validation( 'ensure_binding needs '.$needed ) unless defined $arg{$needed};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{$needed} 2 22 24
623 }
624 6 my %wanted = %arg;
625 # only "there is no such flow" becomes a validation error here; a refused
626 # request or a 500 has to stay what it is instead of being reported as a
627 # missing flow
628 6 my $flow = delete $wanted{flow};
629 6 ▶ unless ( $flow =~ $self->uuid_pattern ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flow =~ $self->uuid_pattern) 6 0 6
630 6 my $found = await $self->find_flow_f($flow);
631 5 ▶ return await $self->fail_validation( 'ensure_binding: no flow "'.$flow.'"' ) unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 4 5
632 4 $flow = $found->{pk};
633 }
634 4 my $stage = $wanted{stage};
635 4 ▶ unless ( $stage =~ $self->uuid_pattern ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stage =~ $self->uuid_pattern) 4 0 4
636 4 my $found = await $self->find_stage_f($stage);
637 4 ▶ return await $self->fail_validation( 'ensure_binding: no stage "'.$stage.'"' ) unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 3 4
638 3 $stage = $found->{pk};
639 }
640 3 @wanted{qw( target stage )} = ( $flow, $stage );
641 return await $self->_ensure_f(
642 wanted => \%wanted,
643 # a flow binds a stage at most once here; the order is what ensure moves
644 3 ▶ find => async sub { $self->_find_one( await( $self->list_bindings_f( target => $flow, stage => $stage ) ), 'stage', $stage ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
645 1 ▶ create => sub { $self->create_binding_f( \%wanted ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
646 1 ▶ update => sub { $self->update_binding_f( $_[0]{pk}, $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
647 3 );
648 8 }
649  
650  
651 8 1;
652  
653 __END__
« Authentik/OIDC.pm ↑ Summary Authentik.pm »