blib/lib/Net/Cisco/ACS/User.pm

filter: Statementstmt 64.4% 38 / 59 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 43.6% 45 / 103 CC 13 SCAR 48.3
CC
13
Cov
46%
toXML
182.0
header
2.0
BEGIN
1.0
CRAP 124.9
« blib/lib/Net/Cisco/ACS/Device.pm ↑ Summary blib/lib/Net/Cisco/ACS/Host.pm »
1 package Net::Cisco::ACS::User;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %actions);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ $VERSION = '0.02';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 @ISA = qw(Exporter);
10 1 @EXPORT = qw();
11 1 @EXPORT_OK = qw();
12 1 %EXPORT_TAGS = ();
13 };
14  
15 1 %actions = ( "query" => "/Rest/Identity/User",
16 "create" => "/Rest/Identity/User",
17 "update" => "/Rest/Identity/User",
18 "getByName" => "/Rest/Identity/User/name/",
19 "getById" => "/Rest/Identity/User/id/",
20 );
21  
22 # MOOSE!
23
24 1 has 'description' => (
25 is => 'rw',
26 isa => 'Any',
27 );
28  
29 1 has 'id' => (
30 is => 'rw',
31 isa => 'Str',
32 );
33  
34 1 has 'identityGroupName' => (
35 is => 'rw',
36 isa => 'Str',
37 );
38  
39 1 has 'name' => (
40 is => 'rw',
41 isa => 'Str',
42 );
43  
44 1 has 'dateExceeds' => (
45 is => 'rw',
46 isa => 'Str',
47 );
48  
49 1 has 'changePassword' => (
50 is => 'ro',
51 isa => 'Str',
52 );
53  
54 1 has 'created' => (
55 is => 'ro',
56 isa => 'Str',
57 );
58  
59 1 has 'attributeInfo' => (
60 is => 'ro',
61 isa => 'ArrayRef',
62 auto_deref => '1',
63 );
64  
65 1 has 'dateExceedsEnabled' => (
66 is => 'rw',
67 isa => 'Str',
68 );
69  
70 1 has 'enablePassword' => (
71 is => 'rw',
72 isa => 'Str',
73 );
74  
75 1 has 'enabled' => (
76 is => 'rw',
77 isa => 'Str',
78 );
79  
80 1 has 'lastLogin' => (
81 is => 'ro',
82 isa => 'Any',
83 );
84  
85 1 has 'lastModified' => (
86 is => 'ro',
87 isa => 'Str',
88 );
89  
90 1 has 'lastPasswordChange' => (
91 is => 'ro',
92 isa => 'Str',
93 );
94  
95 1 has 'loginFailuresCounter' => (
96 is => 'ro',
97 isa => 'Int',
98 );
99  
100 1 has 'password' => (
101 is => 'rw',
102 isa => 'Str',
103 );
104  
105 1 has 'passwordNeverExpires' => (
106 is => 'rw',
107 isa => 'Str',
108 );
109  
110 1 has 'passwordType' => (
111 is => 'rw',
112 isa => 'Str',
113 );
114  
115 # No Moose
116
117 sub toXML
118 0 ▶{ my $self = shift;
Subroutine toXML: not called CC=13 SCAR=52.0
Pod documented
119 0 my $id = $self->id;
120 0 ▶ my $description = $self->description || "";
Condition0%0/2
$self->description || ''
l!l
00
MC/DC0%0/1
$self->description || ''
$self->description
Truth table0%0/2
A
A= $self->description
Aresult
11
00
121 0 ▶ my $identitygroupname = $self->identityGroupName || "All Groups";
Condition0%0/2
$self->identityGroupName || 'All Groups'
l!l
00
MC/DC0%0/1
$self->identityGroupName || 'All Groups'
$self->identityGroupName
Truth table0%0/2
A
A= $self->identityGroupName
Aresult
11
00
122 0 ▶ my $name = $self->name || "";
Condition0%0/2
$self->name || ''
l!l
00
MC/DC0%0/1
$self->name || ''
$self->name
Truth table0%0/2
A
A= $self->name
Aresult
11
00
123 0 ▶ my $changepassword = $self->changePassword || "false";
Condition0%0/2
$self->changePassword || 'false'
l!l
00
MC/DC0%0/1
$self->changePassword || 'false'
$self->changePassword
Truth table0%0/2
A
A= $self->changePassword
Aresult
11
00
124 0 ▶ my $enabled = $self->enabled || "true";
Condition0%0/2
$self->enabled || 'true'
l!l
00
MC/DC0%0/1
$self->enabled || 'true'
$self->enabled
Truth table0%0/2
A
A= $self->enabled
Aresult
11
00
125 0 ▶ my $password = $self->password || "";
Condition0%0/2
$self->password || ''
l!l
00
MC/DC0%0/1
$self->password || ''
$self->password
Truth table0%0/2
A
A= $self->password
Aresult
11
00
126 0 ▶ my $passwordneverexpires = $self->passwordNeverExpires || "false";
Condition0%0/2
$self->passwordNeverExpires || 'false'
l!l
00
MC/DC0%0/1
$self->passwordNeverExpires || 'false'
$self->passwordNeverExpires
Truth table0%0/2
A
A= $self->passwordNeverExpires
Aresult
11
00
127 0 ▶ my $passwordtype = $self->passwordType || "Internal Users";
Condition0%0/2
$self->passwordType || 'Internal Users'
l!l
00
MC/DC0%0/1
$self->passwordType || 'Internal Users'
$self->passwordType
Truth table0%0/2
A
A= $self->passwordType
Aresult
11
00
128 0 ▶ my $enablepassword = $self->enablePassword || "";
Condition0%0/2
$self->enablePassword || ''
l!l
00
MC/DC0%0/1
$self->enablePassword || ''
$self->enablePassword
Truth table0%0/2
A
A= $self->enablePassword
Aresult
11
00
129 0 ▶ my $dateexceeds = $self->dateExceeds || "";
Condition0%0/2
$self->dateExceeds || ''
l!l
00
MC/DC0%0/1
$self->dateExceeds || ''
$self->dateExceeds
Truth table0%0/2
A
A= $self->dateExceeds
Aresult
11
00
130 0 ▶ my $dateexceedsenabled = $self->dateExceedsEnabled || "false";
Condition0%0/2
$self->dateExceedsEnabled || 'false'
l!l
00
MC/DC0%0/1
$self->dateExceedsEnabled || 'false'
$self->dateExceedsEnabled
Truth table0%0/2
A
A= $self->dateExceedsEnabled
Aresult
11
00
131 0 my $result = "";
132
133 0 ▶ if ($id) { $result = " <id>$id</id>\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
134 0 $result .= <<XML;
135 <description>$description</description>
136 <identityGroupName>$identitygroupname</identityGroupName>
137 <name>$name</name>
138 <changePassword>$changepassword</changePassword>
139 <enablePassword>$enablepassword</enablePassword>
140 <enabled>$enabled</enabled>
141 <password>$password</password>
142 <passwordNeverExpires>$passwordneverexpires</passwordNeverExpires>
143 <passwordType>$passwordtype</passwordType>
144 <dateExceeds>$dateexceeds</dateExceeds>
145 <dateExceedsEnabled>$dateexceedsenabled</dateExceedsEnabled>
146 XML
147  
148 0 return $result;
149 }
150  
151 sub header
152 0 ▶{ my $self = shift;
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
153 0 my $users = shift;
154 0 return qq{<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:user xmlns:ns2="identity.rest.mgmt.acs.nm.cisco.com">$users</ns2:user>};
155 }
156
157 =head1 NAME
158  
159 Net::Cisco::ACS::User - Access Cisco ACS functionality through REST API - User fields
160  
161 =head1 SYNOPSIS
162  
163 use Net::Cisco::ACS;
164 use Net::Cisco::ACS::User;
165
166 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
167 my $user = Net::Cisco::ACS::User->new("name"=>"soloh","description"=>"Han Solo","identityGroupName"=>"All Groups:MilleniumCrew","password"=>"Leia");
168  
169 my %users = $acs->users;
170 # Retrieve all users from ACS
171 # Returns hash with username / Net::Cisco::ACS::User pairs
172
173 print $acs->users->{"acsadmin"}->toXML;
174 # Dump in XML format (used by ACS for API calls)
175
176 my $user = $acs->users("name","acsadmin");
177 # Faster call to request specific user information by name
178  
179 my $user = $acs->users("id","150");
180 # Faster call to request specific user information by ID (assigned by ACS, present in Net::Cisco::ACS::User)
181  
182 $user->id(0); # Required for new user!
183 my $id = $acs->create($user);
184 # Create new user based on Net::Cisco::ACS::User instance
185 # Return value is ID generated by ACS
186 print "Record ID is $id" if $id;
187 print $Net::Cisco::ACS::ERROR unless $id;
188 # $Net::Cisco::ACS::ERROR contains details about failure
189  
190 my $id = $acs->update($user);
191 # Update existing user based on Net::Cisco::ACS::User instance
192 # Return value is ID generated by ACS
193 print "Record ID is $id" if $id;
194 print $Net::Cisco::ACS::ERROR unless $id;
195 # $Net::Cisco::ACS::ERROR contains details about failure
196  
197 $acs->delete($user);
198 # Delete existing user based on Net::Cisco::ACS::User instance
199
200 =head1 DESCRIPTION
201  
202 The Net::Cisco::ACS::User class holds all the user relevant information from Cisco ACS 5.x
203  
204 =head1 USAGE
205  
206 All calls are typically handled through an instance of the L<Net::Cisco::ACS> class. L<Net::Cisco::ACS::User> acts as a container for user related information.
207  
208 =over 3
209  
210 =item new
211  
212 Class constructor. Returns object of Net::Cisco::ACS::User on succes. The following fields can be set / retrieved:
213  
214 =over 5
215  
216 =item description
217 =item name
218 =item identityGroupName
219 =item enablePassword
220 =item enabled
221 =item password
222 =item passwordNeverExpires
223 =item passwordType
224 =item dateExceeds
225 =item dateExceedsEnabled
226 =item id
227  
228 Formatting rules may be in place & enforced by Cisco ACS.
229  
230 =back
231  
232 Read-only values:
233  
234 =over 5
235  
236 =item changePassword
237 =item created
238 =item attributeInfo
239 =item lastLogin
240 =item lastModified
241 =item lastPasswordChange
242 =item loginFailuresCounter
243  
244 =back
245  
246 =over 3
247  
248 =item description
249  
250 The user account description, typically used for full name.
251  
252 =item name
253  
254 The user account name. This is a required value in the constructor but can be redefined afterwards.
255  
256 =item identityGroupName
257  
258 The user group name. This is a required value in the constructor but can be redefined afterwards. See L<Net::Cisco::ACS::IdentityGroupName>.
259  
260 =item enablePassword
261  
262 The enable password (for Cisco-level access), not needed if you work with command sets in your access policies.
263  
264 =item enabled
265  
266 Boolean flag to indicate account status.
267  
268 =item password
269  
270 Password. When querying user account information, the password will be masked as *********. This is a required value in the constructor but can be redefined afterwards.
271  
272 =item passwordNeverExpires
273  
274 Boolean flag to indicate account expiration status.
275  
276 =item passwordType
277  
278 A read-only valie that indicates the password type, either for Internal User or Active Directory (needs confirmation).
279  
280 =item dateExceeds
281  
282 Date field to automatically deactivate the account once passed.
283  
284 =item dateExceedsEnabled
285  
286 Boolean flag to activate the automatic deactivation feature based on expiration dates.
287  
288 =item id
289  
290 Cisco ACS generates a unique ID for each User record. This field cannot be updated within ACS but is used for reference. Set to 0 when creating a new record or when duplicating an existing user.
291  
292 =item toXML
293  
294 Dump the record in ACS accept XML formatting (without header).
295  
296 =item header
297  
298 Generate the correct XML header. Takes output of C<toXML> as argument.
299  
300 =back
301  
302 =head1 BUGS
303  
304 None yet
305  
306 =head1 SUPPORT
307  
308 None yet :)
309  
310 =head1 AUTHOR
311  
312 Hendrik Van Belleghem
313 CPAN ID: BEATNIK
314 hendrik.vanbelleghem@gmail.com
315  
316 =head1 COPYRIGHT
317  
318 This program is free software licensed under the...
319  
320 The General Public License (GPL)
321 Version 2, June 1991
322  
323 The full text of the license can be found in the
324 LICENSE file included with this module.
325  
326  
327 =head1 SEE ALSO
328  
329 perl(1).
330  
331 =cut
332  
333 #################### main pod documentation end ###################
334 1 __PACKAGE__->meta->make_immutable();
335  
336 1 1;
337 # The preceding line will help the module return a true value
338  
« blib/lib/Net/Cisco/ACS/Device.pm ↑ Summary blib/lib/Net/Cisco/ACS/Host.pm »