line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Cisco::FMC::v1::Role::ObjectMethods; |
2
|
|
|
|
|
|
|
$Net::Cisco::FMC::v1::Role::ObjectMethods::VERSION = '0.008000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Role for Cisco Firepower Management Center (FMC) API version 1 method generation |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21
|
use 5.024; |
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
5
|
use feature 'signatures'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
110
|
|
7
|
1
|
|
|
1
|
|
475
|
use MooX::Role::Parameterized; |
|
1
|
|
|
|
|
4153
|
|
|
1
|
|
|
|
|
103
|
|
8
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
9
|
1
|
|
|
1
|
|
7
|
use Clone qw( clone ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
10
|
1
|
|
|
1
|
|
484
|
use Moo::Role; # last for cleanup |
|
1
|
|
|
|
|
8992
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
574
|
no warnings "experimental::signatures"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
851
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires qw( _create _list _get _update _delete ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
role { |
24
|
|
|
|
|
|
|
my $params = shift; |
25
|
|
|
|
|
|
|
my $mop = shift; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
|
|
$mop->method('create_' . $params->{singular} => sub ($self, $object_data) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->_create(join('/', |
29
|
|
|
|
|
|
|
'/api/fmc_config/v1/domain', |
30
|
|
|
|
|
|
|
$self->domain_uuid, |
31
|
|
|
|
|
|
|
$params->{path}, |
32
|
|
|
|
|
|
|
$params->{object} |
33
|
0
|
|
|
|
|
|
), $object_data); |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
|
|
$mop->method('list_' . $params->{object} => sub ($self, $query_params = {}) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $self->_list(join('/', |
38
|
|
|
|
|
|
|
'/api/fmc_config/v1/domain', |
39
|
|
|
|
|
|
|
$self->domain_uuid, |
40
|
|
|
|
|
|
|
$params->{path}, |
41
|
|
|
|
|
|
|
$params->{object} |
42
|
0
|
|
|
|
|
|
), $query_params); |
43
|
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
|
|
$mop->method('get_' . $params->{singular} => sub ($self, $id, $query_params = {}) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $self->_get(join('/', |
47
|
|
|
|
|
|
|
'/api/fmc_config/v1/domain', |
48
|
|
|
|
|
|
|
$self->domain_uuid, |
49
|
|
|
|
|
|
|
$params->{path}, |
50
|
|
|
|
|
|
|
$params->{object}, |
51
|
0
|
|
|
|
|
|
$id |
52
|
|
|
|
|
|
|
), $query_params); |
53
|
|
|
|
|
|
|
}); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
|
|
$mop->method('update_' . $params->{singular} => sub ($self, $object, $object_data) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $id = $object->{id}; |
57
|
|
|
|
|
|
|
return $self->_update(join('/', |
58
|
|
|
|
|
|
|
'/api/fmc_config/v1/domain', |
59
|
|
|
|
|
|
|
$self->domain_uuid, |
60
|
|
|
|
|
|
|
$params->{path}, |
61
|
|
|
|
|
|
|
$params->{object}, |
62
|
0
|
|
|
|
|
|
$id |
63
|
|
|
|
|
|
|
), $object, $object_data); |
64
|
|
|
|
|
|
|
}); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
|
|
$mop->method('delete_' . $params->{singular} => sub ($self, $id) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $self->_delete(join('/', |
68
|
|
|
|
|
|
|
'/api/fmc_config/v1/domain', |
69
|
|
|
|
|
|
|
$self->domain_uuid, |
70
|
|
|
|
|
|
|
$params->{path}, |
71
|
|
|
|
|
|
|
$params->{object}, |
72
|
0
|
|
|
|
|
|
$id |
73
|
|
|
|
|
|
|
)); |
74
|
|
|
|
|
|
|
}); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
0
|
|
|
$mop->method('find_' . $params->{singular} => sub ($self, $query_params = {}) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $listname = 'list_' . $params->{object}; |
78
|
0
|
|
|
|
|
|
for my $object ($self->$listname({ expanded => 'true' })->{items}->@*) { |
79
|
0
|
|
|
|
|
|
my $identical = 1; |
80
|
0
|
|
|
|
|
|
for my $key (keys $query_params->%*) { |
81
|
0
|
0
|
|
|
|
|
if ( ref $query_params->{$key} eq 'Regexp') { |
82
|
0
|
0
|
|
|
|
|
if ($object->{$key} !~ $query_params->{$key}) { |
83
|
0
|
|
|
|
|
|
$identical = 0; |
84
|
0
|
|
|
|
|
|
last; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
0
|
0
|
|
|
|
|
if ($object->{$key} ne $query_params->{$key}) { |
89
|
0
|
|
|
|
|
|
$identical = 0; |
90
|
0
|
|
|
|
|
|
last; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
0
|
0
|
|
|
|
|
if ($identical) { |
95
|
0
|
|
|
|
|
|
return $object; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
croak "object not found"; |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Net::Cisco::FMC::v1::Role::ObjectMethods - Role for Cisco Firepower Management Center (FMC) API version 1 method generation |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 0.008000 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
package Net::Cisco::FMC::v1; |
121
|
|
|
|
|
|
|
use Moo; |
122
|
|
|
|
|
|
|
use Net::Cisco::FMC::v1::Role::ObjectMethods; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Net::Cisco::FMC::v1::Role::ObjectMethods->apply([ |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
path => 'object', |
127
|
|
|
|
|
|
|
object => 'portobjectgroups', |
128
|
|
|
|
|
|
|
singular => 'portobjectgroup', |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
{ |
131
|
|
|
|
|
|
|
path => 'object', |
132
|
|
|
|
|
|
|
object => 'protocolportobjects', |
133
|
|
|
|
|
|
|
singular => 'protocolportobject', |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
]); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This role adds methods for the REST methods of a specific object named. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 METHODS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 create_$singular |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Takes a hashref of attributes. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns the created object as hashref. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Throws an exception on error. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 list_$object |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Takes optional query parameters. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns a hashref with a single key 'items' that has a list of hashrefs |
158
|
|
|
|
|
|
|
similar to the FMC API. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Throws an exception on error. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
As the API only allows fetching 1000 objects at a time it works around that by |
163
|
|
|
|
|
|
|
making multiple API calls. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 get_$singular |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Takes an object id and optional query parameters. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns the object as hashref. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Throws an exception on error. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 update_$singular |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Takes an object and a hashref of attributes. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns the updated object as hashref. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Throws an exception on error. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 delete_$singular |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Takes an object id. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Returns true on success. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Throws an exception on error. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 find_$singular |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Takes query parameters. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns the object as hashref on success. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Throws an exception on error. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
As there is no API for searching by all attributes this method emulates this |
198
|
|
|
|
|
|
|
by fetching all objects using the L<list_$object> method and performing the |
199
|
|
|
|
|
|
|
search on the client. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 AUTHOR |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Alexander Hartmaier <abraxxa@cpan.org> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This software is copyright (c) 2018 - 2023 by Alexander Hartmaier. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
210
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |