This is an automated email from the ASF dual-hosted git repository. martinzink pushed a commit to branch minifi_rust_pgp in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 491b928d89381138179e117103e9444a174be0a3 Author: Martin Zink <[email protected]> AuthorDate: Tue Aug 4 15:57:57 2026 +0200 rebase --- .../src/controller_services/private_key_service.rs | 8 ++-- .../controller_service_definition.rs | 4 +- .../private_key_service/properties.rs | 42 ++++++---------- .../src/controller_services/public_key_service.rs | 5 +- .../controller_service_definition.rs | 4 +- .../public_key_service/properties.rs | 30 +++++------- minifi_rust/extensions/minifi_pgp/src/lib.rs | 1 + .../minifi_pgp/src/processors/decrypt_content.rs | 9 ++-- .../decrypt_content/processor_definition.rs | 6 +-- .../src/processors/decrypt_content/properties.rs | 45 ++++++----------- .../src/processors/decrypt_content/tests.rs | 14 +++--- .../minifi_pgp/src/processors/encrypt_content.rs | 19 +++----- .../encrypt_content/processor_definition.rs | 6 +-- .../src/processors/encrypt_content/properties.rs | 56 +++++++--------------- .../src/processors/encrypt_content/tests.rs | 3 +- minifi_rust/extensions/minifi_pgp/src/utils.rs | 7 ++- 16 files changed, 96 insertions(+), 163 deletions(-) diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service.rs index bef534236..46744ef94 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service.rs @@ -4,13 +4,11 @@ mod properties; #[cfg(test)] use crate::controller_services::key_lookup::key_matches; use crate::controller_services::private_key_service::properties::KEY_PASSPHRASE; -use crate::utils; use minifi_native::macros::ComponentIdentifier; use minifi_native::{EnableControllerService, GetProperty, Logger, MinifiError, warn}; use pgp::composed::{Deserializable, SignedSecretKey, TheRing}; #[cfg(test)] use pgp::types::KeyDetails; -use std::path::PathBuf; #[derive(Debug, ComponentIdentifier)] pub(crate) struct PGPPrivateKeyService { @@ -24,7 +22,7 @@ impl EnableControllerService for PGPPrivateKeyService { Self: Sized, { let mut private_keys = vec![]; - if let Some(keyring_file_path) = context.get_property::<PathBuf>(&properties::KEY_FILE)? { + if let Some(keyring_file_path) = context.get_property(&properties::KEY_FILE)? { if let Ok((keys, _headers)) = SignedSecretKey::from_armor_file_many(&keyring_file_path) { collect_keys(keys, &mut private_keys, logger); @@ -32,14 +30,14 @@ impl EnableControllerService for PGPPrivateKeyService { collect_keys(keys, &mut private_keys, logger); } } - if let Some(keyring_ascii) = context.get_property::<String>(&properties::KEY)? + if let Some(keyring_ascii) = context.get_property(&properties::KEY)? && let Ok((keys, _headers)) = SignedSecretKey::from_armor_many(keyring_ascii.as_bytes()) { collect_keys(keys, &mut private_keys, logger); } let passphrase = context - .get_property::<utils::Password>(&KEY_PASSPHRASE)? + .get_property(&KEY_PASSPHRASE)? .unwrap_or_default(); if private_keys.is_empty() { diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/controller_service_definition.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/controller_service_definition.rs index 11f80a911..0099d3d97 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/controller_service_definition.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/controller_service_definition.rs @@ -1,10 +1,10 @@ use super::PGPPrivateKeyService; use super::properties::*; -use minifi_native::{ControllerServiceDefinition, Property, ProvidedInterface}; +use minifi_native::{property_definitions, ControllerServiceDefinition, PropertyDefinition, ProvidedInterface}; impl ControllerServiceDefinition for PGPPrivateKeyService { const DESCRIPTION: &'static str = "PGP Private Key Service provides Private Keys loaded from files or properties"; - const PROPERTIES: &'static [Property] = &[KEY_FILE, KEY, KEY_PASSPHRASE]; + const PROPERTIES: &'static [PropertyDefinition] = property_definitions![KEY_FILE, KEY, KEY_PASSPHRASE]; const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[]; } diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/properties.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/properties.rs index 6cabc0086..445e111f2 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/properties.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/private_key_service/properties.rs @@ -1,32 +1,18 @@ use minifi_native::Property; -use minifi_native::PropertyConstraints::NoConstraints; +use std::path::PathBuf; +use crate::utils; -pub(crate) const KEY_FILE: Property = Property { - name: "Key File", - description: "File path to PGP Secret Key encoded in binary or ASCII Armor", - is_required: false, - is_sensitive: false, - supports_expr_lang: true, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const KEY_FILE: Property<Option<PathBuf>> = Property::new( + "Key File", + "File path to PGP Secret Key encoded in binary or ASCII Armor", +) +.supports_expression_language(); -pub(crate) const KEY: Property = Property { - name: "Key", - description: "Secret Key encoded in ASCII Armor", - is_required: false, - is_sensitive: true, - supports_expr_lang: false, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const KEY: Property<Option<String>> = + Property::new("Key", "Secret Key encoded in ASCII Armor").sensitive(); -pub(crate) const KEY_PASSPHRASE: Property = Property { - name: "Key Passphrase", - description: "Passphrase used for decrypting Private Keys", - is_required: false, - is_sensitive: true, - supports_expr_lang: false, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const KEY_PASSPHRASE: Property<Option<utils::Password>> = Property::new( + "Key Passphrase", + "Passphrase used for decrypting Private Keys", +) +.sensitive(); diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service.rs index 93f03d20e..97de8f755 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service.rs @@ -7,7 +7,6 @@ use minifi_native::macros::ComponentIdentifier; use minifi_native::{EnableControllerService, GetProperty, Logger, MinifiError, warn}; use pgp::composed::{Deserializable, SignedPublicKey}; use pgp::types::KeyDetails; -use std::path::PathBuf; #[derive(Debug, ComponentIdentifier, PartialEq)] pub(crate) struct PGPPublicKeyService { @@ -20,7 +19,7 @@ impl EnableControllerService for PGPPublicKeyService { Self: Sized, { let mut public_keys = vec![]; - if let Some(keyring_file_path) = context.get_property::<PathBuf>(&KEYRING_FILE)? { + if let Some(keyring_file_path) = context.get_property(&KEYRING_FILE)? { if let Ok((keys, _headers)) = SignedPublicKey::from_armor_file_many(&keyring_file_path) { collect_keys(keys, &mut public_keys, logger); @@ -28,7 +27,7 @@ impl EnableControllerService for PGPPublicKeyService { collect_keys(keys, &mut public_keys, logger); } } - if let Some(keyring_ascii) = context.get_property::<String>(&KEYRING)? + if let Some(keyring_ascii) = context.get_property(&KEYRING)? && let Ok((keys, _headers)) = SignedPublicKey::from_armor_many(keyring_ascii.as_bytes()) { collect_keys(keys, &mut public_keys, logger); diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/controller_service_definition.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/controller_service_definition.rs index 77fb1c34a..b7025284f 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/controller_service_definition.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/controller_service_definition.rs @@ -1,10 +1,10 @@ use super::PGPPublicKeyService; use super::properties::*; -use minifi_native::{ControllerServiceDefinition, Property, ProvidedInterface}; +use minifi_native::{property_definitions, ControllerServiceDefinition, PropertyDefinition, ProvidedInterface}; impl ControllerServiceDefinition for PGPPublicKeyService { const DESCRIPTION: &'static str = "PGP Public Key Service providing Public Keys loaded from files"; - const PROPERTIES: &'static [Property] = &[KEYRING_FILE, KEYRING]; + const PROPERTIES: &'static [PropertyDefinition] = property_definitions![KEYRING_FILE, KEYRING]; const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[]; } diff --git a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/properties.rs b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/properties.rs index 2087163ea..757336482 100644 --- a/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/properties.rs +++ b/minifi_rust/extensions/minifi_pgp/src/controller_services/public_key_service/properties.rs @@ -1,22 +1,14 @@ use minifi_native::Property; -use minifi_native::PropertyConstraints::NoConstraints; +use std::path::PathBuf; -pub(crate) const KEYRING_FILE: Property = Property { - name: "Keyring File", - description: "File path to PGP Keyring or Secret Key encoded in binary or ASCII Armor", - is_required: false, - is_sensitive: false, - supports_expr_lang: true, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const KEYRING_FILE: Property<Option<PathBuf>> = Property::new( + "Keyring File", + "File path to PGP Keyring or Secret Key encoded in binary or ASCII Armor", +) +.supports_expression_language(); -pub(crate) const KEYRING: Property = Property { - name: "Keyring", - description: "PGP Keyring or Secret Key encoded in ASCII Armor", - is_required: false, - is_sensitive: true, - supports_expr_lang: false, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const KEYRING: Property<Option<String>> = Property::new( + "Keyring", + "PGP Keyring or Secret Key encoded in ASCII Armor", +) +.sensitive(); diff --git a/minifi_rust/extensions/minifi_pgp/src/lib.rs b/minifi_rust/extensions/minifi_pgp/src/lib.rs index 6c0125687..f8085bb07 100644 --- a/minifi_rust/extensions/minifi_pgp/src/lib.rs +++ b/minifi_rust/extensions/minifi_pgp/src/lib.rs @@ -8,6 +8,7 @@ use crate::processors::encrypt_content::EncryptContentPGP; use minifi_native::{FlowFileStreamTransformProcessorType, MultiThreaded}; minifi_native::declare_minifi_extension!( + group_name: "org.apache.nifi.minifi.rust", processors: [ (FlowFileStreamTransformProcessorType, MultiThreaded, EncryptContentPGP), (FlowFileStreamTransformProcessorType, MultiThreaded, DecryptContentPGP), diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content.rs b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content.rs index e97b15e54..6bd74be79 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content.rs @@ -7,7 +7,6 @@ use crate::processors::decrypt_content::properties::{ DECRYPTION_STRATEGY, PRIVATE_KEY_SERVICE, SYMMETRIC_PASSWORD, }; use crate::processors::decrypt_content::relationships::{FAILURE, SUCCESS}; -use crate::utils; use minifi_native::macros::{ComponentIdentifier, PropertyType}; use minifi_native::{ FlowFileStreamTransform, GetControllerService, GetProperty, InputStream, Logger, MinifiError, @@ -40,11 +39,11 @@ impl Schedule for DecryptContentPGP { L: Logger, { let decryption_strategy = - context.get_req_property::<DecryptionStrategy>(&DECRYPTION_STRATEGY)?; + context.get_property(&DECRYPTION_STRATEGY)?; - let symmetric_password = context.get_property::<utils::Password>(&SYMMETRIC_PASSWORD)?; + let symmetric_password = context.get_property(&SYMMETRIC_PASSWORD)?; let has_context_service = context - .get_property::<String>(&PRIVATE_KEY_SERVICE)? + .get_raw_property(&PRIVATE_KEY_SERVICE)? .is_some(); if !has_context_service && symmetric_password.is_none() { Err(MinifiError::schedule_err( @@ -114,7 +113,7 @@ impl FlowFileStreamTransform for DecryptContentPGP { }; let private_key_service = - context.get_controller_service::<PGPPrivateKeyService>(&PRIVATE_KEY_SERVICE)?; + context.get_controller_service(&PRIVATE_KEY_SERVICE)?; let Ok(mut decrypted_msg) = self.decrypt_msg(msg, private_key_service) else { warn!(logger, "Failed to decrypt data"); diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/processor_definition.rs b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/processor_definition.rs index c9c6fddf6..9aa750430 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/processor_definition.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/processor_definition.rs @@ -1,7 +1,5 @@ use super::{DecryptContentPGP, output_attributes, properties, relationships}; -use minifi_native::{ - OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, Property, Relationship, -}; +use minifi_native::{property_definitions, OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, PropertyDefinition, Relationship}; impl ProcessorDefinition for DecryptContentPGP { const DESCRIPTION: &'static str = "Decrypt contents of OpenPGP messages. Using the Packaged Decryption Strategy preserves OpenPGP encoding to support subsequent signature verification."; @@ -14,7 +12,7 @@ impl ProcessorDefinition for DecryptContentPGP { ]; const RELATIONSHIPS: &'static [Relationship] = &[relationships::SUCCESS, relationships::FAILURE]; - const PROPERTIES: &'static [Property] = &[ + const PROPERTIES: &'static [PropertyDefinition] = property_definitions![ properties::DECRYPTION_STRATEGY, properties::SYMMETRIC_PASSWORD, properties::PRIVATE_KEY_SERVICE, diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/properties.rs b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/properties.rs index d642e7f35..5015ca707 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/properties.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/properties.rs @@ -1,36 +1,21 @@ use crate::controller_services::private_key_service::PGPPrivateKeyService; use crate::processors::decrypt_content::DecryptionStrategy; -use minifi_native::ComponentIdentifier; use minifi_native::Property; -use minifi_native::PropertyConstraints::{AllowedType, AllowedValues, NoConstraints}; -use strum::VariantNames; +use crate::utils; -pub(crate) const DECRYPTION_STRATEGY: Property = Property { - name: "Decryption Strategy", - description: "Strategy for writing files to success after decryption", - is_required: true, - is_sensitive: false, - supports_expr_lang: false, - default_value: Some(DecryptionStrategy::Decrypted.into_str()), - constraints: AllowedValues(DecryptionStrategy::VARIANTS), -}; +pub(super) const DECRYPTION_STRATEGY: Property<DecryptionStrategy> = Property::new( + "Decryption Strategy", + "Strategy for writing files to success after decryption", +) +.with_default(DecryptionStrategy::Decrypted.into_str()); -pub(crate) const SYMMETRIC_PASSWORD: Property = Property { - name: "Symmetric Password", - description: "Password used for decrypting data encrypted with Password-Based Encryption", - is_required: false, - is_sensitive: true, - supports_expr_lang: false, - default_value: None, - constraints: NoConstraints, -}; +pub(super) const SYMMETRIC_PASSWORD: Property<Option<utils::Password>> = Property::new( + "Symmetric Password", + "Password used for decrypting data encrypted with Password-Based Encryption", +) +.sensitive(); -pub(crate) const PRIVATE_KEY_SERVICE: Property = Property { - name: "Private Key Service", - description: "PGP Private Key Service for decrypting data encrypted with Public Key Encryption", - is_required: false, - is_sensitive: false, - supports_expr_lang: false, - default_value: None, - constraints: AllowedType(PGPPrivateKeyService::CLASS_NAME), -}; +pub(super) const PRIVATE_KEY_SERVICE: Property<Option<PGPPrivateKeyService>> = Property::new( + "Private Key Service", + "PGP Private Key Service for decrypting data encrypted with Public Key Encryption", +); diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/tests.rs b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/tests.rs index 65d4167dc..b29e27b42 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/tests.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/decrypt_content/tests.rs @@ -28,7 +28,7 @@ fn fails_to_schedule_by_default() { fn schedules_with_password() { let mut context = MockProcessContext::new(); context.properties.insert( - super::properties::SYMMETRIC_PASSWORD.name.to_string(), + super::properties::SYMMETRIC_PASSWORD.name(), "my_secret_password".to_string(), ); let decrypt_content = DecryptContentPGP::schedule(&context, &MockLogger::new()); @@ -39,7 +39,7 @@ fn schedules_with_password() { fn schedules_with_controller() { let mut context = MockProcessContext::new(); context.properties.insert( - super::properties::PRIVATE_KEY_SERVICE.name.to_string(), + super::properties::PRIVATE_KEY_SERVICE.name(), "my_private_key_service".to_string(), ); let decrypt_content = DecryptContentPGP::schedule(&context, &MockLogger::new()); @@ -50,11 +50,11 @@ fn schedules_with_controller() { fn schedule_rejects_invalid_strategy_without_panicking() { let mut context = MockProcessContext::new(); context.properties.insert( - super::properties::DECRYPTION_STRATEGY.name.to_string(), + super::properties::DECRYPTION_STRATEGY.name(), "NOT_A_STRATEGY".to_string(), ); context.properties.insert( - super::properties::SYMMETRIC_PASSWORD.name.to_string(), + super::properties::SYMMETRIC_PASSWORD.name(), "my_secret_password".to_string(), ); // Must return Err, not panic. @@ -96,13 +96,13 @@ fn test_decryption( Box::new(private_key.into_controller()), ); processor_context.properties.insert( - super::properties::PRIVATE_KEY_SERVICE.name.to_string(), + super::properties::PRIVATE_KEY_SERVICE.name(), "my_private_key_service".to_string(), ); } if let Some(symmetric_password) = symmetric_password { processor_context.properties.insert( - super::properties::SYMMETRIC_PASSWORD.name.to_string(), + super::properties::SYMMETRIC_PASSWORD.name(), symmetric_password.to_string(), ); } @@ -226,7 +226,7 @@ fn decryption_of_not_encrypted_data() { Box::new(alice_private_key.into_controller()), ); processor_context.properties.insert( - super::properties::PRIVATE_KEY_SERVICE.name.to_string(), + super::properties::PRIVATE_KEY_SERVICE.name(), "my_private_key_service".to_string(), ); diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content.rs b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content.rs index 1c1d47d7d..f21b03e0c 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content.rs @@ -10,7 +10,6 @@ mod output_attributes; mod properties; mod relationships; -use crate::controller_services::public_key_service::PGPPublicKeyService; use crate::processors::encrypt_content::output_attributes::FILE_ENCODING; use crate::processors::encrypt_content::properties::{ PASSWORD, PUBLIC_KEY_SEARCH, PUBLIC_KEY_SERVICE, @@ -81,15 +80,11 @@ impl Schedule for EncryptContentPGP { where Self: Sized, { - let file_encoding = context.get_req_property::<FileEncoding>(&properties::FILE_ENCODING)?; + let file_encoding = context.get_property::<FileEncoding>(&properties::FILE_ENCODING)?; - let has_password = context.get_property::<String>(&PASSWORD)?.is_some(); - let has_public_key = context - .get_property::<String>(&PUBLIC_KEY_SERVICE)? - .is_some() - && context - .get_property::<String>(&PUBLIC_KEY_SEARCH)? - .is_some(); + let has_password = context.get_property(&PASSWORD)?.is_some(); + let has_public_key = context.get_raw_property(&PUBLIC_KEY_SERVICE)?.is_some() + && context.get_property(&PUBLIC_KEY_SEARCH)?.is_some(); if !has_password && !has_public_key { Err(MinifiError::schedule_err( @@ -111,14 +106,14 @@ impl FlowFileStreamTransform for EncryptContentPGP { ) -> Result<TransformStreamResult, MinifiError> { let file_name = context.get_attribute("filename")?.unwrap_or_default(); let public_key = if let (Some(pub_key_search), Some(public_key_service)) = ( - context.get_property::<String>(&PUBLIC_KEY_SEARCH)?, - context.get_controller_service::<PGPPublicKeyService>(&PUBLIC_KEY_SERVICE)?, + context.get_property(&PUBLIC_KEY_SEARCH)?, + context.get_controller_service(&PUBLIC_KEY_SERVICE)?, ) { public_key_service.get(&pub_key_search) } else { None }; - let password = context.get_property::<String>(&PASSWORD)?; + let password = context.get_property(&PASSWORD)?; if public_key.is_none() && password.is_none() { warn!(logger, "No password or public key to encrypt with"); return Ok(TransformStreamResult::route_without_changes(&FAILURE)); diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/processor_definition.rs b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/processor_definition.rs index 4ac06faa7..f8b0855a9 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/processor_definition.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/processor_definition.rs @@ -1,7 +1,5 @@ use super::{EncryptContentPGP, output_attributes, properties, relationships}; -use minifi_native::{ - OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, Property, Relationship, -}; +use minifi_native::{property_definitions, OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, Relationship, PropertyDefinition}; impl ProcessorDefinition for EncryptContentPGP { const DESCRIPTION: &'static str = "Encrypt contents using OpenPGP."; @@ -11,7 +9,7 @@ impl ProcessorDefinition for EncryptContentPGP { const OUTPUT_ATTRIBUTES: &'static [OutputAttribute] = &[output_attributes::FILE_ENCODING]; const RELATIONSHIPS: &'static [Relationship] = &[relationships::SUCCESS, relationships::FAILURE]; - const PROPERTIES: &'static [Property] = &[ + const PROPERTIES: &'static [PropertyDefinition] = property_definitions![ properties::FILE_ENCODING, properties::PASSWORD, properties::PUBLIC_KEY_SEARCH, diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/properties.rs b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/properties.rs index 70ebdb404..6922b7c63 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/properties.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/properties.rs @@ -1,46 +1,22 @@ use crate::controller_services::public_key_service::PGPPublicKeyService; use crate::processors::encrypt_content::FileEncoding; -use minifi_native::ComponentIdentifier; use minifi_native::Property; -use minifi_native::PropertyConstraints::{AllowedType, AllowedValues, NoConstraints}; -use strum::VariantNames; -pub(crate) const FILE_ENCODING: Property = Property { - name: "File Encoding", - description: "File Encoding for encryption", - is_required: true, - is_sensitive: false, - supports_expr_lang: false, - default_value: Some(FileEncoding::Binary.into_str()), - constraints: AllowedValues(FileEncoding::VARIANTS), -}; +pub(crate) const FILE_ENCODING: Property<FileEncoding> = + Property::new("File Encoding", "File Encoding for encryption") + .with_default(FileEncoding::Binary.into_str()); +pub(crate) const PASSWORD: Property<Option<String>> = Property::new( + "Symmetric Password", + "Password used for encrypting data with Password-Based Encryption", +) +.sensitive(); -pub(crate) const PASSWORD: Property = Property { - name: "Symmetric Password", - description: "Password used for encrypting data with Password-Based Encryption", - is_required: false, - is_sensitive: true, - supports_expr_lang: false, - default_value: None, - constraints: NoConstraints, -}; +pub(crate) const PUBLIC_KEY_SEARCH: Property<Option<String>> = Property::new( + "Public Key Search", + "PGP Public Key Search will be used to match against the User ID or Key ID when formatted as uppercase hexadecimal string of 16 characters", +); -pub(crate) const PUBLIC_KEY_SEARCH: Property = Property { - name: "Public Key Search", - description: "PGP Public Key Search will be used to match against the User ID or Key ID when formatted as uppercase hexadecimal string of 16 characters", - is_required: false, - is_sensitive: false, - supports_expr_lang: true, - default_value: None, - constraints: NoConstraints, -}; - -pub(crate) const PUBLIC_KEY_SERVICE: Property = Property { - name: "Public Key Service", - description: "PGP Public Key Service for encrypting data with Public Key Encryption", - is_required: false, - is_sensitive: false, - supports_expr_lang: false, - default_value: None, - constraints: AllowedType(PGPPublicKeyService::CLASS_NAME), -}; +pub(crate) const PUBLIC_KEY_SERVICE: Property<Option<PGPPublicKeyService>> = Property::new( + "Public Key Service", + "PGP Public Key Service for encrypting data with Public Key Encryption", +); diff --git a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/tests.rs b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/tests.rs index 2e961dd7e..c79542ee4 100644 --- a/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/tests.rs +++ b/minifi_rust/extensions/minifi_pgp/src/processors/encrypt_content/tests.rs @@ -4,6 +4,7 @@ use minifi_native::{ ComponentIdentifier, EnableControllerService, IoState, MockControllerServiceContext, MockLogger, MockProcessContext, }; +use crate::controller_services::public_key_service::PGPPublicKeyService; #[test] fn test_ids() { @@ -32,7 +33,7 @@ fn assert_content(transform_result: &TransformStreamResult, is_ascii: bool) { #[test] fn encrypts_via_passphrase() { let mut context = MockProcessContext::new(); - context.properties.insert(PASSWORD.name, "password"); + context.properties.insert(PASSWORD.name(), "password"); context .attributes .insert("filename".to_owned(), "mammut".to_owned()); diff --git a/minifi_rust/extensions/minifi_pgp/src/utils.rs b/minifi_rust/extensions/minifi_pgp/src/utils.rs index 95b346238..f222127ef 100644 --- a/minifi_rust/extensions/minifi_pgp/src/utils.rs +++ b/minifi_rust/extensions/minifi_pgp/src/utils.rs @@ -1,7 +1,12 @@ -use minifi_native::{MinifiError, PropertyType}; +use minifi_native::{MinifiError, PropertyConstraints, PropertySchema, PropertyType}; pub(crate) struct Password {} +impl PropertySchema for Password { + const CONSTRAINT: Option<PropertyConstraints> = None; + const IS_REQUIRED: bool = false; +} + impl PropertyType for Password { type Output = pgp::types::Password;
