mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	refactor: kms decrypt analytics config (#3984)
This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -349,6 +349,7 @@ dependencies = [ | |||||||
|  "error-stack", |  "error-stack", | ||||||
|  "external_services", |  "external_services", | ||||||
|  "futures 0.3.28", |  "futures 0.3.28", | ||||||
|  |  "hyperswitch_interfaces", | ||||||
|  "masking", |  "masking", | ||||||
|  "once_cell", |  "once_cell", | ||||||
|  "reqwest", |  "reqwest", | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ api_models = { version = "0.1.0", path = "../api_models" , features = ["errors"] | |||||||
| storage_impl = { version = "0.1.0", path = "../storage_impl", default-features = false } | storage_impl = { version = "0.1.0", path = "../storage_impl", default-features = false } | ||||||
| common_utils = { version = "0.1.0", path = "../common_utils" } | common_utils = { version = "0.1.0", path = "../common_utils" } | ||||||
| external_services = { version = "0.1.0", path = "../external_services", default-features = false } | external_services = { version = "0.1.0", path = "../external_services", default-features = false } | ||||||
|  | hyperswitch_interfaces = { version = "0.1.0", path = "../hyperswitch_interfaces" } | ||||||
| masking = { version = "0.1.0", path = "../masking" } | masking = { version = "0.1.0", path = "../masking" } | ||||||
| router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] } | router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] } | ||||||
| diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] } | diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] } | ||||||
|  | |||||||
| @ -15,7 +15,13 @@ pub mod sdk_events; | |||||||
| mod sqlx; | mod sqlx; | ||||||
| mod types; | mod types; | ||||||
| use api_event::metrics::{ApiEventMetric, ApiEventMetricRow}; | use api_event::metrics::{ApiEventMetric, ApiEventMetricRow}; | ||||||
|  | use common_utils::errors::CustomResult; | ||||||
| use disputes::metrics::{DisputeMetric, DisputeMetricRow}; | use disputes::metrics::{DisputeMetric, DisputeMetricRow}; | ||||||
|  | use hyperswitch_interfaces::secrets_interface::{ | ||||||
|  |     secret_handler::SecretsHandler, | ||||||
|  |     secret_state::{RawSecret, SecretStateContainer, SecuredSecret}, | ||||||
|  |     SecretManagementInterface, SecretsManagementError, | ||||||
|  | }; | ||||||
| pub use types::AnalyticsDomain; | pub use types::AnalyticsDomain; | ||||||
| pub mod lambda_utils; | pub mod lambda_utils; | ||||||
| pub mod utils; | pub mod utils; | ||||||
| @ -598,6 +604,51 @@ pub enum AnalyticsConfig { | |||||||
|     }, |     }, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[async_trait::async_trait] | ||||||
|  | impl SecretsHandler for AnalyticsConfig { | ||||||
|  |     async fn convert_to_raw_secret( | ||||||
|  |         value: SecretStateContainer<Self, SecuredSecret>, | ||||||
|  |         secret_management_client: &dyn SecretManagementInterface, | ||||||
|  |     ) -> CustomResult<SecretStateContainer<Self, RawSecret>, SecretsManagementError> { | ||||||
|  |         let analytics_config = value.get_inner(); | ||||||
|  |         let decrypted_password = match analytics_config { | ||||||
|  |             // Todo: Perform kms decryption of clickhouse password | ||||||
|  |             Self::Clickhouse { .. } => masking::Secret::new(String::default()), | ||||||
|  |             Self::Sqlx { sqlx } | ||||||
|  |             | Self::CombinedCkh { sqlx, .. } | ||||||
|  |             | Self::CombinedSqlx { sqlx, .. } => { | ||||||
|  |                 secret_management_client | ||||||
|  |                     .get_secret(sqlx.password.clone()) | ||||||
|  |                     .await? | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         Ok(value.transition_state(|conf| match conf { | ||||||
|  |             Self::Sqlx { sqlx } => Self::Sqlx { | ||||||
|  |                 sqlx: Database { | ||||||
|  |                     password: decrypted_password, | ||||||
|  |                     ..sqlx | ||||||
|  |                 }, | ||||||
|  |             }, | ||||||
|  |             Self::Clickhouse { clickhouse } => Self::Clickhouse { clickhouse }, | ||||||
|  |             Self::CombinedCkh { sqlx, clickhouse } => Self::CombinedCkh { | ||||||
|  |                 sqlx: Database { | ||||||
|  |                     password: decrypted_password, | ||||||
|  |                     ..sqlx | ||||||
|  |                 }, | ||||||
|  |                 clickhouse, | ||||||
|  |             }, | ||||||
|  |             Self::CombinedSqlx { sqlx, clickhouse } => Self::CombinedSqlx { | ||||||
|  |                 sqlx: Database { | ||||||
|  |                     password: decrypted_password, | ||||||
|  |                     ..sqlx | ||||||
|  |                 }, | ||||||
|  |                 clickhouse, | ||||||
|  |             }, | ||||||
|  |         })) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| impl Default for AnalyticsConfig { | impl Default for AnalyticsConfig { | ||||||
|     fn default() -> Self { |     fn default() -> Self { | ||||||
|         Self::Sqlx { |         Self::Sqlx { | ||||||
|  | |||||||
| @ -233,6 +233,13 @@ pub(crate) async fn fetch_raw_secrets( | |||||||
|             .await |             .await | ||||||
|             .expect("Failed to decrypt master database configuration"); |             .expect("Failed to decrypt master database configuration"); | ||||||
|  |  | ||||||
|  |     #[cfg(feature = "olap")] | ||||||
|  |     #[allow(clippy::expect_used)] | ||||||
|  |     let analytics = | ||||||
|  |         analytics::AnalyticsConfig::convert_to_raw_secret(conf.analytics, secret_management_client) | ||||||
|  |             .await | ||||||
|  |             .expect("Failed to decrypt analytics configuration"); | ||||||
|  |  | ||||||
|     #[cfg(feature = "olap")] |     #[cfg(feature = "olap")] | ||||||
|     #[allow(clippy::expect_used)] |     #[allow(clippy::expect_used)] | ||||||
|     let replica_database = |     let replica_database = | ||||||
| @ -342,7 +349,7 @@ pub(crate) async fn fetch_raw_secrets( | |||||||
|         temp_locker_enable_config: conf.temp_locker_enable_config, |         temp_locker_enable_config: conf.temp_locker_enable_config, | ||||||
|         payment_link: conf.payment_link, |         payment_link: conf.payment_link, | ||||||
|         #[cfg(feature = "olap")] |         #[cfg(feature = "olap")] | ||||||
|         analytics: conf.analytics, |         analytics, | ||||||
|         #[cfg(feature = "kv_store")] |         #[cfg(feature = "kv_store")] | ||||||
|         kv_config: conf.kv_config, |         kv_config: conf.kv_config, | ||||||
|         #[cfg(feature = "frm")] |         #[cfg(feature = "frm")] | ||||||
|  | |||||||
| @ -105,7 +105,7 @@ pub struct Settings<S: SecretState> { | |||||||
|     pub temp_locker_enable_config: TempLockerEnableConfig, |     pub temp_locker_enable_config: TempLockerEnableConfig, | ||||||
|     pub payment_link: PaymentLink, |     pub payment_link: PaymentLink, | ||||||
|     #[cfg(feature = "olap")] |     #[cfg(feature = "olap")] | ||||||
|     pub analytics: AnalyticsConfig, |     pub analytics: SecretStateContainer<AnalyticsConfig, S>, | ||||||
|     #[cfg(feature = "kv_store")] |     #[cfg(feature = "kv_store")] | ||||||
|     pub kv_config: KvConfig, |     pub kv_config: KvConfig, | ||||||
|     #[cfg(feature = "frm")] |     #[cfg(feature = "frm")] | ||||||
|  | |||||||
| @ -200,7 +200,8 @@ impl AppState { | |||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             #[cfg(feature = "olap")] |             #[cfg(feature = "olap")] | ||||||
|             let pool = crate::analytics::AnalyticsProvider::from_conf(&conf.analytics).await; |             let pool = | ||||||
|  |                 crate::analytics::AnalyticsProvider::from_conf(conf.analytics.get_inner()).await; | ||||||
|  |  | ||||||
|             #[cfg(feature = "email")] |             #[cfg(feature = "email")] | ||||||
|             let email_client = Arc::new(create_email_client(&conf).await); |             let email_client = Arc::new(create_email_client(&conf).await); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Chethan Rao
					Chethan Rao