| 1 | # Net::IPA.pm -- Perl 5 interface of the (Free)IPA JSON-RPC API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # for more information about this api see: https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # written by Nicolas Cisco (https://github.com/nickcis) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # https://github.com/nickcis/perl-Net-IPA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Copyright (c) 2016 Nicolas Cisco. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Licensed under the GPLv2, see LICENSE file for more information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | package Net::IPA::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | OptionError => 3005, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | RequirementError => 3007, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | NotFound => 4001, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | DuplicateEntry => 4002, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | EmptyModlist => 4202, # e.g: user_mod with no modifications to the db | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my ($proto, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $self = $result || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result || {}
MC/DC0%0/1
$result || {}
$result
Truth table0%0/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #** Returns a string explaining the error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # If it's not an error, it returns an empty string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # @return String explaining the error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sub error_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return "" unless($self->is_error()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return "undef" unless(%$self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return "code: " . $self->error_code() ." (" . $self->error_name() .") " . $self->error_message(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | sub error_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_code: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $self->{error_code} if($self->{error_code}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $self->{error}->{code} if(ref($self->{error}) eq 'HASH' and $self->{error}->{code}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"code"}
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"code"}
ref $self->{"error"} eq "HASH"
$self->{"error"}{"code"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub error_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_name: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return $self->{error_name} if($self->{error_name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return $self->{error}->{name} if(ref($self->{error}) eq 'HASH' and $self->{error}->{name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"name"}
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"name"}
ref $self->{"error"} eq "HASH"
$self->{"error"}{"name"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sub error_message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_message: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $self->{error}->{message} if(ref($self->{error}) eq 'HASH' and $self->{error}->{message}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self->{"error"} eq "HASH" and $self->{"error"}{"message"}
MC/DC0%0/2
ref $self->{"error"} eq "HASH" and $self->{"error"}{"message"}
ref $self->{"error"} eq "HASH"
$self->{"error"}{"message"}
Truth table0%0/3
A and B
A= ref $self->{"error"} eq "HASH"B= $self->{"error"}{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return $self->{error} if($self->{error}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | #** Checks if the response is an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # @returns 1: If error, 0: if not error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub is_error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 1 if( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not %$self or $self->error_code or $self->error_name or $self->error_message
not %$self or $self->error_code or $self->error_name
not %$self or $self->error_code
MC/DC0%0/4
not %$self or $self->error_code or $self->error_name or $self->error_message
not %$self
$self->error_code
$self->error_name
$self->error_message
Truth table0%0/5
not(A) or B or C or D
A= not %$selfB= $self->error_codeC= $self->error_nameD= $self->error_message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | not(%$self) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $self->error_code() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $self->error_name() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | $self->error_message() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $sub = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | (my $name = $sub) =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if(ref($self->{result}) eq 'HASH'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $value = $self->{result}->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return ref($value) eq 'ARRAY' ? $value->[0] : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||