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