mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor(router): Introduce ApiKeyId id type (#6324)
This commit is contained in:
@ -45,6 +45,9 @@ pub enum ApiEventsType {
|
||||
BusinessProfile {
|
||||
profile_id: id_type::ProfileId,
|
||||
},
|
||||
ApiKey {
|
||||
key_id: id_type::ApiKeyId,
|
||||
},
|
||||
User {
|
||||
user_id: String,
|
||||
},
|
||||
@ -130,10 +133,6 @@ impl_api_event_type!(
|
||||
(
|
||||
String,
|
||||
id_type::MerchantId,
|
||||
(id_type::MerchantId, String),
|
||||
(id_type::MerchantId, &String),
|
||||
(&id_type::MerchantId, &String),
|
||||
(&String, &String),
|
||||
(Option<i64>, Option<i64>, String),
|
||||
(Option<i64>, Option<i64>, id_type::MerchantId),
|
||||
bool
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
use std::{borrow::Cow, fmt::Debug};
|
||||
|
||||
mod api_key;
|
||||
mod customer;
|
||||
mod merchant;
|
||||
mod merchant_connector_account;
|
||||
@ -14,6 +15,7 @@ mod routing;
|
||||
#[cfg(feature = "v2")]
|
||||
mod global_id;
|
||||
|
||||
pub use api_key::ApiKeyId;
|
||||
pub use customer::CustomerId;
|
||||
use diesel::{
|
||||
backend::Backend,
|
||||
|
||||
46
crates/common_utils/src/id_type/api_key.rs
Normal file
46
crates/common_utils/src/id_type/api_key.rs
Normal file
@ -0,0 +1,46 @@
|
||||
crate::id_type!(
|
||||
ApiKeyId,
|
||||
"A type for key_id that can be used for API key IDs"
|
||||
);
|
||||
crate::impl_id_type_methods!(ApiKeyId, "key_id");
|
||||
|
||||
// This is to display the `ApiKeyId` as ApiKeyId(abcd)
|
||||
crate::impl_debug_id_type!(ApiKeyId);
|
||||
crate::impl_try_from_cow_str_id_type!(ApiKeyId, "key_id");
|
||||
|
||||
crate::impl_serializable_secret_id_type!(ApiKeyId);
|
||||
crate::impl_queryable_id_type!(ApiKeyId);
|
||||
crate::impl_to_sql_from_sql_id_type!(ApiKeyId);
|
||||
|
||||
impl ApiKeyId {
|
||||
/// Generate Api Key Id from prefix
|
||||
pub fn generate_key_id(prefix: &'static str) -> Self {
|
||||
Self(crate::generate_ref_id_with_default_length(prefix))
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::events::ApiEventMetric for ApiKeyId {
|
||||
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||
Some(crate::events::ApiEventsType::ApiKey {
|
||||
key_id: self.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::events::ApiEventMetric for (super::MerchantId, ApiKeyId) {
|
||||
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||
Some(crate::events::ApiEventsType::ApiKey {
|
||||
key_id: self.1.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::events::ApiEventMetric for (&super::MerchantId, &ApiKeyId) {
|
||||
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||
Some(crate::events::ApiEventsType::ApiKey {
|
||||
key_id: self.1.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_default_id_type!(ApiKeyId, "key");
|
||||
Reference in New Issue
Block a user