File Coverage

blib/lib/Net/Fortinet/FortiManager.pm
Criterion Covered Total %
statement 23 475 4.8
branch 0 42 0.0
condition 0 30 0.0
subroutine 8 77 10.3
pod 62 62 100.0
total 93 686 13.5


line stmt bran cond sub pod time code
1             package Net::Fortinet::FortiManager;
2             $Net::Fortinet::FortiManager::VERSION = '0.004001';
3             # ABSTRACT: Fortinet FortiManager REST API client library
4              
5 2     2   583046 use 5.024;
  2         10  
6 2     2   1476 use Moo;
  2         26296  
  2         16  
7 2     2   4224 use feature 'signatures';
  2         6  
  2         456  
8 2     2   1777 use Types::Standard qw( ArrayRef HashRef InstanceOf Str );
  2         348459  
  2         43  
9 2     2   11591 use Types::Common::Numeric qw( PositiveInt );
  2         78147  
  2         25  
10 2     2   1996 use Carp qw( croak );
  2         5  
  2         173  
11 2     2   12 use List::Util qw( all any none );
  2         5  
  2         190  
12              
13 2     2   21 no warnings "experimental::signatures";
  2         3  
  2         11625  
14              
15              
16             has 'user' => (
17             isa => Str,
18             is => 'rw',
19             predicate => 1,
20             );
21              
22             has 'passwd' => (
23             isa => Str,
24             is => 'rw',
25             predicate => 1,
26             );
27              
28             has '_sessionid' => (
29             isa => Str,
30             is => 'rw',
31             predicate => 1,
32             clearer => 1,
33             );
34              
35             has '_last_transaction_id' => (
36             isa => PositiveInt,
37             is => 'rw',
38             predicate => 1,
39             clearer => 1,
40             );
41              
42 0     0     sub _get_transaction_id ($self) {
  0            
  0            
43 0           my $id;
44 0 0         if ($self->_has_last_transaction_id) {
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             has 'adoms' => (
58             is => 'rwp',
59             isa => ArrayRef[Str],
60             );
61              
62              
63             has 'adom' => (
64             is => 'rw',
65             isa => Str,
66             default => sub { 'root' },
67             );
68              
69             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 0     0     sub _http_error_handler ($self, $res) {
  0            
  0            
  0            
79 0 0         croak('http error (' . $res->code . '): ' . $res->response->decoded_content)
80             unless $res->code == 200;
81             }
82              
83 0     0     sub _rpc_error_handler ($self, $res, $number_of_expected_results) {
  0            
  0            
  0            
  0            
84 0 0 0       if (ref $res->data eq 'HASH'
      0        
      0        
      0        
85             && exists $res->data->{result}
86             && ref $res->data->{result} eq 'ARRAY'
87             && scalar $res->data->{result}->@* == $number_of_expected_results
88 0     0     && all { ref $_ eq 'HASH' } $res->data->{result}->@* ) {
89 0 0         if ($number_of_expected_results == 1) {
90 0           my $code = $res->data->{result}->[0]->{status}->{code};
91 0           my $message = $res->data->{result}->[0]->{status}->{message};
92 0 0         if ($code != 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 0         if (@failed_calls) {
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     0     sub _exec_method ($self, $method, $params = undef) {
  0            
  0            
  0            
  0            
116 0 0 0       croak 'params needs to be an arrayref'
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 0         $body->{session} = $self->_sessionid
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 0         $self->_rpc_error_handler($res, defined $params ? scalar $params->@* : 1);
135              
136 0           return $res;
137             }
138              
139              
140 0     0 1   sub exec_method ($self, $method, $url, $params = undef) {
  0            
  0            
  0            
  0            
  0            
141 0 0 0       croak 'params needs to be a hashref'
142             if defined $params && ref $params ne 'HASH';
143              
144 0 0         my %full_params = defined $params
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 0         if (exists $rv->{result}[0]->{data}) {
153 0           return $rv->{result}[0]->{data};
154             }
155 0           return 1;
156             }
157              
158              
159 0     0 1   sub exec_method_multi ($self, $method, $params) {
  0            
  0            
  0            
  0            
160 0 0         croak 'params needs to be an arrayref'
161             unless ref $params eq 'ARRAY';
162              
163             croak 'each parameter needs to be a hashref'
164 0 0   0     unless any { ref $_ eq 'HASH' } $params->@*;
  0            
165              
166 0           my $rv = $self->_exec_method($method, $params)->data;
167              
168 0 0         if (exists $rv->{result}) {
169 0           return $rv->{result};
170             }
171 0           return 1;
172             }
173              
174              
175 0     0 1   sub login ($self) {
  0            
  0            
176 0 0 0       die "user and password required\n"
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_by_name);
190              
191             # switch to first ADOM if the currently set ADOM isn't available
192 0 0   0     if (none { $_ eq $self->adom } $self->adoms->@*) {
  0            
193 0           $self->adom($self->adoms->[0]);
194             }
195              
196 0           return 1;
197             }
198              
199              
200 0     0 1   sub logout ($self) {
  0            
  0            
201 0           $self->exec_method('exec', '/sys/logout');
202 0           $self->_clear_sessionid;
203 0           $self->_clear_last_transaction_id;
204              
205 0           return 1;
206             }
207              
208              
209 0     0 1   sub get_sys_status ($self) {
  0            
  0            
210 0           return $self->exec_method('get', '/sys/status');
211             }
212              
213              
214 0     0 1   sub has_firewall_service_udp_lite_support ($self) {
  0            
  0            
215 0           state $rv;
216 0 0         return $rv
217             if defined $rv;
218              
219 0           my $sys_status = $self->get_sys_status;
220              
221 0           my $major_version = $sys_status->{Major};
222 0           my $minor_version = $sys_status->{Minor};
223              
224 0   0       $rv = ($major_version == 7 && $minor_version >= 6)
225             || $major_version > 7;
226              
227 0           return $rv;
228             }
229              
230              
231 0     0 1   sub list_adoms ($self, $params = {}) {
  0            
  0            
  0            
232 0           $self->exec_method('get', '/dvmdb/adom', $params);
233             }
234              
235              
236 0     0 1   sub list_adoms_by_name ($self) {
  0            
  0            
237             my @adoms =
238             sort
239             map {
240 0           $_->{name}
241 0           } $self->list_adoms({
242             fields => [qw( name )],
243             })->@*;
244 0           return \@adoms;
245             }
246              
247              
248 0     0 1   sub list_firewall_addresses ($self, $params = {}) {
  0            
  0            
  0            
249 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
250             '/obj/firewall/address', $params);
251             }
252              
253              
254 0     0 1   sub get_firewall_address ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
255 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
256             '/obj/firewall/address/'. $name, $params);
257             }
258              
259              
260 0     0 1   sub create_firewall_address ($self, $name, $data) {
  0            
  0            
  0            
  0            
261 0           my $params = {
262             data => [{
263             $data->%*,
264             name => $name,
265             }],
266             };
267 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
268             '/obj/firewall/address', $params);
269             }
270              
271              
272 0     0 1   sub update_firewall_address ($self, $name, $data) {
  0            
  0            
  0            
  0            
273 0           my $params = {
274             data => {
275             $data->%*,
276             },
277             };
278 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
279             '/obj/firewall/address/' . $name, $params);
280             }
281              
282              
283 0     0 1   sub delete_firewall_address ($self, $name) {
  0            
  0            
  0            
284 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
285             '/obj/firewall/address/' . $name);
286             }
287              
288              
289 0     0 1   sub list_firewall_address_groups ($self, $params = {}) {
  0            
  0            
  0            
290 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
291             '/obj/firewall/addrgrp', $params);
292             }
293              
294              
295 0     0 1   sub get_firewall_address_group ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
296 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
297             '/obj/firewall/addrgrp/'. $name, $params);
298             }
299              
300              
301 0     0 1   sub create_firewall_address_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
302 0           my $params = {
303             data => [{
304             $data->%*,
305             name => $name,
306             }],
307             };
308 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
309             '/obj/firewall/addrgrp', $params);
310             }
311              
312              
313 0     0 1   sub update_firewall_address_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
314 0           my $params = {
315             data => {
316             $data->%*,
317             },
318             };
319 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
320             '/obj/firewall/addrgrp/' . $name, $params);
321             }
322              
323              
324 0     0 1   sub delete_firewall_address_group ($self, $name) {
  0            
  0            
  0            
325 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
326             '/obj/firewall/addrgrp/' . $name);
327             }
328              
329              
330 0     0 1   sub list_firewall_ipv6_addresses ($self, $params = {}) {
  0            
  0            
  0            
331 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
332             '/obj/firewall/address6', $params);
333             }
334              
335              
336 0     0 1   sub get_firewall_ipv6_address ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
337 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
338             '/obj/firewall/address6/'. $name, $params);
339             }
340              
341              
342 0     0 1   sub create_firewall_ipv6_address ($self, $name, $data) {
  0            
  0            
  0            
  0            
343 0           my $params = {
344             data => [{
345             $data->%*,
346             name => $name,
347             }],
348             };
349 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
350             '/obj/firewall/address6', $params);
351             }
352              
353              
354 0     0 1   sub update_firewall_ipv6_address ($self, $name, $data) {
  0            
  0            
  0            
  0            
355 0           my $params = {
356             data => {
357             $data->%*,
358             },
359             };
360 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
361             '/obj/firewall/address6/' . $name, $params);
362             }
363              
364              
365 0     0 1   sub delete_firewall_ipv6_address ($self, $name) {
  0            
  0            
  0            
366 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
367             '/obj/firewall/address6/' . $name);
368             }
369              
370              
371 0     0 1   sub list_firewall_ipv6_address_groups ($self, $params = {}) {
  0            
  0            
  0            
372 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
373             '/obj/firewall/addrgrp6', $params);
374             }
375              
376              
377 0     0 1   sub get_firewall_ipv6_address_group ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
378 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
379             '/obj/firewall/addrgrp6/'. $name, $params);
380             }
381              
382              
383 0     0 1   sub create_firewall_ipv6_address_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
384 0           my $params = {
385             data => [{
386             $data->%*,
387             name => $name,
388             }],
389             };
390 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
391             '/obj/firewall/addrgrp6', $params);
392             }
393              
394              
395 0     0 1   sub update_firewall_ipv6_address_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
396 0           my $params = {
397             data => {
398             $data->%*,
399             },
400             };
401 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
402             '/obj/firewall/addrgrp6/' . $name, $params);
403             }
404              
405              
406 0     0 1   sub delete_firewall_ipv6_address_group ($self, $name) {
  0            
  0            
  0            
407 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
408             '/obj/firewall/addrgrp6/' . $name);
409             }
410              
411              
412 0     0 1   sub list_firewall_wildcard_fqdns ($self, $params = {}) {
  0            
  0            
  0            
413 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
414             '/obj/firewall/wildcard-fqdn/custom', $params);
415             }
416              
417              
418 0     0 1   sub get_firewall_wildcard_fqdn ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
419 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
420             '/obj/firewall/wildcard-fqdn/custom/'. $name, $params);
421             }
422              
423              
424 0     0 1   sub create_firewall_wildcard_fqdn ($self, $name, $data) {
  0            
  0            
  0            
  0            
425 0           my $params = {
426             data => [{
427             $data->%*,
428             name => $name,
429             }],
430             };
431 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
432             '/obj/firewall/wildcard-fqdn/custom', $params);
433             }
434              
435              
436 0     0 1   sub update_firewall_wildcard_fqdn ($self, $name, $data) {
  0            
  0            
  0            
  0            
437 0           my $params = {
438             data => {
439             $data->%*,
440             },
441             };
442 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
443             '/obj/firewall/wildcard-fqdn/custom/' . $name, $params);
444             }
445              
446              
447 0     0 1   sub delete_firewall_wildcard_fqdn ($self, $name) {
  0            
  0            
  0            
448 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
449             '/obj/firewall/wildcard-fqdn/custom/' . $name);
450             }
451              
452              
453 0     0 1   sub list_firewall_services ($self, $params = {}) {
  0            
  0            
  0            
454 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
455             '/obj/firewall/service/custom', $params);
456             }
457              
458              
459 0     0 1   sub get_firewall_service ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
460 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
461             '/obj/firewall/service/custom/'. $name, $params);
462             }
463              
464              
465 0     0 1   sub create_firewall_service ($self, $name, $data) {
  0            
  0            
  0            
  0            
466 0           my $params = {
467             data => [{
468             $data->%*,
469             name => $name,
470             }],
471             };
472 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
473             '/obj/firewall/service/custom', $params);
474             }
475              
476              
477 0     0 1   sub update_firewall_service ($self, $name, $data) {
  0            
  0            
  0            
  0            
478 0           my $params = {
479             data => {
480             $data->%*,
481             },
482             };
483 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
484             '/obj/firewall/service/custom/' . $name, $params);
485             }
486              
487              
488 0     0 1   sub delete_firewall_service ($self, $name) {
  0            
  0            
  0            
489 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
490             '/obj/firewall/service/custom/' . $name);
491             }
492              
493              
494 0     0 1   sub list_firewall_service_groups ($self, $params = {}) {
  0            
  0            
  0            
495 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
496             '/obj/firewall/service/group', $params);
497             }
498              
499              
500 0     0 1   sub get_firewall_service_group ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
501 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
502             '/obj/firewall/service/group/'. $name, $params);
503             }
504              
505              
506 0     0 1   sub create_firewall_service_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
507 0           my $params = {
508             data => [{
509             $data->%*,
510             name => $name,
511             }],
512             };
513 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
514             '/obj/firewall/service/group', $params);
515             }
516              
517              
518 0     0 1   sub update_firewall_service_group ($self, $name, $data) {
  0            
  0            
  0            
  0            
519 0           my $params = {
520             data => {
521             $data->%*,
522             },
523             };
524 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
525             '/obj/firewall/service/group/' . $name, $params);
526             }
527              
528              
529 0     0 1   sub delete_firewall_service_group ($self, $name) {
  0            
  0            
  0            
530 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
531             '/obj/firewall/service/group/' . $name);
532             }
533              
534              
535 0     0 1   sub list_policy_packages ($self, $params = {}) {
  0            
  0            
  0            
536 0           $self->exec_method('get', '/pm/pkg/adom/' . $self->adom, $params);
537             }
538              
539              
540 0     0 1   sub get_policy_package ($self, $name, $params = {}) {
  0            
  0            
  0            
  0            
541 0           $self->exec_method('get', '/pm/pkg/adom/' . $self->adom . '/'. $name,
542             $params);
543             }
544              
545              
546 0     0 1   sub create_policy_package ($self, $name, $data) {
  0            
  0            
  0            
  0            
547 0           my $params = {
548             data => [{
549             $data->%*,
550             name => $name,
551             }],
552             };
553 0           $self->exec_method('add', '/pm/pkg/adom/' . $self->adom, $params);
554             }
555              
556              
557 0     0 1   sub update_policy_package ($self, $name, $data) {
  0            
  0            
  0            
  0            
558 0           my $params = {
559             data => {
560             $data->%*,
561             },
562             };
563 0           $self->exec_method('update', '/pm/pkg/adom/' . $self->adom . '/' . $name,
564             $params);
565             }
566              
567              
568 0     0 1   sub delete_policy_package ($self, $name) {
  0            
  0            
  0            
569 0           $self->exec_method('delete', '/pm/pkg/adom/' . $self->adom . '/' . $name);
570             }
571              
572              
573 0     0 1   sub install_policy_package ($self, $name, $data = {}) {
  0            
  0            
  0            
  0            
574 0           my $params = {
575             data => {
576             $data->%*,
577             adom => $self->adom,
578             pkg => $name,
579             },
580             };
581 0           my $res = $self->exec_method('exec', '/securityconsole/install/package',
582             $params);
583              
584 0           return $res->{task};
585             }
586              
587              
588 0     0 1   sub list_tasks ($self, $params = {}) {
  0            
  0            
  0            
589 0           $self->exec_method('get', '/task/task', $params);
590             }
591              
592              
593 0     0 1   sub get_task ($self, $id, $params = {}) {
  0            
  0            
  0            
  0            
594 0           $self->exec_method('get', '/task/task/' . $id, $params);
595             }
596              
597              
598 0     0 1   sub wait_for_task($self, $taskid, $callback = undef) {
  0            
  0            
  0            
  0            
599 0 0         croak "task-id missing"
600             unless defined $taskid;
601 0 0 0       croak "callback must be a coderef"
602             if defined $callback && ref $callback ne 'CODE';
603              
604 0           my $task;
605 0   0       while (($task = $self->get_task($taskid))
606             && $task->{percent} != 100) {
607 0 0         &$callback($task)
608             if defined $callback;
609 0           sleep 1;
610             }
611 0           return $task;
612             }
613              
614              
615 0     0 1   sub list_firewall_policies ($self, $pkg, $params = {}) {
  0            
  0            
  0            
  0            
616 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
617             '/pkg/' . $pkg . '/firewall/policy', $params);
618             }
619              
620              
621 0     0 1   sub get_firewall_policy ($self, $pkg, $id, $params = {}) {
  0            
  0            
  0            
  0            
  0            
622 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
623             '/pkg/' . $pkg . '/firewall/policy/' . $id, $params);
624             }
625              
626              
627 0     0 1   sub create_firewall_policy ($self, $pkg, $data) {
  0            
  0            
  0            
  0            
628 0           my $params = {
629             data => [{
630             $data->%*,
631             }],
632             };
633 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
634             '/pkg/' . $pkg . '/firewall/policy', $params);
635             }
636              
637              
638 0     0 1   sub update_firewall_policy ($self, $pkg, $id, $data) {
  0            
  0            
  0            
  0            
  0            
639 0           my $params = {
640             data => {
641             $data->%*,
642             },
643             };
644 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
645             '/pkg/' . $pkg . '/firewall/policy/' . $id , $params);
646             }
647              
648              
649 0     0 1   sub delete_firewall_policy ($self, $pkg, $id) {
  0            
  0            
  0            
  0            
650 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
651             '/pkg/' . $pkg . '/firewall/policy/' . $id);
652             }
653              
654              
655 0     0 1   sub list_firewall_security_policies ($self, $pkg, $params = {}) {
  0            
  0            
  0            
  0            
656 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
657             '/pkg/' . $pkg . '/firewall/security-policy', $params);
658             }
659              
660              
661 0     0 1   sub get_firewall_security_policy ($self, $pkg, $id, $params = {}) {
  0            
  0            
  0            
  0            
  0            
662 0           $self->exec_method('get', '/pm/config/adom/' . $self->adom .
663             '/pkg/' . $pkg . '/firewall/security-policy/' . $id, $params);
664             }
665              
666              
667              
668 0     0 1   sub create_firewall_security_policy ($self, $pkg, $data) {
  0            
  0            
  0            
  0            
669 0           my $params = {
670             data => [{
671             $data->%*,
672             }],
673             };
674 0           $self->exec_method('add', '/pm/config/adom/' . $self->adom .
675             '/pkg/' . $pkg . '/firewall/security-policy', $params);
676             }
677              
678              
679 0     0 1   sub update_firewall_security_policy ($self, $pkg, $id, $data) {
  0            
  0            
  0            
  0            
  0            
680 0           my $params = {
681             data => {
682             $data->%*,
683             },
684             };
685 0           $self->exec_method('update', '/pm/config/adom/' . $self->adom .
686             '/pkg/' . $pkg . '/firewall/security-policy/' . $id , $params);
687             }
688              
689              
690 0     0 1   sub delete_firewall_security_policy ($self, $pkg, $id) {
  0            
  0            
  0            
  0            
691 0           $self->exec_method('delete', '/pm/config/adom/' . $self->adom .
692             '/pkg/' . $pkg . '/firewall/security-policy/' . $id);
693             }
694              
695              
696             1;
697              
698             __END__
699              
700             =pod
701              
702             =encoding UTF-8
703              
704             =head1 NAME
705              
706             Net::Fortinet::FortiManager - Fortinet FortiManager REST API client library
707              
708             =head1 VERSION
709              
710             version 0.004001
711              
712             =head1 SYNOPSIS
713              
714             use strict;
715             use warnings;
716             use Net::Fortinet::FortiManager;
717              
718             my $fortimanager = Net::Fortinet::FortiManager->new(
719             server => 'https://fortimanager.example.com',
720             user => 'username',
721             passwd => '$password',
722             clientattrs => {
723             timeout => 10,
724             },
725             );
726              
727             $fortimanager->login;
728              
729             $fortimanager->adom('adomname');
730              
731             =head1 DESCRIPTION
732              
733             This module is a client library for the Fortigate FortiManager JSONRPC-like
734             API.
735             Currently it is developed and tested against version 6.4.6.
736             All requests have the verbose parameter set to 1 to ensure that enums return
737             their strings instead of undocumented ids.
738              
739             =head1 ATTRIBUTES
740              
741             =head2 adoms
742              
743             Returns a list of hashrefs containing name and uuid of all ADOMs which gets
744             populated by L</login>.
745              
746             =head2 adom
747              
748             The name of the ADOM which is used by all methods.
749             Defaults to 'root'.
750              
751             =head1 METHODS
752              
753             =head2 exec_method
754              
755             Executes a method with the specified parameters.
756              
757             Returns its response.
758              
759             This is the lowest level method which can be used to execute every API action
760             that's available.
761             It does the http and JSONRPC error handling and extraction of the result
762             from the JSONRPC response.
763              
764             =head2 exec_method_multi
765              
766             Executes a method with multiple specified parameters.
767              
768             Returns its responses.
769              
770             This is also a low level method which can be used to execute multiple API
771             actions in a single JSONRPC call.
772             The only restriction of the JSONRPC API is that all actions need to use the
773             same method.
774             It does the http and JSONRPC error handling and extraction of the results
775             from the JSONRPC response.
776              
777             =head2 login
778              
779             Logs into the Fortinet FortiManager and switches to the first available ADOM
780             if the currently set L<adom> isn't available, for example because the user
781             is limited to one or more ADOMs.
782              
783             =head2 logout
784              
785             Logs out of the Fortinet FortiManager.
786              
787             =head2 get_sys_status
788              
789             Returns /sys/status.
790              
791             =head2 has_firewall_service_udp_lite_support
792              
793             Returns true if the version supports UDP-Lite.
794             This was introduced in version 7.6.0.
795              
796             =head2 list_adoms
797              
798             Takes an optional parameter hashref.
799              
800             Returns an arrayref of ADOMs.
801              
802             =head2 list_adoms_by_name
803              
804             Returns an arrayref of ADOMs sorted by name.
805              
806             =head2 list_firewall_addresses
807              
808             Returns an arrayref of firewall addresses.
809              
810             =head2 get_firewall_address
811              
812             Takes a firewall address name and an optional parameter hashref.
813              
814             Returns its data as a hashref.
815              
816             =head2 create_firewall_address
817              
818             Takes a firewall address name and a hashref of address config.
819              
820             Returns true on success.
821              
822             Throws an exception on error.
823              
824             =head2 update_firewall_address
825              
826             Takes a firewall address name and a hashref of address config.
827              
828             Returns true on success.
829              
830             Throws an exception on error.
831              
832             =head2 delete_firewall_address
833              
834             Takes a firewall address name.
835              
836             Returns true on success.
837              
838             Throws an exception on error.
839              
840             =head2 list_firewall_address_groups
841              
842             Returns an arrayref of firewall address groups.
843              
844             =head2 get_firewall_address_group
845              
846             Takes a firewall address group name and an optional parameter hashref.
847              
848             Returns its data as a hashref.
849              
850             =head2 create_firewall_address_group
851              
852             Takes a firewall address group name and a hashref of address group config.
853              
854             Returns true on success.
855              
856             Throws an exception on error.
857              
858             =head2 update_firewall_address_group
859              
860             Takes a firewall address group name and a hashref of address group config.
861              
862             Returns true on success.
863              
864             Throws an exception on error.
865              
866             =head2 delete_firewall_address_group
867              
868             Takes a firewall address group name.
869              
870             Returns true on success.
871              
872             Throws an exception on error.
873              
874             =head2 list_firewall_ipv6_addresses
875              
876             Returns an arrayref of firewall IPv6 addresses.
877              
878             =head2 get_firewall_ipv6_address
879              
880             Takes a firewall IPv6 address name and an optional parameter hashref.
881              
882             Returns its data as a hashref.
883              
884             =head2 create_firewall_ipv6_address
885              
886             Takes a firewall IPv6 address name and a hashref of address config.
887              
888             Returns true on success.
889              
890             Throws an exception on error.
891              
892             =head2 update_firewall_ipv6_address
893              
894             Takes a firewall IPv6 address name and a hashref of address config.
895              
896             Returns true on success.
897              
898             Throws an exception on error.
899              
900             =head2 delete_firewall_ipv6_address
901              
902             Takes a firewall IPv6 address name.
903              
904             Returns true on success.
905              
906             Throws an exception on error.
907              
908             =head2 list_firewall_ipv6_address_groups
909              
910             Returns an arrayref of firewall IPv6 address groups.
911              
912             =head2 get_firewall_ipv6_address_group
913              
914             Takes a firewall IPv6 address group name and an optional parameter hashref.
915              
916             Returns its data as a hashref.
917              
918             =head2 create_firewall_ipv6_address_group
919              
920             Takes a firewall IPv6 address group name and a hashref of address group config.
921              
922             Returns true on success.
923              
924             Throws an exception on error.
925              
926             =head2 update_firewall_ipv6_address_group
927              
928             Takes a firewall IPv6 address group name and a hashref of address group config.
929              
930             Returns true on success.
931              
932             Throws an exception on error.
933              
934             =head2 delete_firewall_ipv6_address_group
935              
936             Takes a firewall IPv6 address group name.
937              
938             Returns true on success.
939              
940             Throws an exception on error.
941              
942             =head2 list_firewall_wildcard_fqdns
943              
944             Returns an arrayref of firewall wildcard FQDN objects.
945              
946             =head2 get_firewall_wildcard_fqdn
947              
948             Takes a firewall wildcard FQDN name and an optional parameter hashref.
949              
950             Returns its data as a hashref.
951              
952             =head2 create_firewall_wildcard_fqdn
953              
954             Takes a firewall wildcard FQDN name and a hashref of wildcard FQDN config.
955              
956             Returns true on success.
957              
958             Throws an exception on error.
959              
960             =head2 update_firewall_wildcard_fqdn
961              
962             Takes a firewall wildcard FQDN name and a hashref of wildcard FQDN config.
963              
964             Returns true on success.
965              
966             Throws an exception on error.
967              
968             =head2 delete_firewall_wildcard_fqdn
969              
970             Takes a firewall wildcard FQDN name.
971              
972             Returns true on success.
973              
974             Throws an exception on error.
975              
976             =head2 list_firewall_services
977              
978             Returns an arrayref of firewall services.
979              
980             =head2 get_firewall_service
981              
982             Takes a firewall service name and an optional parameter hashref.
983              
984             Returns its data as a hashref.
985              
986             =head2 create_firewall_service
987              
988             Takes a firewall service name and a hashref of service config.
989              
990             Returns true on success.
991              
992             Throws an exception on error.
993              
994             =head2 update_firewall_service
995              
996             Takes a firewall service name and a hashref of service config.
997              
998             Returns true on success.
999              
1000             Throws an exception on error.
1001              
1002             =head2 delete_firewall_service
1003              
1004             Takes a firewall service name.
1005              
1006             Returns true on success.
1007              
1008             Throws an exception on error.
1009              
1010             =head2 list_firewall_service_groups
1011              
1012             Returns an arrayref of firewall service groups.
1013              
1014             =head2 get_firewall_service_group
1015              
1016             Takes a firewall service group name and an optional parameter hashref.
1017              
1018             Returns its data as a hashref.
1019              
1020             =head2 create_firewall_service_group
1021              
1022             Takes a firewall service group name and a hashref of service group config.
1023              
1024             Returns true on success.
1025              
1026             Throws an exception on error.
1027              
1028             =head2 update_firewall_service_group
1029              
1030             Takes a firewall service group name and a hashref of service group config.
1031              
1032             Returns true on success.
1033              
1034             Throws an exception on error.
1035              
1036             =head2 delete_firewall_service_group
1037              
1038             Takes a firewall service group name.
1039              
1040             Returns true on success.
1041              
1042             Throws an exception on error.
1043              
1044             =head2 list_policy_packages
1045              
1046             Takes optional parameters.
1047              
1048             Returns an arrayref of policy packages.
1049              
1050             =head2 get_policy_package
1051              
1052             Takes a policy package name and an optional parameter hashref.
1053              
1054             Returns its data as a hashref.
1055              
1056             =head2 create_policy_package
1057              
1058             Takes a policy package name and a hashref of attributes.
1059              
1060             Returns true on success.
1061              
1062             Throws an exception on error.
1063              
1064             The firewall policies are configured depending on the 'ngfw-mode'.
1065             For profile-based policy packages you have to use the 'policy' methods,
1066             for policy-based the 'security_policy' methods.
1067              
1068             =head2 update_policy_package
1069              
1070             Takes a policy package name and a hashref of attributes.
1071              
1072             Returns true on success.
1073              
1074             Throws an exception on error.
1075              
1076             =head2 delete_policy_package
1077              
1078             Takes a policy package name.
1079              
1080             Returns true on success.
1081              
1082             Throws an exception on error.
1083              
1084             =head2 install_policy_package
1085              
1086             Takes a policy package name and a hashref of parameters.
1087              
1088             Returns the task id on success.
1089              
1090             Throws an exception on error.
1091              
1092             =head2 list_tasks
1093              
1094             Takes optional parameters.
1095              
1096             Returns an arrayref of tasks.
1097              
1098             =head2 get_task
1099              
1100             Takes a task id and an optional parameter hashref.
1101              
1102             Returns its data as a hashref.
1103              
1104             =head2 wait_for_task
1105              
1106             Takes a task id and checks its status every second until its percent
1107             have reached 100 and return the status.
1108             Takes an optional callback coderef which is called for every check with the
1109             task as argument.
1110              
1111             =head2 list_firewall_policies
1112              
1113             Takes a package name and optional parameters.
1114              
1115             Returns an arrayref of firewall policies.
1116              
1117             =head2 get_firewall_policy
1118              
1119             Takes a policy package name, a firewall policy id and an optional parameter
1120             hashref.
1121              
1122             Returns its data as a hashref.
1123              
1124             =head2 create_firewall_policy
1125              
1126             Takes a policy package name and a hashref of firewall policy attributes.
1127              
1128             Returns the response data from the API on success which is a hashref
1129             containing only the policyid.
1130              
1131             Throws an exception on error.
1132              
1133             =head2 update_firewall_policy
1134              
1135             Takes a policy package name, a firewall policy id and a hashref of firewall
1136             policy attributes.
1137              
1138             Returns the response data from the API on success which is a hashref
1139             containing only the policyid.
1140              
1141             Throws an exception on error.
1142              
1143             =head2 delete_firewall_policy
1144              
1145             Takes a policy package name and a firewall policy id.
1146              
1147             Returns true on success.
1148              
1149             Throws an exception on error.
1150              
1151             =head2 list_firewall_security_policies
1152              
1153             Takes a package name and optional parameters.
1154              
1155             Returns an arrayref of firewall security policies.
1156              
1157             =head2 get_firewall_security_policy
1158              
1159             Takes a policy package name, a firewall security policy id and an optional
1160             parameter hashref.
1161              
1162             Returns its data as a hashref.
1163              
1164             =head2 create_firewall_security_policy
1165              
1166             Takes a policy package name and a hashref of firewall security policy
1167             attributes.
1168              
1169             Returns the response data from the API on success which is a hashref
1170             containing only the policyid.
1171              
1172             Throws an exception on error.
1173              
1174             =head2 update_firewall_security_policy
1175              
1176             Takes a policy package name, a firewall security policy id and a hashref of
1177             firewall security policy attributes.
1178              
1179             Returns the response data from the API on success which is a hashref
1180             containing only the policyid.
1181              
1182             Throws an exception on error.
1183              
1184             =head2 delete_firewall_security_policy
1185              
1186             Takes a policy package name and a firewall security policy id.
1187              
1188             Returns true on success.
1189              
1190             Throws an exception on error.
1191              
1192             =for Pod::Coverage has_user has_passwd has_api_key
1193              
1194             =head1 TESTS
1195              
1196             To run the live API tests the following environment variables need to be set:
1197              
1198             =over
1199              
1200             =item NET_FORTINET_FORTIMANAGER_HOSTNAME
1201              
1202             =item NET_FORTINET_FORTIMANAGER_USERNAME
1203              
1204             =item NET_FORTINET_FORTIMANAGER_PASSWORD
1205              
1206             =item NET_FORTINET_FORTIMANAGER_POLICY
1207              
1208             =back
1209              
1210             Several network objects are created as well as a policy package named by the
1211             NET_FORTINET_FORTIMANAGER_POLICY environment variable.
1212              
1213             The test aborts if any of the objects can't be created, most likely if it
1214             already exists.
1215             All objects are deleted at the end of the test run, even when it aborts.
1216              
1217             =head1 AUTHOR
1218              
1219             Alexander Hartmaier <abraxxa@cpan.org>
1220              
1221             =head1 COPYRIGHT AND LICENSE
1222              
1223             This software is copyright (c) 2023 by Alexander Hartmaier.
1224              
1225             This is free software; you can redistribute it and/or modify it under
1226             the same terms as the Perl 5 programming language system itself.
1227              
1228             =cut