blib/lib/Zabbix2/API/User.pm

filter: Statementstmt 40.9% 27 / 66 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 47.0% 8 / 17 Podpod 100% 5 / 5 totaltotal 36.3% 40 / 110 SCAR 37.3
CC
10
Cov
32%
_usergroup_or_name_to_usergroup
30.0
id
6.0
_prefix
6.0
CRAP 41.8
« blib/lib/Zabbix2/API.pm ↑ Summary blib/lib/Zabbix2/API/Screen.pm »
1 package Zabbix2::API::User;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Moo::Lax;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 extends qw/Exporter Zabbix2::API::CRUDE/;
12  
13 use constant {
14 2 USER_TYPE_USER => 1,
15 USER_TYPE_ADMIN => 2,
16 USER_TYPE_SUPERADMIN => 3,
17 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 our @EXPORT_OK = qw/
20 USER_TYPE_USER
21 USER_TYPE_ADMIN
22 USER_TYPE_SUPERADMIN/;
23  
24 2 our %EXPORT_TAGS = (
25 user_types => [
26 qw/USER_TYPE_USER
27 USER_TYPE_ADMIN
28 USER_TYPE_SUPERADMIN/
29 ],
30 );
31  
32 sub _readonly_properties {
33 return {
34 0 ▶ userid => 1,
Subroutine _readonly_properties: not called CC=1 SCAR=6.9
35 attempt_clock => 1,
36 attempt_failed => 1,
37 attempt_ip => 1,
38 };
39 }
40  
41 sub id {
42 ## mutator for id
43 0 ▶ my ($self, $value) = @_;
Subroutine id: not called CC=2 SCAR=17.9
Pod documented
44 0 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
45 0 $self->data->{userid} = $value;
46 0 return $self->data->{userid};
47 } else {
48 0 return $self->data->{userid};
49 }
50 }
51  
52 sub _prefix {
53 0 ▶ my (undef, $suffix) = @_;
Subroutine _prefix: not called CC=2 SCAR=17.9
54 0 ▶ if ($suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) { } 0 0 0
55 0 return 'user'.$suffix;
56 } else {
57 0 return 'user';
58 }
59 }
60  
61 sub _extension {
62 0 ▶ return (output => 'extend');
Subroutine _extension: not called CC=1 SCAR=6.9
63 }
64  
65 sub name {
66 0 ▶ my $self = shift;
Subroutine name: not called CC=2 SCAR=17.9
Pod documented
67 0 ▶ return $self->data->{alias} || '???';
Condition0%0/2
$self->data->{'alias'} || '???'
l!l
00
MC/DC0%0/1
$self->data->{'alias'} || '???'
$self->data->{'alias'}
Truth table0%0/2
A
A= $self->data->{'alias'}
Aresult
11
00
68 }
69  
70 sub _usergroup_or_name_to_usergroup {
71  
72 0 ▶ my $zabbix = shift;
Subroutine _usergroup_or_name_to_usergroup: not called CC=5 SCAR=34.0
73 0 my $usergroup_or_name = shift;
74 0 my $usergroup;
75  
76 0 ▶ if (ref $usergroup_or_name and eval { $usergroup_or_name->isa('Zabbix2::API::UserGroup') }) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $usergroup_or_name and eval { do { $usergroup_or_name->isa('Zabbix2::API::UserGroup') } }) { } 0 0 0
elsif (not ref $usergroup_or_name) { } 0 0 0
Condition0%0/3
ref $usergroup_or_name and eval { do { $usergroup_or_name->isa("Zabbix2::API::UserGroup") } }
!ll&&!rl&&r
000
MC/DC0%0/2
ref $usergroup_or_name and eval { do { $usergroup_or_name->isa("Zabbix2::API::UserGroup") } }
ref $usergroup_or_name eval { do { $usergroup_or_name->isa("Zabbix2::API::UserGroup") } }
Truth table0%0/3
A and B
A= ref $usergroup_or_nameB= eval { do { $usergroup_or_name->isa("Zabbix2::API::UserGroup") } }
ABresult
0X0
100
111
77  
78 # it's a UserGroup object, keep it
79 0 $usergroup = $usergroup_or_name;
80  
81 } elsif (not ref $usergroup_or_name) {
82  
83 0 $usergroup = $zabbix->fetch_single('UserGroup', params => { filter => { name => $usergroup_or_name } });
84  
85 0 ▶ unless ($usergroup) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($usergroup) 0 0 0
86  
87 0 die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix2::API::UserGroup object or an existing usergroup name';
88  
89 }
90  
91 } else {
92  
93 0 die 'Parameter to add_to_usergroup or set_usergroups must be a Zabbix2::API::UserGroup object or an existing usergroup name';
94  
95 }
96  
97 0 return $usergroup;
98  
99 }
100  
101 sub add_to_usergroup {
102  
103 0 ▶ my ($self, $usergroup_or_name) = @_;
Subroutine add_to_usergroup: not called CC=2 SCAR=17.9
Pod documented
104 0 my $usergroup = _usergroup_or_name_to_usergroup($self->{root}, $usergroup_or_name);
105  
106 0 ▶ croak('Cannot add user without ID to usergroup: needs to be created or fetched')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
107 unless $self->id;
108  
109 0 $self->{root}->query(method => 'usergroup.massAdd',
110 params => { usrgrpids => [ $usergroup->id ],
111 userids => [ $self->id ] });
112  
113 0 return $self;
114  
115 }
116  
117 sub set_usergroups {
118  
119 0 ▶ my ($self, @list_of_usergroups_or_names) = @_;
Subroutine set_usergroups: not called CC=2 SCAR=17.9
Pod documented
120  
121 0 ▶ die 'User does not exist (yet?) on server'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->created 0 0 0
122 unless $self->created;
123  
124 0 my @list_of_usergroups = map { _usergroup_or_name_to_usergroup($self->{root}, $_) } @list_of_usergroups_or_names;
125  
126 $self->{root}->query(method => 'user.update',
127 params => { userid => $self->id,
128 0 usrgrps => [ map { $_->id } @list_of_usergroups ] });
129  
130 0 return $self;
131  
132 }
133  
134 sub set_password {
135  
136 0 ▶ my ($self, $password) = @_;
Subroutine set_password: not called CC=1 SCAR=6.9
Pod documented
137 0 $self->data->{passwd} = $password;
138 0 return $self;
139  
140 }
141  
142 2 1;
143 __END__
« blib/lib/Zabbix2/API.pm ↑ Summary blib/lib/Zabbix2/API/Screen.pm »