line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SecurityCenter::API::Policy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
18
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use parent 'Net::SecurityCenter::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
55
|
use Net::SecurityCenter::Utils qw(:all); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1198
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.311'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $single_id_filter = sub { |
15
|
|
|
|
|
|
|
return { 'id' => $_[0] }; |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $common_template = { |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
id => { |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
allow => qr/^\d+$/, |
23
|
|
|
|
|
|
|
messages => { |
24
|
|
|
|
|
|
|
required => 'Policy ID is required', |
25
|
|
|
|
|
|
|
allow => 'Invalid Policy ID', |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
policy_template => { |
30
|
|
|
|
|
|
|
remap => 'policyTemplate', |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
filter => \&$single_id_filter |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
name => {}, |
36
|
|
|
|
|
|
|
description => {}, |
37
|
|
|
|
|
|
|
tags => {}, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
filter => { |
40
|
|
|
|
|
|
|
allow => [ 'usable', 'manageable' ], |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
fields => { |
44
|
|
|
|
|
|
|
filter => \&sc_filter_array_to_string, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
# METHODS |
51
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub list { |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
1
|
4
|
my ( $self, %args ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $tmpl = { |
58
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
59
|
1
|
|
|
|
|
9
|
filter => $common_template->{'filter'}, |
60
|
|
|
|
|
|
|
raw => {} |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
6
|
my $params = sc_check_params( $tmpl, \%args ); |
64
|
1
|
|
|
|
|
10
|
my $raw = delete( $params->{'raw'} ); |
65
|
1
|
|
|
|
|
11
|
my $policies = $self->client->get( '/policy', $params ); |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
6
|
return if ( !$policies ); |
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
6
|
if ($raw) { |
70
|
0
|
0
|
|
|
|
0
|
return wantarray ? @{$policies} : $policies; |
|
0
|
|
|
|
|
0
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
1
|
50
|
|
|
|
6
|
return wantarray ? @{ sc_merge($policies) } : sc_merge($policies); |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get { |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
1
|
1
|
5
|
my ( $self, %args ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $tmpl = { |
84
|
|
|
|
|
|
|
fields => $common_template->{'fields'}, |
85
|
1
|
|
|
|
|
5
|
id => $common_template->{'id'}, |
86
|
|
|
|
|
|
|
raw => {}, |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
5
|
my $params = sc_check_params( $tmpl, \%args ); |
90
|
1
|
|
|
|
|
6
|
my $policy_id = delete( $params->{'id'} ); |
91
|
1
|
|
|
|
|
4
|
my $raw = delete( $params->{'raw'} ); |
92
|
1
|
|
|
|
|
6
|
my $policy = $self->client->get( "/policy/$policy_id", $params ); |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
13
|
return if ( !$policy ); |
95
|
1
|
50
|
|
|
|
9
|
return $policy if ($raw); |
96
|
0
|
|
|
|
|
0
|
return sc_normalize_hash($policy); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub create { |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
1
|
1
|
10
|
my ( $self, %args ) = @_; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $tmpl = { |
107
|
|
|
|
|
|
|
name => { |
108
|
|
|
|
|
|
|
required => 1, |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
description => {}, |
111
|
1
|
|
|
|
|
8
|
policy_template => $common_template->{'policy_template'}, |
112
|
|
|
|
|
|
|
tags => {}, |
113
|
|
|
|
|
|
|
preferences => {}, |
114
|
|
|
|
|
|
|
families => {}, |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
6
|
my $params = sc_check_params( $tmpl, \%args ); |
118
|
1
|
|
|
|
|
10
|
my $policy = $self->client->post( '/policy', $params ); |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
6
|
return sc_normalize_hash($policy); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub edit { |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %args ) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $tmpl = { |
131
|
0
|
|
|
|
|
0
|
id => $common_template->{'id'}, |
132
|
|
|
|
|
|
|
name => {}, |
133
|
|
|
|
|
|
|
description => {}, |
134
|
|
|
|
|
|
|
tags => {}, |
135
|
|
|
|
|
|
|
preferences => {}, |
136
|
|
|
|
|
|
|
families => {}, |
137
|
|
|
|
|
|
|
remove_prefs => { |
138
|
|
|
|
|
|
|
remap => 'removePrefs' |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
my $params = sc_check_params( $tmpl, \%args ); |
143
|
0
|
|
|
|
|
0
|
my $policy_id = delete( $params->{'id'} ); |
144
|
0
|
|
|
|
|
0
|
my $policy = $self->client->patch( "/policy/$policy_id", $params ); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
0
|
return sc_normalize_hash($policy); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub copy { |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %args ) = @_; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $tmpl = { |
157
|
0
|
|
|
|
|
0
|
id => $common_template->{'id'}, |
158
|
|
|
|
|
|
|
name => {}, |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
my $params = sc_check_params( $tmpl, \%args ); |
162
|
0
|
|
|
|
|
0
|
my $policy_id = delete( $params->{'id'} ); |
163
|
0
|
|
|
|
|
0
|
my $policy = $self->client->post( "/policy/$policy_id/copy", $params ); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
0
|
return sc_normalize_hash($policy); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub delete { |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
1
|
1
|
5
|
my ( $self, %args ) = @_; |
174
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
4
|
my $tmpl = { id => $common_template->{'id'} }; |
176
|
|
|
|
|
|
|
|
177
|
1
|
|
|
|
|
5
|
my $params = sc_check_params( $tmpl, \%args ); |
178
|
1
|
|
|
|
|
7
|
my $policy_id = delete( $params->{'id'} ); |
179
|
|
|
|
|
|
|
|
180
|
1
|
|
|
|
|
6
|
$self->client->delete("/policy/$policy_id"); |
181
|
|
|
|
|
|
|
|
182
|
1
|
|
|
|
|
7
|
return 1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub download { |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
my $tmpl = { |
193
|
|
|
|
|
|
|
filename => {}, |
194
|
0
|
|
|
|
|
|
id => $common_template->{'id'}, |
195
|
|
|
|
|
|
|
}; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $params = sc_check_params( $tmpl, \%args ); |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $policy_id = delete( $params->{'id'} ); |
200
|
0
|
|
|
|
|
|
my $filename = delete( $params->{'filename'} ); |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my $policy_data = $self->client->post("/policy/$policy_id/export"); |
203
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
return $policy_data if ( !$filename ); |
205
|
|
|
|
|
|
|
|
206
|
0
|
0
|
|
|
|
|
open my $fh, '>', $filename |
207
|
|
|
|
|
|
|
or croak("Could not open file '$filename': $!"); |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
print $fh $policy_data; |
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
close $fh |
212
|
|
|
|
|
|
|
or carp("Failed to close file '$filename': $!"); |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
return 1; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
__END__ |