line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
$Net::Checkpoint::Management::v1::Role::ObjectMethods::VERSION = '0.001010'; |
2
|
|
|
|
|
|
|
# ABSTRACT: Role for Checkpoint Management API version 1.x method generation |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use 5.024; |
5
|
1
|
|
|
1
|
|
13
|
use feature 'signatures'; |
|
1
|
|
|
|
|
2
|
|
6
|
1
|
|
|
1
|
|
4
|
use MooX::Role::Parameterized; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
102
|
|
7
|
1
|
|
|
1
|
|
340
|
use Carp::Clan qw(^Net::Checkpoint::Management::v1); |
|
1
|
|
|
|
|
2731
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
6
|
use Moo::Role; # last for cleanup |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
376
|
|
|
1
|
|
|
|
|
5921
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
no warnings "experimental::signatures"; |
11
|
1
|
|
|
1
|
|
420
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
738
|
|
12
|
|
|
|
|
|
|
requires qw( _create _list _get _update _delete ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
role { |
22
|
|
|
|
|
|
|
my $params = shift; |
23
|
|
|
|
|
|
|
my $mop = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if (exists $params->{singular} && defined $params->{singular}) { |
26
|
|
|
|
|
|
|
$mop->method('create_' . $params->{singular} => sub ($self, $object_data) { |
27
|
0
|
|
|
0
|
|
|
return $self->_create(join('/', |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
'/web_api', |
29
|
|
|
|
|
|
|
'v' . $self->api_version, |
30
|
|
|
|
|
|
|
$params->{create} |
31
|
|
|
|
|
|
|
), $object_data); |
32
|
0
|
|
|
|
|
|
}) |
33
|
|
|
|
|
|
|
if exists $params->{create} && defined $params->{create}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$mop->method('get_' . $params->{singular} => sub ($self, $query_params = {}) { |
36
|
0
|
|
|
0
|
|
|
return $self->_get(join('/', |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
'/web_api', |
38
|
|
|
|
|
|
|
'v' . $self->api_version, |
39
|
|
|
|
|
|
|
$params->{get} |
40
|
|
|
|
|
|
|
), $query_params); |
41
|
0
|
|
|
|
|
|
}) |
42
|
|
|
|
|
|
|
if exists $params->{get} && defined $params->{get}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$mop->method('update_' . $params->{singular} => sub ($self, $object, $object_data) { |
45
|
0
|
|
|
0
|
|
|
my $updated_data = { %$object, %$object_data }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
if (exists $params->{id_keys} && ref $params->{id_keys} eq 'ARRAY') { |
47
|
0
|
0
|
0
|
|
|
|
# ensure that only a single key is passed to the update call |
48
|
|
|
|
|
|
|
# the order of keys is the priority |
49
|
|
|
|
|
|
|
my @id_keys = $params->{id_keys}->@*; |
50
|
0
|
|
|
|
|
|
while (my $key = shift @id_keys) { |
51
|
0
|
|
|
|
|
|
last |
52
|
|
|
|
|
|
|
if exists $updated_data->{$key} |
53
|
|
|
|
|
|
|
&& defined $updated_data->{$key}; |
54
|
0
|
0
|
0
|
|
|
|
} |
55
|
|
|
|
|
|
|
delete $updated_data->{$_} |
56
|
|
|
|
|
|
|
for @id_keys; |
57
|
0
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $self->_update(join('/', |
60
|
|
|
|
|
|
|
'/web_api', |
61
|
|
|
|
|
|
|
'v' . $self->api_version, |
62
|
|
|
|
|
|
|
$params->{update} |
63
|
|
|
|
|
|
|
), $updated_data); |
64
|
0
|
|
|
|
|
|
}) |
65
|
|
|
|
|
|
|
if exists $params->{update} && defined $params->{update}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$mop->method('delete_' . $params->{singular} => sub ($self, $object) { |
68
|
0
|
|
|
0
|
|
|
return $self->_delete(join('/', |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
'/web_api', |
70
|
|
|
|
|
|
|
'v' . $self->api_version, |
71
|
|
|
|
|
|
|
$params->{delete} |
72
|
|
|
|
|
|
|
), $object); |
73
|
0
|
|
|
|
|
|
}) |
74
|
|
|
|
|
|
|
if exists $params->{delete} && defined $params->{delete}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$mop->method('find_' . $params->{singular} => sub ($self, $search_params = {}, $query_params = {}) { |
77
|
0
|
|
|
0
|
|
|
my $listname = 'list_' . $params->{object}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $list_key = $params->{list_key}; |
79
|
0
|
|
|
|
|
|
for my $object ($self->$listname({ 'details-level' => 'full', %$query_params })->{$list_key}->@*) { |
80
|
0
|
|
|
|
|
|
my $identical = 0; |
81
|
0
|
|
|
|
|
|
for my $key (keys $search_params->%*) { |
82
|
0
|
|
|
|
|
|
if ( ref $search_params->{$key} eq 'Regexp') { |
83
|
0
|
0
|
|
|
|
|
if ( exists $object->{$key} |
84
|
0
|
0
|
0
|
|
|
|
&& $object->{$key} =~ $search_params->{$key}) { |
85
|
|
|
|
|
|
|
$identical++; |
86
|
0
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
|
|
|
|
|
|
if ( exists $object->{$key} |
90
|
0
|
0
|
0
|
|
|
|
&& $object->{$key} eq $search_params->{$key}) { |
91
|
|
|
|
|
|
|
$identical++; |
92
|
0
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
if ($identical == scalar keys $search_params->%*) { |
96
|
0
|
0
|
|
|
|
|
return $object; |
97
|
0
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
croak "object not found"; |
100
|
0
|
|
|
|
|
|
}); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if (exists $params->{object} && defined $params->{object}) { |
104
|
|
|
|
|
|
|
$mop->method('list_' . $params->{object} => sub ($self, $query_params = {}) { |
105
|
0
|
|
|
0
|
|
|
return $self->_list(join('/', |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
'/web_api', |
107
|
|
|
|
|
|
|
'v' . $self->api_version, |
108
|
|
|
|
|
|
|
$params->{list} |
109
|
|
|
|
|
|
|
), $params->{list_key}, $query_params); |
110
|
0
|
|
|
|
|
|
}); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=pod |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=encoding UTF-8 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 NAME |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Net::Checkpoint::Management::v1::Role::ObjectMethods - Role for Checkpoint Management API version 1.x method generation |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 VERSION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
version 0.001010 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SYNOPSIS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
package Net::Checkpoint::Management::v1; |
132
|
|
|
|
|
|
|
use Moo; |
133
|
|
|
|
|
|
|
use Net::Checkpoint::Management::v1::Role::ObjectMethods; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Net::Checkpoint::Management::v1::Role::ObjectMethods->apply([ |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
object => 'packages', |
138
|
|
|
|
|
|
|
singular => 'package', |
139
|
|
|
|
|
|
|
create => 'add-package', |
140
|
|
|
|
|
|
|
list => 'show-packages', |
141
|
|
|
|
|
|
|
get => 'show-package', |
142
|
|
|
|
|
|
|
update => 'set-package', |
143
|
|
|
|
|
|
|
delete => 'delete-package', |
144
|
|
|
|
|
|
|
list_key => 'packages', |
145
|
|
|
|
|
|
|
id_keys => [qw( uid name )], |
146
|
|
|
|
|
|
|
}, |
147
|
|
|
|
|
|
|
{ |
148
|
|
|
|
|
|
|
object => 'accessrules', |
149
|
|
|
|
|
|
|
singular => 'accessrule', |
150
|
|
|
|
|
|
|
create => 'add-access-rule', |
151
|
|
|
|
|
|
|
list => 'show-access-rulebase', |
152
|
|
|
|
|
|
|
get => 'show-access-rule', |
153
|
|
|
|
|
|
|
update => 'set-access-rule', |
154
|
|
|
|
|
|
|
delete => 'delete-access-rule', |
155
|
|
|
|
|
|
|
list_key => 'rulebase', |
156
|
|
|
|
|
|
|
id_keys => ['uid', 'name', 'rule-number'], |
157
|
|
|
|
|
|
|
}, |
158
|
|
|
|
|
|
|
]); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 DESCRIPTION |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This role adds methods for the commands of a specific object. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 METHODS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 create_$singular |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Takes a hashref of attributes. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns the created object as hashref. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Throws an exception on error. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 list_$object |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Takes optional query parameters. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns a hashref similar to the Checkpoint Management API but without the |
181
|
|
|
|
|
|
|
'from' and 'to' keys. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Throws an exception on error. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
As the API only allows fetching 500 objects at a time it works around that by |
186
|
|
|
|
|
|
|
making multiple API calls. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 get_$singular |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Takes an object id and optional query parameters. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Returns the object as hashref. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Throws an exception on error. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 update_$singular |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Takes an object and a hashref of attributes. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Returns the updated object as hashref. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Throws an exception on error. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 delete_$singular |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Takes a hashref of attributes uniquely identifying the object. |
207
|
|
|
|
|
|
|
For most objects the uid is sufficient, accessrule requires the layer uid too. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns true on success. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Throws an exception on error. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 find_$singular |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Takes search and optional query parameters. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns the object as hashref on success. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Throws an exception on error. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
As there is no API for searching by all attributes this method emulates this |
222
|
|
|
|
|
|
|
by fetching all objects using the L</list_$object> method and performing the |
223
|
|
|
|
|
|
|
search on the client. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 AUTHOR |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Alexander Hartmaier <abraxxa@cpan.org> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Alexander Hartmaier. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
234
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |