| 1 | package Net::SecurityCenter::API::Report; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use parent 'Net::SecurityCenter::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Net::SecurityCenter::Utils qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | our $VERSION = '0.311'; | |||||||||
| 13 | |||||||||||
| 14 | 2 | my $common_template = { | |||||||||
| 15 | |||||||||||
| 16 | id => { | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | allow => qr/^\d+$/, | ||||||||||
| 19 | messages => { | ||||||||||
| 20 | required => 'Report ID is required', | ||||||||||
| 21 | allow => 'Invalid Report ID', | ||||||||||
| 22 | }, | ||||||||||
| 23 | }, | ||||||||||
| 24 | |||||||||||
| 25 | filter => { | ||||||||||
| 26 | allow => [ 'running', 'completed', 'usable', 'manageable' ], | ||||||||||
| 27 | }, | ||||||||||
| 28 | |||||||||||
| 29 | fields => { | ||||||||||
| 30 | filter => \&sc_filter_array_to_string, | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | }; | ||||||||||
| 34 | |||||||||||
| 35 | #------------------------------------------------------------------------------- | ||||||||||
| 36 | # METHODS | ||||||||||
| 37 | #------------------------------------------------------------------------------- | ||||||||||
| 38 | |||||||||||
| 39 | 1 | ▶ | sub list { | ||||||||
|
Subroutine
list: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | 1 | my ( $self, %args ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | my $tmpl = { | ||||||||||
| 44 | fields => $common_template->{'fields'}, | ||||||||||
| 45 | 1 | filter => $common_template->{'filter'}, | |||||||||
| 46 | raw => {}, | ||||||||||
| 47 | }; | ||||||||||
| 48 | |||||||||||
| 49 | 1 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||
| 50 | 1 | my $raw = delete( $params->{'raw'} ); | |||||||||
| 51 | 1 | my $reports = $self->client->get( '/report', $params ); | |||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | return if ( !$reports ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | if ($raw) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | ▶ | return wantarray ? @{$reports} : $reports; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | return wantarray ? @{ sc_merge($reports) } : sc_merge($reports); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | #------------------------------------------------------------------------------- | ||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 1 | my ( $self, %args ) = @_; | |||||||||
| 68 | |||||||||||
| 69 | my $tmpl = { | ||||||||||
| 70 | fields => $common_template->{'fields'}, | ||||||||||
| 71 | 1 | id => $common_template->{'id'}, | |||||||||
| 72 | raw => {}, | ||||||||||
| 73 | }; | ||||||||||
| 74 | |||||||||||
| 75 | 1 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||
| 76 | |||||||||||
| 77 | 1 | my $report_id = delete( $params->{'id'} ); | |||||||||
| 78 | 1 | my $raw = delete( $params->{'raw'} ); | |||||||||
| 79 | |||||||||||
| 80 | 1 | my $report = $self->client->get( "/report/$report_id", $params ); | |||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | return if ( !$report ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | ▶ | return $report if ($raw); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 1 | return sc_normalize_hash($report); | |||||||||
| 85 | |||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | #------------------------------------------------------------------------------- | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub download { | ||||||||
|
Subroutine
download: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 91 | |||||||||||
| 92 | 0 | my ( $self, %args ) = @_; | |||||||||
| 93 | |||||||||||
| 94 | my $tmpl = { | ||||||||||
| 95 | filename => {}, | ||||||||||
| 96 | 0 | id => $common_template->{'id'}, | |||||||||
| 97 | }; | ||||||||||
| 98 | |||||||||||
| 99 | 0 | my $params = sc_check_params( $tmpl, \%args ); | |||||||||
| 100 | |||||||||||
| 101 | 0 | my $report_id = delete( $params->{'id'} ); | |||||||||
| 102 | 0 | my $filename = delete( $params->{'filename'} ); | |||||||||
| 103 | |||||||||||
| 104 | 0 | my $report_data = $self->client->post("/report/$report_id/download"); | |||||||||
| 105 | |||||||||||
| 106 | 0 | ▶ | return $report_data if ( !$filename ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | open my $fh, '>', $filename | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | or croak("Could not open file '$filename': $!"); | ||||||||||
| 110 | |||||||||||
| 111 | 0 | print $fh $report_data; | |||||||||
| 112 | |||||||||||
| 113 | 0 | ▶ | close $fh | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | or carp("Failed to close file '$filename': $!"); | ||||||||||
| 115 | |||||||||||
| 116 | 0 | return 1; | |||||||||
| 117 | |||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | #------------------------------------------------------------------------------- | ||||||||||
| 121 | |||||||||||
| 122 | 2 | 1; | |||||||||
| 123 | |||||||||||
| 124 | __END__ | ||||||||||