File: | /home/mik/work/module/Tivoli/AccessManager/Admin/Objectspace.pm |
Coverage: | 99.4% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Tivoli::AccessManager::Admin::Objectspace; | ||||||
2 | 15 15 15 | 150 65 296 | use Carp; | ||||
3 | 15 15 15 | 244 79 234 | use strict; | ||||
4 | 15 15 15 | 2425 97 297 | use warnings; | ||||
5 | |||||||
6 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||||||
7 | # $Id: Objectspace.pm 335 2006-11-20 19:10:46Z mik $ | ||||||
8 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||||||
9 | |||||||
10 | $Tivoli::AccessManager::Admin::Objectspace::VERSION = '0.04'; | ||||||
11 | 15 | 198 | use Inline(C => 'DATA', | ||||
12 | INC => '-I/opt/PolicyDirector/include', | ||||||
13 | LIBS => ' -lpthread -lpdadminapi -lstdc++', | ||||||
14 | CCFLAGS => '-Wall', | ||||||
15 | # VERSION => '0.04', | ||||||
16 | NAME => 'Tivoli::AccessManager::Admin::Objectspace', | ||||||
17 | 15 15 | 182 62 | ); | ||||
18 | 15 15 15 | 235 68 289 | use Tivoli::AccessManager::Admin::Response; | ||||
19 | 15 15 15 | 273 92 329 | use Tivoli::AccessManager::Admin::ProtObject; | ||||
20 | |||||||
21 | my %obj_types = ( unknown => 0, | ||||||
22 | domain => 1, | ||||||
23 | file => 2, | ||||||
24 | program => 3, | ||||||
25 | dir => 4, | ||||||
26 | junction => 5, | ||||||
27 | webseal => 6, | ||||||
28 | nonexist => 10, | ||||||
29 | container => 11, | ||||||
30 | leaf => 12, | ||||||
31 | port => 13, | ||||||
32 | app_container => 14, | ||||||
33 | app_leaf => 15, | ||||||
34 | mgmt_object => 16, | ||||||
35 | ); | ||||||
36 | |||||||
37 | my %rev_obj_types = map { $obj_types{$_} => $_ } keys %obj_types; | ||||||
38 | |||||||
39 | sub new { | ||||||
40 | 13 | 1 | 63 | my $class = shift; | |||
41 | 13 | 32 | my $cont = shift; | ||||
42 | |||||||
43 | 13 | 176 | unless ( defined($cont) and UNIVERSAL::isa($cont,'Tivoli::AccessManager::Admin::Context' ) ) { | ||||
44 | 2 | 33 | warn "Incorrect syntax -- did you forget the context?\n"; | ||||
45 | 2 | 16 | return undef; | ||||
46 | } | ||||||
47 | |||||||
48 | 11 | 268 | my $self = bless {}, $class; | ||||
49 | 11 | 61 | if ( @_ % 2 ) { | ||||
50 | 2 | 29 | warn "Invalid syntax\n"; | ||||
51 | 2 | 11 | return undef; | ||||
52 | } | ||||||
53 | 9 | 65 | my %opts = @_; | ||||
54 | |||||||
55 | 9 | 60 | $self->{name} = $opts{name} || ''; | ||||
56 | 9 | 56 | $self->{desc} = $opts{desc} || ''; | ||||
57 | 9 | 27 | $self->{exist} = 0; | ||||
58 | 9 | 27 | $self->{context} = $cont; | ||||
59 | |||||||
60 | 9 | 35 | if ( defined $opts{type} ) { | ||||
61 | 7 | 69 | if ( $opts{type} =~ /^\d+$/ ) { | ||||
62 | 3 | 15 | if (defined $rev_obj_types{$opts{type}}) { | ||||
63 | 1 | 9 | $self->{type} = $opts{type}; | ||||
64 | } | ||||||
65 | else { | ||||||
66 | 2 | 32 | warn( "Unknown object type $opts{type}\n" ); | ||||
67 | 2 | 12 | return undef; | ||||
68 | } | ||||||
69 | } | ||||||
70 | else { | ||||||
71 | 4 | 22 | if (defined $obj_types{$opts{type}}) { | ||||
72 | 3 | 19 | $self->{type} = $obj_types{$opts{type}}; | ||||
73 | } | ||||||
74 | else { | ||||||
75 | 1 | 28 | warn( "Unknown object type $opts{type}\n" ); | ||||
76 | 1 | 10 | return undef; | ||||
77 | } | ||||||
78 | } | ||||||
79 | } | ||||||
80 | |||||||
81 | 6 | 38 | return $self; | ||||
82 | } | ||||||
83 | |||||||
84 | sub create { | ||||||
85 | 13 | 1 | 94 | my $self = shift; | |||
86 | 13 | 98 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
87 | |||||||
88 | 13 | 59 | unless (ref $self) { | ||||
89 | 6 | 14 | my $pd = shift; | ||||
90 | 6 | 74 | unless ( defined($pd) and UNIVERSAL::isa($pd,'Tivoli::AccessManager::Admin::Context' ) ) { | ||||
91 | 2 | 14 | $resp->set_message("Incorrect syntax -- did you forget the context?"); | ||||
92 | 2 | 12 | $resp->set_isok(0); | ||||
93 | 2 | 8 | return $resp; | ||||
94 | } | ||||||
95 | |||||||
96 | 4 | 21 | $self = new( $self, $pd, @_ ); | ||||
97 | 4 | 50 | unless ( defined($self) ) { | ||||
98 | 2 | 13 | $resp->set_isok(0); | ||||
99 | 2 | 10 | $resp->set_message("Could not create self"); | ||||
100 | 2 | 10 | return $resp; | ||||
101 | } | ||||||
102 | } | ||||||
103 | |||||||
104 | 9 | 39 | if ( @_ % 2 ) { | ||||
105 | 1 | 6 | $resp->set_message("Invalid syntax"); | ||||
106 | 1 | 7 | $resp->set_isok(0); | ||||
107 | 1 | 5 | return $resp; | ||||
108 | } | ||||||
109 | 8 | 41 | my %opts = @_; | ||||
110 | |||||||
111 | 8 | 36 | if ($self->exist) { | ||||
112 | 1 | 12 | $resp->set_message( $self->{name} . " already exists" ); | ||||
113 | 1 | 11 | $resp->set_iswarning(1); | ||||
114 | |||||||
115 | 1 | 7 | return $resp; | ||||
116 | } | ||||||
117 | |||||||
118 | 7 | 28 | unless ( $self->{name} ) { | ||||
119 | 2 | 21 | $self->{name} = $opts{name} || ''; | ||||
120 | } | ||||||
121 | |||||||
122 | 7 | 27 | unless ( $self->{type} ) { | ||||
123 | 3 | 17 | $self->{type} = 0; | ||||
124 | } | ||||||
125 | |||||||
126 | 7 | 22 | if ( $self->{name} ) { | ||||
127 | 6 | 268339 | my $rc = $self->objectspace_create( $resp, $self->{type} ); | ||||
128 | 6 | 116 | $resp->isok and $resp->set_value($self); | ||||
129 | 6 | 41 | $self->{exist} = $resp->isok; | ||||
130 | } | ||||||
131 | else { | ||||||
132 | 1 | 7 | $resp->set_message("create syntax error"); | ||||
133 | 1 | 7 | $resp->set_isok(0); | ||||
134 | } | ||||||
135 | 7 | 72 | return $resp; | ||||
136 | } | ||||||
137 | |||||||
138 | sub delete { | ||||||
139 | 7 | 1 | 29 | my $self = shift; | |||
140 | 7 | 61 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
141 | 7 | 16 | my $rc; | ||||
142 | |||||||
143 | 7 | 37 | unless ( $self->{name} ) { | ||||
144 | 1 | 8 | $resp->set_message("Cannot delete a nameless objectspace"); | ||||
145 | 1 | 6 | $resp->set_isok(0); | ||||
146 | 1 | 5 | return $resp; | ||||
147 | } | ||||||
148 | |||||||
149 | 6 | 28 | unless ( $self->{exist} ) { | ||||
150 | 1 | 7 | $resp->set_message("Cannot delete a non-existent objectspace"); | ||||
151 | 1 | 6 | $resp->set_isok(0); | ||||
152 | 1 | 5 | return $resp; | ||||
153 | } | ||||||
154 | |||||||
155 | 5 | 222911 | $rc = $self->objectspace_delete( $resp ); | ||||
156 | 5 | 96 | if ($resp->isok) { | ||||
157 | 4 | 31 | $resp->set_value($rc); | ||||
158 | 4 | 32 | $self->{exist} = 0; | ||||
159 | } | ||||||
160 | |||||||
161 | 5 | 35 | return $resp; | ||||
162 | } | ||||||
163 | |||||||
164 | sub list { | ||||||
165 | 2 | 1 | 11 | my $self = shift; | |||
166 | 2 | 5 | my $pd; | ||||
167 | 2 | 15 | my $resp = Tivoli::AccessManager::Admin::Response->new; | ||||
168 | 2 | 6 | my @rc; | ||||
169 | |||||||
170 | |||||||
171 | 2 | 11 | if ( ref($self) ) { | ||||
172 | 1 | 4 | $pd = $self->{context}; | ||||
173 | } | ||||||
174 | else { | ||||||
175 | 1 | 4 | $pd = shift; | ||||
176 | } | ||||||
177 | |||||||
178 | 2 | 85075 | @rc = objectspace_list($pd, $resp); | ||||
179 | 2 | 44 | $resp->isok and $resp->set_value(\@rc); | ||||
180 | |||||||
181 | 2 | 18 | return $resp; | ||||
182 | } | ||||||
183 | |||||||
184 | 8 | 1 | 42 | sub exist { return $_[0]->{exist}; } | |||
185 | |||||||
186 | 1; | ||||||
187 | |||||||
188 - 348 | =head1 NAME Tivoli::AccessManager::Admin::Objectspace =head1 SYNOPSIS use Tivoli::AccessManager::Admin my $resp; my $pd = Tivoli::AccessManager::Admin->new( password => 'N3ew0nk!' ); my $ospace = Tivoli::AccessManager::Admin::Objectspace->new( $pd, name => '/test', type => 'container', desc => 'Test objectspace', ); # Create the objectspace if it doesn't exist unless ( $ospace->exist ) { $resp = $ospace->create() } # Delete the objectspace $ospace->delete; # List all the objectspaces $resp = $ospace->list; print @{$resp->value}, "\n"; =head1 DESCRIPTION B<Tivoli::AccessManager::Admin::Objectspace> provides the interface to the objectspace portion of the TAM APIs. =head1 CONSTRUCTOR =head2 new( PDADMIN[, name =E<gt> NAME, type =E<gt> TYPE, desc => STRING] ) Creates a blessed B<Tivoli::AccessManager::Admin::Objectspace> object and returns it. =head3 Parameters =over 4 =item PDADMIN An initialized L<Tivoli::AccessManager::Admin::Context> object. Please note that, after the L<Tivoli::AccessManager::Admin::Objectspace> object is created, you cannot change the context w/o destroying the object and recreating it. =item name =E<gt> NAME The name of the objectspace to be created. I believe it needs to start with a /, but I don't know for certain. =item type =E<gt> TYPE The type of the objectspace. This can either be a numeric value as defined in the TAM Admin guide, or it may be a word. I have not defined the unused object types. The mapping between names and values looks like this: unknown => 0 domain => 1 file => 2 program => 3 dir => 4 junction => 5 webseal => 6 nonexist => 10 container => 11 leaf => 12 port => 13 app_container => 14 app_leaf => 15 mgmt_object => 16 =item desc =E<gt> STRING A description. =back =head3 Returns A fully blessed L<Tivoli::AccessManager::Admin::Objectspace> object. =head1 METHODS You should know this by now, but all of the methods return a L<Tivoli::AccessManager::Admin::Response> object. See the documentation for that module to learn how to coax the values out. =head2 create([ PDADMIN, name =E<gt> NAME, desc =E<gt> STRING, type =E<gt> TYPE ]) B<create> creates a new objectspace. It can be used as a constructor. The parameters are only required in that instance. =head3 Parameters See L<Tivoli::AccessManager::Admin::Objectspace::new> for the discussion and description. =head3 Returns If used as a contructor, a fully blessed L<Tivoli::AccessManager::Admin::Objectspace> object. Otherwise, the success or failure of the create operation. =head2 delete Deletes an objectspace. =head3 Parameters None =head3 Returns The success or failure of the operation. =head2 list([PDADMIN]) Lists all of the objectspaces in the domain. This can be used as either an instance method ( $self=E<gt>list ) or a class method ( Tivoli::AccessManager::Admin::Objectspace=E<gt>list ). =head3 Parameters =over 4 =item PDADMIN A fully blessed L<Tivoli::AccessManager::Admin::Context> object. This is required only when B<list> is being used as a class method. =back =head3 Returns A list of all the objectspaces defined in the domain. =head2 exist Returns true if the objectspace exists. This is a read only method and DOES NOT use a L<Tivoli::AccessManager::Admin::Response>. =head1 ACKNOWLEDGEMENTS See L<Tivoli::AccessManager::Admin> for the complete list of credits. =head1 BUGS None known =head1 AUTHOR Mik Firestone E<lt>mikfire@gmail.comE<gt> =head1 COPYRIGHT Copyright (c) 2004-2011 Mik Firestone. All rights reserved. This program is free software; you can redistibute it and/or modify it under the same terms as Perl itself. All references to TAM, Tivoli Access Manager, etc are copyrighted, trademarked and otherwise patented by IBM. =cut | ||||||
349 |