blib/lib/Net/Fortinet/FortiManager.pm

filter: Statementstmt 18.0% 32 / 177 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 11.5% 8 / 69 Podpod 100% 54 / 54 totaltotal 25.8% 94 / 364 CC 46 SCAR 27.4
CC
46
Cov
14%
_rpc_error_handler
90.0
_exec_method
42.0
exec_method
42.0
CRAP 15.5
↑ Summary
1 package Net::Fortinet::FortiManager;
2 2 $Net::Fortinet::FortiManager::VERSION = '0.001000';
3 # ABSTRACT: Fortinet FortiManager REST API client library
4  
5 2 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Types::Standard qw( ArrayRef HashRef InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Types::Common::Numeric qw( PositiveInt );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use List::Util qw( all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 2 has 'user' => (
17 isa => Str,
18 is => 'rw',
19 predicate => 1,
20 );
21  
22 2 has 'passwd' => (
23 isa => Str,
24 is => 'rw',
25 predicate => 1,
26 );
27  
28 2 has '_sessionid' => (
29 isa => Str,
30 is => 'rw',
31 predicate => 1,
32 clearer => 1,
33 );
34  
35 2 has '_last_transaction_id' => (
36 isa => PositiveInt,
37 is => 'rw',
38 predicate => 1,
39 clearer => 1,
40 );
41  
42 ▶sub _get_transaction_id ($self) {
Subroutine _get_transaction_id: not called CC=2 SCAR=17.9
43 0 my $id;
44 0 ▶ if ($self->_has_last_transaction_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_last_transaction_id) { } 0 0 0
45 0 $id = $self->_last_transaction_id;
46 0 $id++;
47 }
48 else {
49 0 $id = 1;
50 }
51  
52 0 $self->_last_transaction_id($id);
53 0 return $id;
54 }
55  
56  
57 2 has 'adoms' => (
58 is => 'rwp',
59 isa => ArrayRef[Str],
60 );
61  
62  
63 has 'adom' => (
64 is => 'rw',
65 isa => Str,
66 0 ▶ default => sub { 'root' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 2 );
68  
69 2 with 'Role::REST::Client';
70  
71 # around 'do_request' => sub($orig, $self, $method, $uri, $opts) {
72 # warn 'request: ' . np($method, $uri, $opts);
73 # my $response = $orig->($self, $method, $uri, $opts);
74 # warn 'response: ' . np($response);
75 # return $response;
76 # };
77  
78 ▶sub _http_error_handler ($self, $res) {
Subroutine _http_error_handler: not called CC=2 SCAR=17.9
79 0 ▶ croak('http error (' . $res->code . '): ' . $res->response->decoded_content)
Branch: 1 branch
BranchTrueFalseTotal
unless $res->code == 200 0 0 0
80 unless $res->code == 200;
81 }
82  
83 ▶sub _rpc_error_handler ($self, $res, $number_of_expected_results) {
Subroutine _rpc_error_handler: not called CC=9 SCAR=45.0
84 0 ▶ if (ref $res->data eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res->data eq 'HASH' and exists $res->data->{'result'} and ref $res->data->{'result'} eq 'ARRAY' and scalar @{$res->data->{'result'}} == $number_of_expected_results and &all(sub { ref $_ eq 'HASH'; } , @{$res->data->{'result'}})) { } 0 0 0
Condition0%0/12
ref $res->data eq "HASH" and exists $res->data->{"result"} and ref $res->data->{"result"} eq "ARRAY" and scalar @{$res->data->{"result"}} == $number_of_expected_results and &all(sub {
!ll&&!rl&&r
000
ref $res->data eq "HASH" and exists $res->data->{"result"} and ref $res->data->{"result"} eq "ARRAY" and scalar @{$res->data->{"result"}} == $number_of_expected_results
!ll&&!rl&&r
000
ref $res->data eq "HASH" and exists $res->data->{"result"} and ref $res->data->{"result"} eq "ARRAY"
!ll&&!rl&&r
000
ref $res->data eq "HASH" and exists $res->data->{"result"}
!ll&&!rl&&r
000
MC/DC0%0/5
ref $res->data eq "HASH" and exists $res->data->{"result"} and ref $res->data->{"result"} eq "ARRAY" and scalar @{$res->data->{"result"}} == $number_of_expected_results and &all(sub { ref $_ eq "HASH"; } , @{$res->data->{"result"}})
ref $res->data eq "HASH" exists $res->data->{"result"} ref $res->data->{"result"} eq "ARRAY" scalar @{$res->data->{"result"}} == $number_of_expected_results &all(sub { ref $_ eq "HASH"; } , @{$res->data->{"result"}})
Truth table0%0/6
A and B and C and D and E
A= ref $res->data eq "HASH"B= exists $res->data->{"result"}C= ref $res->data->{"result"} eq "ARRAY"D= scalar @{$res->data->{"result"}} == $number_of_expected_resultsE= &all(sub { ref $_ eq "HASH"; } , @{$res->data->{"result"}})
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
85 && exists $res->data->{result}
86 && ref $res->data->{result} eq 'ARRAY'
87 && scalar $res->data->{result}->@* == $number_of_expected_results
88 0 ▶ && all { ref $_ eq 'HASH' } $res->data->{result}->@* ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ if ($number_of_expected_results == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number_of_expected_results == 1) { } 0 0 0
90 0 my $code = $res->data->{result}->[0]->{status}->{code};
91 0 my $message = $res->data->{result}->[0]->{status}->{message};
92 0 ▶ if ($code != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code != 0) 0 0 0
93 0 croak("jsonrpc error ($code): $message");
94 }
95 }
96 else {
97 my @failed_calls = grep {
98 0 $_->{status}->{code} != 0
99 0 } $res->data->{result}->@*;
100  
101 0 ▶ if (@failed_calls) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed_calls) 0 0 0
102 croak("jsonrpc errors: " . join(', ', map {
103 0 $_->{url} . ': (' . $_->{status}->{code} . ') ' .
104 $_->{status}->{message}
105 0 } @failed_calls));
106 }
107 }
108 }
109 else {
110 0 croak "jsonrpc error: response not in expected format: " .
111 $res->response->decoded_content;
112 }
113 }
114  
115 0 ▶sub _exec_method ($self, $method, $params = undef) {
Subroutine _exec_method: not called CC=6 SCAR=37.4
116 0 ▶ croak 'params needs to be an arrayref'
Branch: 1 branch
BranchTrueFalseTotal
if defined $params and ref $params ne "ARRAY" 0 0 0
Condition0%0/3
defined $params and ref $params ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params and ref $params ne "ARRAY"
defined $params ref $params ne "ARRAY"
Truth table0%0/3
A and B
A= defined $paramsB= ref $params ne "ARRAY"
ABresult
0X0
100
111
117 if defined $params && ref $params ne 'ARRAY';
118  
119 0 my $body = {
120 id => $self->_get_transaction_id,
121 method => $method,
122 params => $params,
123 verbose => 1,
124 };
125 0 ▶ $body->{session} = $self->_sessionid
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_sessionid 0 0 0
126 if $self->_has_sessionid;
127  
128 # p $body;
129 0 my $res = $self->post('/jsonrpc', $body);
130 # p $res;
131  
132 0 $self->_http_error_handler($res);
133  
134 0 ▶ $self->_rpc_error_handler($res, defined $params ? scalar $params->@* : 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $params ? : 0 0 0
135  
136 0 return $res;
137 }
138  
139  
140 0 ▶sub exec_method ($self, $method, $url, $params = undef) {
Subroutine exec_method: not called CC=6 SCAR=37.4
Pod documented
141 0 ▶ croak 'params needs to be a hashref'
Branch: 1 branch
BranchTrueFalseTotal
if defined $params and ref $params ne "HASH" 0 0 0
Condition0%0/3
defined $params and ref $params ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params and ref $params ne "HASH"
defined $params ref $params ne "HASH"
Truth table0%0/3
A and B
A= defined $paramsB= ref $params ne "HASH"
ABresult
0X0
100
111
142 if defined $params && ref $params ne 'HASH';
143  
144 0 ▶ my %full_params = defined $params
Branch: 1 branch
BranchTrueFalseTotal
defined $params ? : 0 0 0
145 ? $params->%*
146 : ();
147 0 $full_params{url} = $url;
148 0 my $rv = $self->_exec_method($method, [\%full_params])->data;
149  
150 # the existance of {result}[0] is already verified by _rpc_error_handler
151 # called in _exec_method
152 0 ▶ if (exists $rv->{result}[0]->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rv->{"result"}[0]{"data"}) 0 0 0
153 0 return $rv->{result}[0]->{data};
154 }
155 0 return 1;
156 }
157  
158  
159 ▶sub exec_method_multi ($self, $method, $params) {
Subroutine exec_method_multi: not called CC=4 SCAR=30.0
Pod documented
160 0 ▶ croak 'params needs to be an arrayref'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params eq "ARRAY" 0 0 0
161 unless ref $params eq 'ARRAY';
162  
163 croak 'each parameter needs to be a hashref'
164 0 ▶ unless any { ref $_ eq 'HASH' } $params->@*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { ref $_ eq "HASH"; } , @$params) 0 0 0
165  
166 0 my $rv = $self->_exec_method($method, $params)->data;
167  
168 0 ▶ if (exists $rv->{result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rv->{"result"}) 0 0 0
169 0 return $rv->{result};
170 }
171 0 return 1;
172 }
173  
174  
175 ▶sub login ($self) {
Subroutine login: not called CC=3 SCAR=24.8
Pod documented
176 0 ▶ die "user and password required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_user and $self->has_passwd 0 0 0
Condition0%0/3
$self->has_user and $self->has_passwd
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_user and $self->has_passwd
$self->has_user $self->has_passwd
Truth table0%0/3
A and B
A= $self->has_userB= $self->has_passwd
ABresult
0X0
100
111
177 unless $self->has_user && $self->has_passwd;
178  
179 0 my $res = $self->_exec_method('exec', [{
180 url => "/sys/login/user",
181 data => {
182 user => $self->user,
183 passwd => $self->passwd,
184 },
185 }]);
186  
187 0 $self->_sessionid($res->data->{session});
188  
189 0 $self->_set_adoms($self->list_adoms);
190  
191 0 return 1;
192 }
193  
194  
195 ▶sub logout ($self) {
Subroutine logout: not called CC=1 SCAR=6.9
Pod documented
196 0 $self->exec_method('exec', '/sys/logout');
197 0 $self->_clear_sessionid;
198 0 $self->_clear_last_transaction_id;
199  
200 0 return 1;
201 }
202  
203  
204 ▶sub get_sys_status ($self) {
Subroutine get_sys_status: not called CC=1 SCAR=6.9
Pod documented
205 0 return $self->exec_method('get', '/sys/status');
206 }
207  
208  
209 ▶sub list_adoms ($self) {
Subroutine list_adoms: not called CC=1 SCAR=6.9
Pod documented
210 my @adoms = map {
211 0 $_->{name}
212 0 } $self->exec_method('get', '/dvmdb/adom', {
213 fields => [qw( name )],
214 })->@*;
215 0 return \@adoms;
216 }
217  
218  
219 0 ▶sub list_firewall_addresses ($self, $params = {}) {
Subroutine list_firewall_addresses: not called CC=2 SCAR=17.9
Pod documented
220 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
221 '/obj/firewall/address', $params);
222 }
223  
224  
225 0 ▶sub get_firewall_address ($self, $name, $params = {}) {
Subroutine get_firewall_address: not called CC=2 SCAR=17.9
Pod documented
226 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
227 '/obj/firewall/address/'. $name, $params);
228 }
229  
230  
231 ▶sub create_firewall_address ($self, $name, $data) {
Subroutine create_firewall_address: not called CC=1 SCAR=6.9
Pod documented
232 0 my $params = {
233 data => [{
234 $data->%*,
235 name => $name,
236 }],
237 };
238 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
239 '/obj/firewall/address', $params);
240 }
241  
242  
243 ▶sub update_firewall_address ($self, $name, $data) {
Subroutine update_firewall_address: not called CC=1 SCAR=6.9
Pod documented
244 0 my $params = {
245 data => {
246 $data->%*,
247 },
248 };
249 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
250 '/obj/firewall/address/' . $name, $params);
251 }
252  
253  
254 ▶sub delete_firewall_address ($self, $name) {
Subroutine delete_firewall_address: not called CC=1 SCAR=6.9
Pod documented
255 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
256 '/obj/firewall/address/' . $name);
257 }
258  
259  
260 0 ▶sub list_firewall_address_groups ($self, $params = {}) {
Subroutine list_firewall_address_groups: not called CC=2 SCAR=17.9
Pod documented
261 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
262 '/obj/firewall/addrgrp', $params);
263 }
264  
265  
266 0 ▶sub get_firewall_address_group ($self, $name, $params = {}) {
Subroutine get_firewall_address_group: not called CC=2 SCAR=17.9
Pod documented
267 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
268 '/obj/firewall/addrgrp/'. $name, $params);
269 }
270  
271  
272 ▶sub create_firewall_address_group ($self, $name, $data) {
Subroutine create_firewall_address_group: not called CC=1 SCAR=6.9
Pod documented
273 0 my $params = {
274 data => [{
275 $data->%*,
276 name => $name,
277 }],
278 };
279 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
280 '/obj/firewall/addrgrp', $params);
281 }
282  
283  
284 ▶sub update_firewall_address_group ($self, $name, $data) {
Subroutine update_firewall_address_group: not called CC=1 SCAR=6.9
Pod documented
285 0 my $params = {
286 data => {
287 $data->%*,
288 },
289 };
290 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
291 '/obj/firewall/addrgrp/' . $name, $params);
292 }
293  
294  
295 ▶sub delete_firewall_address_group ($self, $name) {
Subroutine delete_firewall_address_group: not called CC=1 SCAR=6.9
Pod documented
296 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
297 '/obj/firewall/addrgrp/' . $name);
298 }
299  
300  
301 0 ▶sub list_firewall_ipv6_addresses ($self, $params = {}) {
Subroutine list_firewall_ipv6_addresses: not called CC=2 SCAR=17.9
Pod documented
302 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
303 '/obj/firewall/address6', $params);
304 }
305  
306  
307 0 ▶sub get_firewall_ipv6_address ($self, $name, $params = {}) {
Subroutine get_firewall_ipv6_address: not called CC=2 SCAR=17.9
Pod documented
308 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
309 '/obj/firewall/address6/'. $name, $params);
310 }
311  
312  
313 ▶sub create_firewall_ipv6_address ($self, $name, $data) {
Subroutine create_firewall_ipv6_address: not called CC=1 SCAR=6.9
Pod documented
314 0 my $params = {
315 data => [{
316 $data->%*,
317 name => $name,
318 }],
319 };
320 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
321 '/obj/firewall/address6', $params);
322 }
323  
324  
325 ▶sub update_firewall_ipv6_address ($self, $name, $data) {
Subroutine update_firewall_ipv6_address: not called CC=1 SCAR=6.9
Pod documented
326 0 my $params = {
327 data => {
328 $data->%*,
329 },
330 };
331 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
332 '/obj/firewall/address6/' . $name, $params);
333 }
334  
335  
336 ▶sub delete_firewall_ipv6_address ($self, $name) {
Subroutine delete_firewall_ipv6_address: not called CC=1 SCAR=6.9
Pod documented
337 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
338 '/obj/firewall/address6/' . $name);
339 }
340  
341  
342 0 ▶sub list_firewall_ipv6_address_groups ($self, $params = {}) {
Subroutine list_firewall_ipv6_address_groups: not called CC=2 SCAR=17.9
Pod documented
343 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
344 '/obj/firewall/addrgrp6', $params);
345 }
346  
347  
348 0 ▶sub get_firewall_ipv6_address_group ($self, $name, $params = {}) {
Subroutine get_firewall_ipv6_address_group: not called CC=2 SCAR=17.9
Pod documented
349 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
350 '/obj/firewall/addrgrp6/'. $name, $params);
351 }
352  
353  
354 ▶sub create_firewall_ipv6_address_group ($self, $name, $data) {
Subroutine create_firewall_ipv6_address_group: not called CC=1 SCAR=6.9
Pod documented
355 0 my $params = {
356 data => [{
357 $data->%*,
358 name => $name,
359 }],
360 };
361 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
362 '/obj/firewall/addrgrp6', $params);
363 }
364  
365  
366 ▶sub update_firewall_ipv6_address_group ($self, $name, $data) {
Subroutine update_firewall_ipv6_address_group: not called CC=1 SCAR=6.9
Pod documented
367 0 my $params = {
368 data => {
369 $data->%*,
370 },
371 };
372 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
373 '/obj/firewall/addrgrp6/' . $name, $params);
374 }
375  
376  
377 ▶sub delete_firewall_ipv6_address_group ($self, $name) {
Subroutine delete_firewall_ipv6_address_group: not called CC=1 SCAR=6.9
Pod documented
378 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
379 '/obj/firewall/addrgrp6/' . $name);
380 }
381  
382  
383 0 ▶sub list_firewall_services ($self, $params = {}) {
Subroutine list_firewall_services: not called CC=2 SCAR=17.9
Pod documented
384 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
385 '/obj/firewall/service/custom', $params);
386 }
387  
388  
389 0 ▶sub get_firewall_service ($self, $name, $params = {}) {
Subroutine get_firewall_service: not called CC=2 SCAR=17.9
Pod documented
390 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
391 '/obj/firewall/service/custom/'. $name, $params);
392 }
393  
394  
395 ▶sub create_firewall_service ($self, $name, $data) {
Subroutine create_firewall_service: not called CC=1 SCAR=6.9
Pod documented
396 0 my $params = {
397 data => [{
398 $data->%*,
399 name => $name,
400 }],
401 };
402 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
403 '/obj/firewall/service/custom', $params);
404 }
405  
406  
407 ▶sub update_firewall_service ($self, $name, $data) {
Subroutine update_firewall_service: not called CC=1 SCAR=6.9
Pod documented
408 0 my $params = {
409 data => {
410 $data->%*,
411 },
412 };
413 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
414 '/obj/firewall/service/custom/' . $name, $params);
415 }
416  
417  
418 ▶sub delete_firewall_service ($self, $name) {
Subroutine delete_firewall_service: not called CC=1 SCAR=6.9
Pod documented
419 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
420 '/obj/firewall/service/custom/' . $name);
421 }
422  
423  
424 0 ▶sub list_firewall_service_groups ($self, $params = {}) {
Subroutine list_firewall_service_groups: not called CC=2 SCAR=17.9
Pod documented
425 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
426 '/obj/firewall/service/group', $params);
427 }
428  
429  
430 0 ▶sub get_firewall_service_group ($self, $name, $params = {}) {
Subroutine get_firewall_service_group: not called CC=2 SCAR=17.9
Pod documented
431 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
432 '/obj/firewall/service/group/'. $name, $params);
433 }
434  
435  
436 ▶sub create_firewall_service_group ($self, $name, $data) {
Subroutine create_firewall_service_group: not called CC=1 SCAR=6.9
Pod documented
437 0 my $params = {
438 data => [{
439 $data->%*,
440 name => $name,
441 }],
442 };
443 0 $self->exec_method('set', '/pm/config/adom/' . $self->adom .
444 '/obj/firewall/service/group', $params);
445 }
446  
447  
448 ▶sub update_firewall_service_group ($self, $name, $data) {
Subroutine update_firewall_service_group: not called CC=1 SCAR=6.9
Pod documented
449 0 my $params = {
450 data => {
451 $data->%*,
452 },
453 };
454 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
455 '/obj/firewall/service/group/' . $name, $params);
456 }
457  
458  
459 ▶sub delete_firewall_service_group ($self, $name) {
Subroutine delete_firewall_service_group: not called CC=1 SCAR=6.9
Pod documented
460 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
461 '/obj/firewall/service/group/' . $name);
462 }
463  
464  
465 0 ▶sub list_policy_packages ($self, $params = {}) {
Subroutine list_policy_packages: not called CC=2 SCAR=17.9
Pod documented
466 0 $self->exec_method('get', '/pm/pkg/adom/' . $self->adom, $params);
467 }
468  
469  
470 0 ▶sub get_policy_package ($self, $name, $params = {}) {
Subroutine get_policy_package: not called CC=2 SCAR=17.9
Pod documented
471 0 $self->exec_method('get', '/pm/pkg/adom/' . $self->adom . '/'. $name,
472 $params);
473 }
474  
475  
476 ▶sub create_policy_package ($self, $name, $data) {
Subroutine create_policy_package: not called CC=1 SCAR=6.9
Pod documented
477 0 my $params = {
478 data => [{
479 $data->%*,
480 name => $name,
481 }],
482 };
483 0 $self->exec_method('add', '/pm/pkg/adom/' . $self->adom, $params);
484 }
485  
486  
487 ▶sub update_policy_package ($self, $name, $data) {
Subroutine update_policy_package: not called CC=1 SCAR=6.9
Pod documented
488 0 my $params = {
489 data => {
490 $data->%*,
491 },
492 };
493 0 $self->exec_method('update', '/pm/pkg/adom/' . $self->adom . '/' . $name,
494 $params);
495 }
496  
497  
498 ▶sub delete_policy_package ($self, $name) {
Subroutine delete_policy_package: not called CC=1 SCAR=6.9
Pod documented
499 0 $self->exec_method('delete', '/pm/pkg/adom/' . $self->adom . '/' . $name);
500 }
501  
502  
503 ▶sub install_policy_package ($self, $name, $data) {
Subroutine install_policy_package: not called CC=1 SCAR=6.9
Pod documented
504 0 my $params = {
505 data => {
506 $data->%*,
507 adom => $self->adom,
508 pkg => $name,
509 },
510 };
511 0 $self->exec_method('exec', '/securityconsole/install/package',
512 $params);
513 }
514  
515  
516 0 ▶sub list_tasks ($self, $params = {}) {
Subroutine list_tasks: not called CC=2 SCAR=17.9
Pod documented
517 0 $self->exec_method('get', '/task/task', $params);
518 }
519  
520  
521 0 ▶sub get_task ($self, $id, $params = {}) {
Subroutine get_task: not called CC=2 SCAR=17.9
Pod documented
522 0 $self->exec_method('get', '/task/task/' . $id, $params);
523 }
524  
525  
526 0 ▶sub list_firewall_policies ($self, $pkg, $params = {}) {
Subroutine list_firewall_policies: not called CC=2 SCAR=17.9
Pod documented
527 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
528 '/pkg/' . $pkg . '/firewall/policy', $params);
529 }
530  
531  
532 0 ▶sub get_firewall_policy ($self, $pkg, $id, $params = {}) {
Subroutine get_firewall_policy: not called CC=2 SCAR=17.9
Pod documented
533 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
534 '/pkg/' . $pkg . '/firewall/policy/' . $id, $params);
535 }
536  
537  
538 ▶sub create_firewall_policy ($self, $pkg, $data) {
Subroutine create_firewall_policy: not called CC=1 SCAR=6.9
Pod documented
539 0 my $params = {
540 data => [{
541 $data->%*,
542 }],
543 };
544 0 $self->exec_method('add', '/pm/config/adom/' . $self->adom .
545 '/pkg/' . $pkg . '/firewall/policy', $params);
546 }
547  
548  
549 ▶sub update_firewall_policy ($self, $pkg, $id, $data) {
Subroutine update_firewall_policy: not called CC=1 SCAR=6.9
Pod documented
550 0 my $params = {
551 data => {
552 $data->%*,
553 },
554 };
555 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
556 '/pkg/' . $pkg . '/firewall/policy/' . $id , $params);
557 }
558  
559  
560 ▶sub delete_firewall_policy ($self, $pkg, $id) {
Subroutine delete_firewall_policy: not called CC=1 SCAR=6.9
Pod documented
561 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
562 '/pkg/' . $pkg . '/firewall/policy/' . $id);
563 }
564  
565  
566 0 ▶sub list_firewall_security_policies ($self, $pkg, $params = {}) {
Subroutine list_firewall_security_policies: not called CC=2 SCAR=17.9
Pod documented
567 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
568 '/pkg/' . $pkg . '/firewall/security-policy', $params);
569 }
570  
571  
572 0 ▶sub get_firewall_security_policy ($self, $pkg, $id, $params = {}) {
Subroutine get_firewall_security_policy: not called CC=2 SCAR=17.9
Pod documented
573 0 $self->exec_method('get', '/pm/config/adom/' . $self->adom .
574 '/pkg/' . $pkg . '/firewall/security-policy/' . $id, $params);
575 }
576  
577  
578  
579 ▶sub create_firewall_security_policy ($self, $pkg, $data) {
Subroutine create_firewall_security_policy: not called CC=1 SCAR=6.9
Pod documented
580 0 my $params = {
581 data => [{
582 $data->%*,
583 }],
584 };
585 0 $self->exec_method('add', '/pm/config/adom/' . $self->adom .
586 '/pkg/' . $pkg . '/firewall/security-policy', $params);
587 }
588  
589  
590 ▶sub update_firewall_security_policy ($self, $pkg, $id, $data) {
Subroutine update_firewall_security_policy: not called CC=1 SCAR=6.9
Pod documented
591 0 my $params = {
592 data => {
593 $data->%*,
594 },
595 };
596 0 $self->exec_method('update', '/pm/config/adom/' . $self->adom .
597 '/pkg/' . $pkg . '/firewall/security-policy/' . $id , $params);
598 }
599  
600  
601 ▶sub delete_firewall_security_policy ($self, $pkg, $id) {
Subroutine delete_firewall_security_policy: not called CC=1 SCAR=6.9
Pod documented
602 0 $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
603 '/pkg/' . $pkg . '/firewall/security-policy/' . $id);
604 }
605  
606 2 1;
607  
608 __END__
609  
610 =pod
611  
612 =encoding UTF-8
613  
614 =head1 NAME
615  
616 Net::Fortinet::FortiManager - Fortinet FortiManager REST API client library
617  
618 =head1 VERSION
619  
620 version 0.001000
621  
622 =head1 SYNOPSIS
623  
624 use strict;
625 use warnings;
626 use Net::Fortinet::FortiManager;
627  
628 my $fortimanager = Net::Fortinet::FortiManager->new(
629 server => 'https://fortimanager.example.com',
630 user => 'username',
631 passwd => '$password',
632 clientattrs => {
633 timeout => 10,
634 },
635 );
636  
637 $fortimanager->login;
638  
639 $fortimanager->adom('adomname');
640  
641 =head1 DESCRIPTION
642  
643 This module is a client library for the Fortigate FortiManager JSONRPC-like
644 API.
645 Currently it is developed and tested against version 6.4.6.
646 All requests have the verbose parameter set to 1 to ensure that enums return
647 their strings instead of undocumented ids.
648  
649 =head1 ATTRIBUTES
650  
651 =head2 adoms
652  
653 Returns a list of hashrefs containing name and uuid of all ADOMs which gets
654 populated by L</login>.
655  
656 =head2 adom
657  
658 The name of the ADOM which is used by all methods.
659 Defaults to 'root'.
660  
661 =head1 METHODS
662  
663 =head2 exec_method
664  
665 Executes a method with the specified parameters.
666  
667 Returns its response.
668  
669 This is the lowest level method which can be used to execute every API action
670 that's available.
671 It does the http and JSONRPC error handling and extraction of the result
672 from the JSONRPC response.
673  
674 =head2 exec_method_multi
675  
676 Executes a method with multiple specified parameters.
677  
678 Returns its responses.
679  
680 This is also a low level method which can be used to execute multiple API
681 actions in a single JSONRPC call.
682 The only restriction of the JSONRPC API is that all actions need to use the
683 same method.
684 It does the http and JSONRPC error handling and extraction of the results
685 from the JSONRPC response.
686  
687 =head2 login
688  
689 Logs into the Fortinet FortiManager.
690  
691 =head2 logout
692  
693 Logs out of the Fortinet FortiManager.
694  
695 =head2 get_sys_status
696  
697 Returns /sys/status.
698  
699 =head2 list_adoms
700  
701 Returns an arrayref of ADOMs by name.
702  
703 =head2 list_firewall_addresses
704  
705 Returns an arrayref of firewall addresses.
706  
707 =head2 get_firewall_address
708  
709 Takes a firewall address name and an optional parameter hashref.
710  
711 Returns its data as a hashref.
712  
713 =head2 create_firewall_address
714  
715 Takes a firewall address name and a hashref of address config.
716  
717 Returns true on success.
718  
719 Throws an exception on error.
720  
721 =head2 update_firewall_address
722  
723 Takes a firewall address name and a hashref of address config.
724  
725 Returns true on success.
726  
727 Throws an exception on error.
728  
729 =head2 delete_firewall_address
730  
731 Takes a firewall address name.
732  
733 Returns true on success.
734  
735 Throws an exception on error.
736  
737 =head2 list_firewall_address_groups
738  
739 Returns an arrayref of firewall address groups.
740  
741 =head2 get_firewall_address_group
742  
743 Takes a firewall address group name and an optional parameter hashref.
744  
745 Returns its data as a hashref.
746  
747 =head2 create_firewall_address_group
748  
749 Takes a firewall address group name and a hashref of address group config.
750  
751 Returns true on success.
752  
753 Throws an exception on error.
754  
755 =head2 update_firewall_address_group
756  
757 Takes a firewall address group name and a hashref of address group config.
758  
759 Returns true on success.
760  
761 Throws an exception on error.
762  
763 =head2 delete_firewall_address_group
764  
765 Takes a firewall address group name.
766  
767 Returns true on success.
768  
769 Throws an exception on error.
770  
771 =head2 list_firewall_ipv6_addresses
772  
773 Returns an arrayref of firewall IPv6 addresses.
774  
775 =head2 get_firewall_ipv6_address
776  
777 Takes a firewall IPv6 address name and an optional parameter hashref.
778  
779 Returns its data as a hashref.
780  
781 =head2 create_firewall_ipv6_address
782  
783 Takes a firewall IPv6 address name and a hashref of address config.
784  
785 Returns true on success.
786  
787 Throws an exception on error.
788  
789 =head2 update_firewall_ipv6_address
790  
791 Takes a firewall IPv6 address name and a hashref of address config.
792  
793 Returns true on success.
794  
795 Throws an exception on error.
796  
797 =head2 delete_firewall_ipv6_address
798  
799 Takes a firewall IPv6 address name.
800  
801 Returns true on success.
802  
803 Throws an exception on error.
804  
805 =head2 list_firewall_ipv6_address_groups
806  
807 Returns an arrayref of firewall IPv6 address groups.
808  
809 =head2 get_firewall_ipv6_address_group
810  
811 Takes a firewall IPv6 address group name and an optional parameter hashref.
812  
813 Returns its data as a hashref.
814  
815 =head2 create_firewall_ipv6_address_group
816  
817 Takes a firewall IPv6 address group name and a hashref of address group config.
818  
819 Returns true on success.
820  
821 Throws an exception on error.
822  
823 =head2 update_firewall_ipv6_address_group
824  
825 Takes a firewall IPv6 address group name and a hashref of address group config.
826  
827 Returns true on success.
828  
829 Throws an exception on error.
830  
831 =head2 delete_firewall_ipv6_address_group
832  
833 Takes a firewall IPv6 address group name.
834  
835 Returns true on success.
836  
837 Throws an exception on error.
838  
839 =head2 list_firewall_services
840  
841 Returns an arrayref of firewall services.
842  
843 =head2 get_firewall_service
844  
845 Takes a firewall service name and an optional parameter hashref.
846  
847 Returns its data as a hashref.
848  
849 =head2 create_firewall_service
850  
851 Takes a firewall service name and a hashref of service config.
852  
853 Returns true on success.
854  
855 Throws an exception on error.
856  
857 =head2 update_firewall_service
858  
859 Takes a firewall service name and a hashref of service config.
860  
861 Returns true on success.
862  
863 Throws an exception on error.
864  
865 =head2 delete_firewall_service
866  
867 Takes a firewall service name.
868  
869 Returns true on success.
870  
871 Throws an exception on error.
872  
873 =head2 list_firewall_service_groups
874  
875 Returns an arrayref of firewall service groups.
876  
877 =head2 get_firewall_service_group
878  
879 Takes a firewall service group name and an optional parameter hashref.
880  
881 Returns its data as a hashref.
882  
883 =head2 create_firewall_service_group
884  
885 Takes a firewall service group name and a hashref of service group config.
886  
887 Returns true on success.
888  
889 Throws an exception on error.
890  
891 =head2 update_firewall_service_group
892  
893 Takes a firewall service group name and a hashref of service group config.
894  
895 Returns true on success.
896  
897 Throws an exception on error.
898  
899 =head2 delete_firewall_service_group
900  
901 Takes a firewall service group name.
902  
903 Returns true on success.
904  
905 Throws an exception on error.
906  
907 =head2 list_policy_packages
908  
909 Takes optional parameters.
910  
911 Returns an arrayref of firewall policies.
912  
913 =head2 get_policy_package
914  
915 Takes a policy package name and an optional parameter hashref.
916  
917 Returns its data as a hashref.
918  
919 =head2 create_policy_package
920  
921 Takes a policy package name and a hashref of attributes.
922  
923 Returns true on success.
924  
925 Throws an exception on error.
926  
927 The firewall policies are configured depending on the 'ngfw-mode'.
928 For profile-based policy packages you have to use the 'policy' methods,
929 for policy-based the 'security_policy' methods.
930  
931 =head2 update_policy_package
932  
933 Takes a policy package name and a hashref of attributes.
934  
935 Returns true on success.
936  
937 Throws an exception on error.
938  
939 =head2 delete_policy_package
940  
941 Takes a policy package name.
942  
943 Returns true on success.
944  
945 Throws an exception on error.
946  
947 =head2 install_policy_package
948  
949 Takes a policy package name and a hashref of parameters.
950  
951 Returns true on success.
952  
953 Throws an exception on error.
954  
955 =head2 list_tasks
956  
957 Takes optional parameters.
958  
959 Returns an arrayref of tasks.
960  
961 =head2 get_task
962  
963 Takes a task id and an optional parameter hashref.
964  
965 Returns its data as a hashref.
966  
967 =head2 list_firewall_policies
968  
969 Takes a package name and optional parameters.
970  
971 Returns an arrayref of firewall policies.
972  
973 =head2 get_firewall_policy
974  
975 Takes a policy package name, a firewall policy id and an optional parameter
976 hashref.
977  
978 Returns its data as a hashref.
979  
980 =head2 create_firewall_policy
981  
982 Takes a policy package name and a hashref of firewall policy attributes.
983  
984 Returns the response data from the API on success which is a hashref
985 containing only the policyid.
986  
987 Throws an exception on error.
988  
989 =head2 update_firewall_policy
990  
991 Takes a policy package name, a firewall policy id and a hashref of firewall
992 policy attributes.
993  
994 Returns the response data from the API on success which is a hashref
995 containing only the policyid.
996  
997 Throws an exception on error.
998  
999 =head2 delete_firewall_policy
1000  
1001 Takes a policy package name and a firewall policy id.
1002  
1003 Returns true on success.
1004  
1005 Throws an exception on error.
1006  
1007 =head2 list_firewall_security_policies
1008  
1009 Takes a package name and optional parameters.
1010  
1011 Returns an arrayref of firewall security policies.
1012  
1013 =head2 get_firewall_security_policy
1014  
1015 Takes a policy package name, a firewall security policy id and an optional
1016 parameter hashref.
1017  
1018 Returns its data as a hashref.
1019  
1020 =head2 create_firewall_security_policy
1021  
1022 Takes a policy package name and a hashref of firewall security policy
1023 attributes.
1024  
1025 Returns the response data from the API on success which is a hashref
1026 containing only the policyid.
1027  
1028 Throws an exception on error.
1029  
1030 =head2 update_firewall_security_policy
1031  
1032 Takes a policy package name, a firewall security policy id and a hashref of
1033 firewall security policy attributes.
1034  
1035 Returns the response data from the API on success which is a hashref
1036 containing only the policyid.
1037  
1038 Throws an exception on error.
1039  
1040 =head2 delete_firewall_security_policy
1041  
1042 Takes a policy package name and a firewall security policy id.
1043  
1044 Returns true on success.
1045  
1046 Throws an exception on error.
1047  
1048 =for Pod::Coverage has_user has_passwd has_api_key
1049  
1050 =head1 AUTHOR
1051  
1052 Alexander Hartmaier <abraxxa@cpan.org>
1053  
1054 =head1 COPYRIGHT AND LICENSE
1055  
1056 This software is copyright (c) 2022 by Alexander Hartmaier.
1057  
1058 This is free software; you can redistribute it and/or modify it under
1059 the same terms as the Perl 5 programming language system itself.
1060  
1061 =cut
↑ Summary