diff --git a/src/policy_artifacthub.rs b/src/policy_artifacthub.rs index 1a92b044..055b9c6f 100644 --- a/src/policy_artifacthub.rs +++ b/src/policy_artifacthub.rs @@ -474,7 +474,7 @@ fn parse_annotations( #[cfg(test)] mod tests { use super::*; - use crate::policy_metadata::ContextAwareResource; + use crate::policy_metadata::{ContextAwareResource, PolicyType}; use assert_json_diff::assert_json_eq; use serde_json::json; use std::collections::{HashMap, HashSet}; @@ -509,6 +509,7 @@ mod tests { background_audit: true, context_aware_resources: HashSet::new(), execution_mode: Default::default(), + policy_type: PolicyType::Kubernetes, minimum_kubewarden_version: None, } } @@ -574,6 +575,7 @@ mod tests { context_aware_resources, execution_mode: Default::default(), minimum_kubewarden_version: None, + policy_type: Default::default(), } } diff --git a/src/policy_metadata.rs b/src/policy_metadata.rs index a0950110..f95f6229 100644 --- a/src/policy_metadata.rs +++ b/src/policy_metadata.rs @@ -128,6 +128,15 @@ pub struct ContextAwareResource { pub kind: String, } +#[derive(Deserialize, Serialize, Debug, Clone, Default)] +pub enum PolicyType { + #[default] + #[serde(rename = "kubernetes")] + Kubernetes, + #[serde(rename = "raw")] + Raw, +} + #[derive(Deserialize, Serialize, Debug, Clone, Validate)] #[serde(rename_all = "camelCase")] #[validate(schema(function = "validate_metadata", skip_on_field_errors = false))] @@ -144,6 +153,8 @@ pub struct Metadata { #[serde(default)] pub execution_mode: PolicyExecutionMode, #[serde(default)] + pub policy_type: PolicyType, + #[serde(default)] #[validate] pub context_aware_resources: HashSet, #[serde(skip_serializing_if = "Option::is_none")] @@ -163,6 +174,7 @@ impl Default for Metadata { mutating: false, background_audit: true, execution_mode: PolicyExecutionMode::KubewardenWapc, + policy_type: PolicyType::Kubernetes, context_aware_resources: HashSet::new(), minimum_kubewarden_version: None, } @@ -345,6 +357,7 @@ mod tests { "backgroundAudit": true, "contextAwareResources": [ ], "executionMode": "kubewarden-wapc", + "policyType": "kubernetes" }); let actual = serde_json::to_value(&metadata).unwrap(); @@ -369,6 +382,7 @@ mod tests { annotations: None, background_audit: true, context_aware_resources: HashSet::new(), + policy_type: PolicyType::Kubernetes, ..Default::default() }; @@ -417,6 +431,7 @@ mod tests { "backgroundAudit": true, "contextAwareResources": [ ], "executionMode": "kubewarden-wapc", + "policyType": "kubernetes" }); let actual = serde_json::to_value(&metadata).unwrap();