Keycloak/Admin.pm

filter: Statementstmt 97.1% 239 / 246 Branchbran 85.0% 51 / 60 Conditioncond 66.6% 26 / 39 MC/DCmcdc 45.0% 9 / 20 Subroutinesub 94.8% 92 / 97 Podpod 96.3% 53 / 55 totaltotal 90.9% 470 / 517 CC 49 SCAR 11.2
CC
49
Cov
92%
export_realm_f
12.0
call_f
9.1
ensure_protocol_mapper_f
7.1
CRAP 3.1
« Keycloak/OIDC.pm ↑ Summary Keycloak.pm »
1 package Net::Async::Keycloak::Admin;
2  
3 # ABSTRACT: Keycloak Admin REST API for one realm, asynchronously, with idempotent ensure methods
4  
5 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 with 'Net::Async::Keycloak::Role::HTTP';
7 7 with 'WWW::Keycloak::Role::HTTP';
8 7 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Types::Standard qw( InstanceOf Object Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Net::Async::Keycloak::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use URI::Escape qw( uri_escape_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use WWW::Keycloak::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 our $VERSION = '0.001';
18  
19  
20 7 has base_url => ( is => 'ro', isa => Str, required => 1 );
21 7 has realm => ( is => 'ro', isa => Str, required => 1 );
22 7 has http => ( is => 'ro', isa => Object, required => 1 );
23 7 has auth => ( is => 'ro', isa => InstanceOf['Net::Async::Keycloak::Auth'], predicate => 'has_auth' );
24  
25  
26 18 ▶sub diff_class { 'WWW::Keycloak::Diff' }
Subroutine diff_class: called CC=1 SCAR=0.0
Pod undocumented
27  
28 #### transport
29  
30 123 ▶sub realm_url { $_[0]->base_url.'/admin/realms/'.uri_escape_utf8( $_[0]->realm ) }
Subroutine realm_url: called CC=1 SCAR=0.0
Pod undocumented
31  
32 128 ▶async sub call_f {
Subroutine call_f: called CC=9 SCAR=22.0
Pod documented
33 128 my ( $self, $method, $path, $body ) = @_;
34 128 ▶ my $url = $path =~ m{\A/admin/} ? $self->base_url.$path : $self->realm_url.$path;
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[\A/admin/] ? : 5 123 128
35 128 ▶ $self->validation_error_class->throw( message => 'the Admin API needs credentials: give username and password, client_id and client_secret, or token' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_auth 1 127 128
36 unless $self->has_auth;
37 127 ▶ my %arg = defined $body ? ( json => $body ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 38 89 127
38 127 my $bearer = await $self->auth->token_f; # outside the eval: a failed login is not a refused token
39 125 my $result = eval { await $self->send_request_f( $method, $url, %arg, bearer => $bearer ) };
40 125 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 11 114 125
41 11 ▶ die $error unless blessed $error && $error->isa('WWW::Keycloak::Error::API') && $error->is_unauthorized && $self->auth->renewable;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable 6 5 11
Condition66%6/9
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable
!ll&&!rl&&r
515
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized
!ll&&!rl&&r
056
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API")
!ll&&!rl&&r
0011
MC/DC50%2/4
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable
builtin::blessed($error) $error->isa("WWW::Keycloak::Error::API") $error->is_unauthorized $self->auth->renewable
Truth table60%3/5
A and B and C and D
A= builtin::blessed($error)B= $error->isa("WWW::Keycloak::Error::API")C= $error->is_unauthorizedD= $self->auth->renewable
ABCDresult
0XXX0
10XX0
110X0
11100
11111
42 5 $self->auth->invalidate($bearer);
43 5 $result = await $self->send_request_f( $method, $url, %arg, bearer => await( $self->auth->token_f ) );
44 }
45 118 return $result;
46 7 }
47  
48  
49 83 ▶async sub _data_f { return ( await $_[0]->call_f( @_[ 1 .. $#_ ] ) )->{data} }
Subroutine _data_f: called CC=1 SCAR=0.0
50 21 ▶async sub _done_f { await $_[0]->call_f( @_[ 1 .. $#_ ] ); return 1 }
Subroutine _done_f: called CC=1 SCAR=0.0
51  
52 19 ▶async sub _create_f {
Subroutine _create_f: called CC=3 SCAR=11.0
53 19 my ( $self, $path, $body ) = @_;
54 19 ▶ my $location = ( await $self->call_f( POST => $path, $body ) )->{location} // '';
Condition100%2/2
<custom op await>->{"location"} // ""
l!l
171
MC/DC100%1/1
<custom op await>->{"location"} // ""
<custom op await>->{"location"}
Truth table100%2/2
A
A= <custom op await>->{"location"}
Aresult
11
00
55 18 my ( $id ) = $location =~ m{/([^/]+)\z};
56 18 ▶ Net::Async::Keycloak::Error->throw( message => 'POST '.$path.' created something but sent no Location header' ) unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 1 17 18
57 17 return $id;
58 7 }
59  
60 124 ▶sub _esc { uri_escape_utf8( $_[1] ) }
Subroutine _esc: called CC=1 SCAR=0.0
61  
62 25 ▶sub _query {
Subroutine _query: called CC=2 SCAR=6.9
63 25 my ( $self, %query ) = @_;
64 25 ▶ return '' unless %query;
Branch: 1 branch
BranchTrueFalseTotal
unless %query 3 22 25
65 22 return '?'.join '&', map { $self->_esc($_).'='.$self->_esc( $query{$_} ) } sort keys %query;
66 }
67  
68 #### server and realm
69  
70 1 ▶sub server_info_f { $_[0]->_data_f( GET => '/admin/serverinfo' ) }
Subroutine server_info_f: called CC=1 SCAR=0.0
Pod documented
71 21 ▶sub get_realm_f { $_[0]->_data_f( GET => '' ) }
Subroutine get_realm_f: called CC=1 SCAR=0.0
Pod documented
72 2 ▶sub update_realm_f { $_[0]->_done_f( PUT => '', $_[1] ) }
Subroutine update_realm_f: called CC=1 SCAR=0.0
Pod documented
73 0 ▶sub delete_realm_f { $_[0]->_done_f( DELETE => '' ) }
Subroutine delete_realm_f: not called CC=1 SCAR=6.9
Pod documented
74  
75 4 ▶async sub create_realm_f {
Subroutine create_realm_f: called CC=2 SCAR=6.9
Pod documented
76 4 my ( $self, $rep ) = @_;
77 4 ▶ await $self->call_f( POST => '/admin/realms', { realm => $self->realm, %{ $rep || {} } } );
Condition100%2/2
$rep || {}
l!l
31
MC/DC100%1/1
$rep || {}
$rep
Truth table100%2/2
A
A= $rep
Aresult
11
00
78 3 return $self->realm;
79 7 }
80  
81 0 ▶sub export_realm_f {
Subroutine export_realm_f: not called CC=3 SCAR=24.8
Pod documented
82 0 my ( $self, %opt ) = @_;
83 return $self->_data_f( POST => '/partial-export'.$self->_query(
84 exportClients => $opt{clients} ? 'true' : 'false',
85 0 ▶ exportGroupsAndRoles => $opt{groups_and_roles} ? 'true' : 'false'
Branch: 2 branches
BranchTrueFalseTotal
$opt{'clients'} ? : 0 0 0
$opt{'groups_and_roles'} ? : 0 0 0
86 ) );
87 }
88  
89 2 ▶sub partial_import_f {
Subroutine partial_import_f: called CC=3 SCAR=11.1
Pod documented
90 2 my ( $self, $rep, %opt ) = @_;
91 2 ▶ return $self->fail_validation('partial_import needs a representation') unless ref $rep eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rep eq "HASH" 1 1 2
92 1 ▶ return $self->_data_f( POST => '/partialImport', { ifResourceExists => $opt{if_exists} // 'FAIL', %$rep } );
Condition50%1/2
$opt{"if_exists"} // "FAIL"
l!l
10
MC/DC0%0/1
$opt{"if_exists"} // "FAIL"
$opt{"if_exists"}
Truth table50%1/2
A
A= $opt{"if_exists"}
Aresult
11
00
93 }
94  
95 #### clients
96  
97 14 ▶sub list_clients_f { my ( $self, %q ) = @_; $self->_data_f( GET => '/clients'.$self->_query(%q) ) }
Subroutine list_clients_f: called CC=1 SCAR=0.0
Pod documented
98 5 ▶sub get_client_f { $_[0]->_data_f( GET => '/clients/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_client_f: called CC=1 SCAR=0.0
Pod documented
99 6 ▶sub create_client_f { $_[0]->_create_f( '/clients', $_[1] ) }
Subroutine create_client_f: called CC=1 SCAR=0.0
Pod documented
100 2 ▶sub update_client_f { $_[0]->_done_f( PUT => '/clients/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_client_f: called CC=1 SCAR=0.0
Pod documented
101 1 ▶sub delete_client_f { $_[0]->_done_f( DELETE => '/clients/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_client_f: called CC=1 SCAR=0.0
Pod documented
102  
103 12 ▶async sub find_client_f {
Subroutine find_client_f: called CC=1 SCAR=0.0
Pod documented
104 12 my ( $self, $client_id ) = @_;
105 12 my ( $client ) = grep { $_->{clientId} eq $client_id } @{ await $self->list_clients_f( clientId => $client_id ) };
106 12 return $client;
107 7 }
108  
109 1 ▶sub get_client_secret_f { $_[0]->_data_f( GET => '/clients/'.$_[0]->_esc( $_[1] ).'/client-secret' ) }
Subroutine get_client_secret_f: called CC=1 SCAR=0.0
Pod documented
110 0 ▶sub regenerate_client_secret_f { $_[0]->_data_f( POST => '/clients/'.$_[0]->_esc( $_[1] ).'/client-secret' ) }
Subroutine regenerate_client_secret_f: not called CC=1 SCAR=6.9
Pod documented
111 1 ▶sub get_service_account_user_f { $_[0]->_data_f( GET => '/clients/'.$_[0]->_esc( $_[1] ).'/service-account-user' ) }
Subroutine get_service_account_user_f: called CC=1 SCAR=0.0
Pod documented
112  
113 #### client scopes
114  
115 6 ▶sub list_client_scopes_f { $_[0]->_data_f( GET => '/client-scopes' ) }
Subroutine list_client_scopes_f: called CC=1 SCAR=0.0
Pod documented
116 0 ▶sub get_client_scope_f { $_[0]->_data_f( GET => '/client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_client_scope_f: not called CC=1 SCAR=6.9
Pod documented
117 2 ▶sub create_client_scope_f { $_[0]->_create_f( '/client-scopes', $_[1] ) }
Subroutine create_client_scope_f: called CC=1 SCAR=0.0
Pod documented
118 1 ▶sub update_client_scope_f { $_[0]->_done_f( PUT => '/client-scopes/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_client_scope_f: called CC=1 SCAR=0.0
Pod documented
119 0 ▶sub delete_client_scope_f { $_[0]->_done_f( DELETE => '/client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_client_scope_f: not called CC=1 SCAR=6.9
Pod documented
120  
121 6 ▶async sub find_client_scope_f {
Subroutine find_client_scope_f: called CC=1 SCAR=0.0
Pod documented
122 6 my ( $self, $name ) = @_;
123 6 my ( $scope ) = grep { $_->{name} eq $name } @{ await $self->list_client_scopes_f };
124 6 return $scope;
125 7 }
126  
127 1 ▶sub add_default_client_scope_f {
Subroutine add_default_client_scope_f: called CC=1 SCAR=0.0
Pod documented
128 1 my ( $self, $client, $scope ) = @_;
129 1 return $self->_done_f( PUT => '/clients/'.$self->_esc($client).'/default-client-scopes/'.$self->_esc($scope) );
130 }
131  
132 1 ▶sub add_realm_default_client_scope_f { $_[0]->_done_f( PUT => '/default-default-client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine add_realm_default_client_scope_f: called CC=1 SCAR=0.0
Pod documented
133  
134 #### protocol mappers
135  
136 14 ▶sub _mapper_path {
Subroutine _mapper_path: called CC=6 SCAR=18.1
137 14 my ( $self, $kind, $owner ) = @_;
138 14 ▶ $self->validation_error_class->throw( message => 'protocol mappers belong to a client or a client_scope, not to '.( $kind // 'nothing' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kind and $kind eq "client" || $kind eq "client_scope" 1 13 14
Condition75%6/8
defined $kind and $kind eq "client" || $kind eq "client_scope"
!ll&&!rl&&r
0113
$kind eq "client" or $kind eq "client_scope"
l!l&&r!l&&!r
1031
$kind // "nothing"
l!l
10
MC/DC66%2/3
defined $kind and $kind eq "client" || $kind eq "client_scope"
defined $kind $kind eq "client" $kind eq "client_scope"
MC/DC0%0/1
$kind // "nothing"
$kind
Truth table75%3/4
A and B or C
A= defined $kindB= $kind eq "client"C= $kind eq "client_scope"
ABCresult
0XX0
1000
11X1
1011
Truth table50%1/2
A
A= $kind
Aresult
11
00
139 unless defined $kind && ( $kind eq 'client' || $kind eq 'client_scope' );
140 13 ▶ return ( $kind eq 'client' ? '/clients/' : '/client-scopes/' ).$self->_esc($owner).'/protocol-mappers/models';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'client' ? : 10 3 13
141 }
142  
143 7 ▶async sub list_protocol_mappers_f { my ( $self, $kind, $owner ) = @_; return await $self->_data_f( GET => $self->_mapper_path( $kind, $owner ) ) }
Subroutine list_protocol_mappers_f: called CC=1 SCAR=0.0
Pod documented
144 4 ▶async sub create_protocol_mapper_f { my ( $self, $kind, $owner, $rep ) = @_; return await $self->_create_f( $self->_mapper_path( $kind, $owner ), $rep ) }
Subroutine create_protocol_mapper_f: called CC=1 SCAR=0.0
Pod documented
145  
146 2 ▶async sub update_protocol_mapper_f {
Subroutine update_protocol_mapper_f: called CC=1 SCAR=0.0
Pod documented
147 2 my ( $self, $kind, $owner, $id, $rep ) = @_;
148 2 return await $self->_done_f( PUT => $self->_mapper_path( $kind, $owner ).'/'.$self->_esc($id), $rep );
149 7 }
150  
151 1 ▶async sub delete_protocol_mapper_f {
Subroutine delete_protocol_mapper_f: called CC=1 SCAR=0.0
Pod documented
152 1 my ( $self, $kind, $owner, $id ) = @_;
153 1 return await $self->_done_f( DELETE => $self->_mapper_path( $kind, $owner ).'/'.$self->_esc($id) );
154 7 }
155  
156 #### users
157  
158 11 ▶sub list_users_f { my ( $self, %q ) = @_; $self->_data_f( GET => '/users'.$self->_query(%q) ) }
Subroutine list_users_f: called CC=1 SCAR=0.0
Pod documented
159 1 ▶sub get_user_f { $_[0]->_data_f( GET => '/users/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_user_f: called CC=1 SCAR=0.0
Pod documented
160 3 ▶sub create_user_f { $_[0]->_create_f( '/users', $_[1] ) }
Subroutine create_user_f: called CC=1 SCAR=0.0
Pod documented
161 3 ▶sub update_user_f { $_[0]->_done_f( PUT => '/users/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_user_f: called CC=1 SCAR=0.0
Pod documented
162 1 ▶sub delete_user_f { $_[0]->_done_f( DELETE => '/users/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_user_f: called CC=1 SCAR=0.0
Pod documented
163  
164 10 ▶async sub find_user_f {
Subroutine find_user_f: called CC=1 SCAR=0.0
Pod documented
165 10 my ( $self, $username ) = @_;
166 10 my ( $user ) = grep { lc $_->{username} eq lc $username } @{ await $self->list_users_f( username => $username, exact => 'true' ) };
167 10 return $user;
168 7 }
169  
170 1 ▶sub set_password_f {
Subroutine set_password_f: called CC=2 SCAR=7.2
Pod documented
171 1 my ( $self, $id, $password, %opt ) = @_;
172 return $self->_done_f( PUT => '/users/'.$self->_esc($id).'/reset-password',
173 1 ▶ { type => 'password', value => $password, temporary => $opt{temporary} ? \1 : \0 } );
Branch: 1 branch
BranchTrueFalseTotal
$opt{'temporary'} ? : 1 0 1
174 }
175  
176 2 ▶sub list_credentials_f { $_[0]->_data_f( GET => '/users/'.$_[0]->_esc( $_[1] ).'/credentials' ) }
Subroutine list_credentials_f: called CC=1 SCAR=0.0
Pod documented
177 1 ▶sub delete_credential_f { $_[0]->_done_f( DELETE => '/users/'.$_[0]->_esc( $_[1] ).'/credentials/'.$_[0]->_esc( $_[2] ) ) }
Subroutine delete_credential_f: called CC=1 SCAR=0.0
Pod documented
178 1 ▶sub list_sessions_f { $_[0]->_data_f( GET => '/users/'.$_[0]->_esc( $_[1] ).'/sessions' ) }
Subroutine list_sessions_f: called CC=1 SCAR=0.0
Pod documented
179 1 ▶sub logout_user_f { $_[0]->_done_f( POST => '/users/'.$_[0]->_esc( $_[1] ).'/logout' ) }
Subroutine logout_user_f: called CC=1 SCAR=0.0
Pod documented
180  
181 #### authentication
182  
183 1 ▶sub list_flows_f { $_[0]->_data_f( GET => '/authentication/flows' ) }
Subroutine list_flows_f: called CC=1 SCAR=0.0
Pod documented
184 7 ▶sub list_executions_f { $_[0]->_data_f( GET => '/authentication/flows/'.$_[0]->_esc( $_[1] ).'/executions' ) }
Subroutine list_executions_f: called CC=1 SCAR=0.0
Pod documented
185 1 ▶sub copy_flow_f { $_[0]->_create_f( '/authentication/flows/'.$_[0]->_esc( $_[1] ).'/copy', { newName => $_[2] } ) }
Subroutine copy_flow_f: called CC=1 SCAR=0.0
Pod documented
186 3 ▶sub get_execution_config_f { $_[0]->_data_f( GET => '/authentication/config/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_execution_config_f: called CC=1 SCAR=0.0
Pod documented
187 3 ▶sub create_execution_config_f { $_[0]->_create_f( '/authentication/executions/'.$_[0]->_esc( $_[1] ).'/config', $_[2] ) }
Subroutine create_execution_config_f: called CC=1 SCAR=0.0
Pod documented
188 4 ▶sub update_execution_config_f {
Subroutine update_execution_config_f: called CC=2 SCAR=6.9
Pod documented
189 4 my ( $self, $id, $rep ) = @_;
190 4 ▶ return $self->fail_validation('update_execution_config needs a representation') unless ref $rep eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rep eq "HASH" 1 3 4
191 3 return $self->_done_f( PUT => '/authentication/config/'.$self->_esc($id), { %$rep, id => $id } );
192 }
193 1 ▶sub describe_authenticator_f { $_[0]->_data_f( GET => '/authentication/config-description/'.$_[0]->_esc( $_[1] ) ) }
Subroutine describe_authenticator_f: called CC=1 SCAR=0.0
Pod documented
194  
195  
196 #### ensure
197  
198 26 ▶async sub _ensure_f {
Subroutine _ensure_f: called CC=3 SCAR=11.0
199 26 my ( $self, %arg ) = @_;
200 26 my $current = await $arg{find}->();
201 26 ▶ return { id => await( $arg{create}->() ), changed => 'created' } unless $current;
Branch: 1 branch
BranchTrueFalseTotal
unless $current 10 16 26
202 16 my $changes = $self->diff_class->changes( $current, $arg{wanted} );
203 16 ▶ return { id => $arg{id}->($current), changed => '' } unless %$changes;
Branch: 1 branch
BranchTrueFalseTotal
unless %$changes 8 8 16
204 8 await $arg{update}->( $current, $changes );
205 8 return { id => $arg{id}->($current), changed => 'updated' };
206 7 }
207  
208 3 ▶sub ensure_realm_f {
Subroutine ensure_realm_f: called CC=1 SCAR=0.4
Pod documented
209 3 my ( $self, %rep ) = @_;
210 return $self->_ensure_f(
211 wanted => \%rep,
212 3 ▶ find => sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
213 1 ▶ $self->get_realm_f->else( sub {
Subroutine __ANON__: called CC=4 SCAR=18.9
214 1 my ( $error ) = @_;
215 1 ▶ return Future->done(undef) if blessed $error && $error->isa('WWW::Keycloak::Error::API') && $error->is_not_found;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found 1 0 1
Condition33%2/6
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found
!ll&&!rl&&r
001
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API")
!ll&&!rl&&r
001
MC/DC0%0/3
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found
builtin::blessed($error) $error->isa("WWW::Keycloak::Error::API") $error->is_not_found
Truth table25%1/4
A and B and C
A= builtin::blessed($error)B= $error->isa("WWW::Keycloak::Error::API")C= $error->is_not_found
ABCresult
0XX0
10X0
1100
1111
216 0 return Future->fail($error);
217 3 } );
218 },
219 1 ▶ create => sub { $self->create_realm_f( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
220 1 ▶ update => sub { $self->update_realm_f( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
221 2 ▶ id => sub { $_[0]->{realm} }
Subroutine __ANON__: called CC=1 SCAR=0.0
222 3 );
223 }
224  
225 9 ▶sub ensure_client_f {
Subroutine ensure_client_f: called CC=4 SCAR=13.9
Pod documented
226 9 my ( $self, %rep ) = @_;
227 9 ▶ return $self->fail_validation('ensure_client needs a clientId') unless defined $rep{clientId};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"clientId"} 1 8 9
228 8 for my $ignored (qw( defaultClientScopes optionalClientScopes protocolMappers )) {
229 return $self->fail_validation( 'ensure_client cannot set '.$ignored
230 .': Keycloak ignores it when a client is updated; use add_default_client_scope or ensure_protocol_mapper' )
231 21 ▶ if exists $rep{$ignored};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rep{$ignored} 3 18 21
232 }
233 return $self->_ensure_f(
234 wanted => \%rep,
235 5 ▶ find => sub { $self->find_client_f( $rep{clientId} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
236 2 ▶ create => sub { $self->create_client_f( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
237 1 ▶ update => sub { $self->update_client_f( $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
238 3 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
239 5 );
240 }
241  
242 3 ▶sub ensure_client_scope_f {
Subroutine ensure_client_scope_f: called CC=2 SCAR=6.9
Pod documented
243 3 my ( $self, %rep ) = @_;
244 3 ▶ return $self->fail_validation('ensure_client_scope needs a name') unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 0 3 3
245 return $self->_ensure_f(
246 wanted => \%rep,
247 3 ▶ find => sub { $self->find_client_scope_f( $rep{name} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
248 1 ▶ create => sub { $self->create_client_scope_f( { protocol => 'openid-connect', %rep } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
249 1 ▶ update => sub { $self->update_client_scope_f( $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
250 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
251 3 );
252 }
253  
254 6 ▶async sub ensure_protocol_mapper_f {
Subroutine ensure_protocol_mapper_f: called CC=7 SCAR=19.6
Pod documented
255 6 my ( $self, $kind, $owner_key, %rep ) = @_;
256 6 ▶ $self->validation_error_class->throw( message => 'ensure_protocol_mapper needs a name' ) unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 1 5 6
257 5 ▶ my $owner = $kind && $kind eq 'client' ? await( $self->find_client_f($owner_key) )
Branch: 2 branches
BranchTrueFalseTotal
$kind && $kind eq 'client' ? : 4 1 5
$kind && $kind eq 'client_scope' ? : 1 0 1
Condition50%3/6
$kind and $kind eq "client"
!ll&&!rl&&r
014
$kind and $kind eq "client_scope"
!ll&&!rl&&r
001
MC/DC50%1/2
$kind and $kind eq "client"
$kind $kind eq "client"
MC/DC0%0/2
$kind and $kind eq "client_scope"
$kind $kind eq "client_scope"
Truth table66%2/3
A and B
A= $kindB= $kind eq "client"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $kindB= $kind eq "client_scope"
ABresult
0X0
100
111
258 : $kind && $kind eq 'client_scope' ? await( $self->find_client_scope_f($owner_key) )
259 : $self->_mapper_path($kind);
260 5 ▶ $self->validation_error_class->throw( message => 'ensure_protocol_mapper: no '.$kind.' '.$owner_key ) unless $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless $owner 1 4 5
261 return await $self->_ensure_f(
262 wanted => \%rep,
263 4 ▶ find => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
264 4 ▶ $self->list_protocol_mappers_f( $kind, $owner->{id} )->then( sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
265 4 Future->done( ( grep { $_->{name} eq $rep{name} } @{ $_[0] } )[0] );
266 4 } );
267 },
268 2 ▶ create => sub { $self->create_protocol_mapper_f( $kind, $owner->{id}, { protocol => 'openid-connect', %rep } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
269 1 ▶ update => sub { $self->update_protocol_mapper_f( $kind, $owner->{id}, $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
270 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
271 4 );
272 7 }
273  
274 7 ▶sub ensure_user_f {
Subroutine ensure_user_f: called CC=5 SCAR=16.1
Pod documented
275 7 my ( $self, %rep ) = @_;
276 7 ▶ return $self->fail_validation('ensure_user needs a username') unless defined $rep{username};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"username"} 0 7 7
277 # Keycloak keeps user names and e-mail addresses in lower case
278 7 my %compare = %rep;
279 7 delete $compare{credentials};
280 7 $compare{$_} = lc $compare{$_} for grep { defined $compare{$_} } qw( username email );
281 # Keycloak keeps every user attribute as a list of strings
282 3 ▶ $compare{attributes} = { map { $_ => ref $rep{attributes}{$_} eq 'ARRAY' ? $rep{attributes}{$_} : [ $rep{attributes}{$_} ] } keys %{ $rep{attributes} } }
Branch: 1 branch
BranchTrueFalseTotal
ref $rep{'attributes'}{$_} eq 'ARRAY' ? : 1 2 3
283 7 ▶ if ref $rep{attributes} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rep{"attributes"} eq "HASH" 3 4 7
284 return $self->_ensure_f(
285 wanted => \%compare,
286 7 ▶ find => sub { $self->find_user_f( $rep{username} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
287 2 ▶ create => sub { $self->create_user_f( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
288 # the whole user: Keycloak's user profile drops fields a PUT with attributes does not name
289 2 ▶ update => sub { $self->update_user_f( $_[0]{id}, $self->diff_class->merge( $_[0], $_[1] ) ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
290 5 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
291 7 );
292 }
293  
294 6 ▶async sub ensure_execution_config_f {
Subroutine ensure_execution_config_f: called CC=6 SCAR=17.9
Pod documented
295 6 my ( $self, %arg ) = @_;
296 6 for (qw( flow authenticator config )) {
297 18 ▶ $self->validation_error_class->throw( message => 'ensure_execution_config needs '.$_ ) unless defined $arg{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{$_} 1 17 18
298 }
299 5 ▶ my ( $execution ) = grep { ( $_->{providerId} // '' ) eq $arg{authenticator} } @{ await $self->list_executions_f( $arg{flow} ) };
Condition100%2/2
$_->{"providerId"} // ""
l!l
144
MC/DC100%1/1
$_->{"providerId"} // ""
$_->{"providerId"}
Truth table100%2/2
A
A= $_->{"providerId"}
Aresult
11
00
300 5 ▶ $self->validation_error_class->throw( message => 'flow "'.$arg{flow}.'" has no step '.$arg{authenticator} ) unless $execution;
Branch: 1 branch
BranchTrueFalseTotal
unless $execution 1 4 5
301 4 ▶ my $alias = $arg{alias} // $arg{flow}.' '.$arg{authenticator};
Condition100%2/2
$arg{"alias"} // $arg{"flow"} . ' ' . $arg{"authenticator"}
l!l
13
MC/DC100%1/1
$arg{"alias"} // $arg{"flow"} . ' ' . $arg{"authenticator"}
$arg{"alias"}
Truth table100%2/2
A
A= $arg{"alias"}
Aresult
11
00
302 return await $self->_ensure_f(
303 wanted => { config => $arg{config} },
304 4 ▶ find => sub { $execution->{authenticationConfig} ? $self->get_execution_config_f( $execution->{authenticationConfig} ) : Future->done(undef) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$execution->{'authenticationConfig'} ? : 2 2 4
305 2 ▶ create => sub { $self->create_execution_config_f( $execution->{id}, { alias => $alias, config => $arg{config} } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
306 2 ▶ update => sub { $self->update_execution_config_f( $_[0]{id}, { alias => $_[0]{alias}, config => $arg{config} } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
307 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
308 4 );
309 7 }
310  
311  
312 7 1;
313  
314 __END__
« Keycloak/OIDC.pm ↑ Summary Keycloak.pm »