@@ -31,7 +31,7 @@ lazy_static! {
31
31
pub struct Config {
32
32
pub addr : SocketAddr ,
33
33
pub sources : Option < Sources > ,
34
- pub policies : HashMap < String , Policy > ,
34
+ pub policies : HashMap < String , PolicyOrPolicyGroup > ,
35
35
pub policies_download_dir : PathBuf ,
36
36
pub ignore_kubernetes_connection_failure : bool ,
37
37
pub always_accept_admission_reviews_on_namespace : Option < String > ,
@@ -193,7 +193,7 @@ fn tls_files(matches: &clap::ArgMatches) -> Result<(String, String)> {
193
193
}
194
194
}
195
195
196
- fn policies ( matches : & clap:: ArgMatches ) -> Result < HashMap < String , Policy > > {
196
+ fn policies ( matches : & clap:: ArgMatches ) -> Result < HashMap < String , PolicyOrPolicyGroup > > {
197
197
let policies_file = Path :: new ( matches. get_one :: < String > ( "policies" ) . unwrap ( ) ) ;
198
198
read_policies_file ( policies_file) . map_err ( |e| {
199
199
anyhow ! (
@@ -275,19 +275,19 @@ impl TryFrom<HashMap<String, serde_yaml::Value>> for SettingsJSON {
275
275
}
276
276
277
277
#[ derive( Debug , Clone ) ]
278
- pub enum PolicySettings {
279
- IndividualPolicy ( SettingsJSON ) ,
280
- GroupPolicy {
278
+ pub enum PolicyOrPolicyGroupSettings {
279
+ Policy ( SettingsJSON ) ,
280
+ PolicyGroup {
281
281
expression : String ,
282
282
message : String ,
283
- sub_policies : Vec < String > ,
283
+ members : Vec < String > ,
284
284
} ,
285
285
}
286
286
287
- /// `GroupPolicyMember ` represents a single policy that is part of a group policy.
287
+ /// `PolicyGroupMember ` represents a single policy that is part of a policy group .
288
288
#[ derive( Deserialize , Debug , Clone ) ]
289
289
#[ serde( rename_all = "camelCase" ) ]
290
- pub struct GroupPolicyMember {
290
+ pub struct PolicyGroupMember {
291
291
/// Thge URL where the policy is located
292
292
pub url : String ,
293
293
/// The settings for the policy
@@ -297,19 +297,19 @@ pub struct GroupPolicyMember {
297
297
pub context_aware_resources : BTreeSet < ContextAwareResource > ,
298
298
}
299
299
300
- impl GroupPolicyMember {
301
- pub fn settings ( & self ) -> Result < PolicySettings > {
300
+ impl PolicyGroupMember {
301
+ pub fn settings ( & self ) -> Result < PolicyOrPolicyGroupSettings > {
302
302
let settings = SettingsJSON :: try_from ( self . settings . clone ( ) . unwrap_or_default ( ) ) ?;
303
- Ok ( PolicySettings :: IndividualPolicy ( settings) )
303
+ Ok ( PolicyOrPolicyGroupSettings :: Policy ( settings) )
304
304
}
305
305
}
306
306
307
307
/// Describes a policy that can be either an individual policy or a group policy.
308
308
#[ derive( Deserialize , Debug , Clone ) ]
309
309
#[ serde( untagged, rename_all = "camelCase" ) ]
310
- pub enum Policy {
310
+ pub enum PolicyOrPolicyGroup {
311
311
/// An individual policy
312
- Individual {
312
+ Policy {
313
313
/// The URL where the policy is located
314
314
url : String ,
315
315
#[ serde( default ) ]
@@ -324,36 +324,36 @@ pub enum Policy {
324
324
context_aware_resources : BTreeSet < ContextAwareResource > ,
325
325
} ,
326
326
/// A group of policies that are evaluated together using a given expression
327
- Group {
327
+ PolicyGroup {
328
328
/// The mode of the policy
329
329
#[ serde( default ) ]
330
330
policy_mode : PolicyMode ,
331
331
/// The policies that make up for this group
332
332
/// Key is a unique identifier
333
- policies : HashMap < String , GroupPolicyMember > ,
333
+ members : HashMap < String , PolicyGroupMember > ,
334
334
/// The expression that is used to evaluate the group of policies
335
335
expression : String ,
336
336
/// The message that is returned when the group of policies evaluates to false
337
337
message : String ,
338
338
} ,
339
339
}
340
340
341
- impl Policy {
342
- pub fn settings ( & self ) -> Result < PolicySettings > {
341
+ impl PolicyOrPolicyGroup {
342
+ pub fn settings ( & self ) -> Result < PolicyOrPolicyGroupSettings > {
343
343
match self {
344
- Policy :: Individual { settings, .. } => {
344
+ PolicyOrPolicyGroup :: Policy { settings, .. } => {
345
345
let settings = SettingsJSON :: try_from ( settings. clone ( ) . unwrap_or_default ( ) ) ?;
346
- Ok ( PolicySettings :: IndividualPolicy ( settings) )
346
+ Ok ( PolicyOrPolicyGroupSettings :: Policy ( settings) )
347
347
}
348
- Policy :: Group {
348
+ PolicyOrPolicyGroup :: PolicyGroup {
349
349
expression,
350
350
message,
351
- policies,
351
+ members : policies,
352
352
..
353
- } => Ok ( PolicySettings :: GroupPolicy {
353
+ } => Ok ( PolicyOrPolicyGroupSettings :: PolicyGroup {
354
354
expression : expression. clone ( ) ,
355
355
message : message. clone ( ) ,
356
- sub_policies : policies. keys ( ) . cloned ( ) . collect ( ) ,
356
+ members : policies. keys ( ) . cloned ( ) . collect ( ) ,
357
357
} ) ,
358
358
}
359
359
}
@@ -391,9 +391,9 @@ fn convert_yaml_map_to_json(
391
391
/// and Policy as values. The key is the name of the policy as provided by the user
392
392
/// inside of the configuration file. This name is used to build the API path
393
393
/// exposing the policy.
394
- fn read_policies_file ( path : & Path ) -> Result < HashMap < String , Policy > > {
394
+ fn read_policies_file ( path : & Path ) -> Result < HashMap < String , PolicyOrPolicyGroup > > {
395
395
let settings_file = File :: open ( path) ?;
396
- let ps: HashMap < String , Policy > = serde_yaml:: from_reader ( & settings_file) ?;
396
+ let ps: HashMap < String , PolicyOrPolicyGroup > = serde_yaml:: from_reader ( & settings_file) ?;
397
397
Ok ( ps)
398
398
}
399
399
@@ -442,13 +442,13 @@ example:
442
442
"# , json!( { "counter" : 1 , "items" : [ "a" , "b" ] , "nested" : { "key" : "value" } } )
443
443
) ]
444
444
fn handle_settings_conversion ( #[ case] input : & str , #[ case] expected : serde_json:: Value ) {
445
- let policies: HashMap < String , Policy > = serde_yaml:: from_str ( input) . unwrap ( ) ;
445
+ let policies: HashMap < String , PolicyOrPolicyGroup > = serde_yaml:: from_str ( input) . unwrap ( ) ;
446
446
assert ! ( !policies. is_empty( ) ) ;
447
447
448
448
let policy = policies. get ( "example" ) . unwrap ( ) ;
449
449
let settings = policy. settings ( ) . unwrap ( ) ;
450
450
match settings {
451
- PolicySettings :: IndividualPolicy ( settings) => {
451
+ PolicyOrPolicyGroupSettings :: Policy ( settings) => {
452
452
assert_eq ! ( serde_json:: Value :: Object ( settings. 0 ) , expected) ;
453
453
}
454
454
_ => panic ! ( "Expected an Individual policy" ) ,
0 commit comments