text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response/context.rs | crate: router use rust_i18n::t; use tera::Context; pub fn insert_locales_in_context_for_payout_link_status(context: &mut Context, locale: &str) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response/context.rs | crate: router use rust_i18n::t; use tera::Context; pub fn insert_locales_in_context_for_payout_link(context: &mut Context, locale: &str) { {let i18n_payout_link_title = t!("payout_link.initiate.title", locale = locale);let i18n_january = t!("months.january", locale = locale);<|fim_suffix|> <|fim_middle|> context.insert("i18n_am", &i18n_am);context.insert("i18n_pm", &i18n_pm);}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response/context.rs | crate: router use rust_i18n::t; use tera::Context; pub fn insert_locales_in_context_for_payout_link_status(context: &mut Context, locale: &str) { {let i18n_payout_link_status_title = t!("payout_link.status.title", locale = locale);<|fim_suffix|> <|fim_middle|> context.insert("i18n_seconds_text", &i18n_seconds_text);}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use std::collections::HashMap; use api_models::enums::ReconPermissionScope; use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; use super::permission_groups::{RECON_OPS, RECON_REPORTS}; pub fn get_recon_acl(&self) -> HashMap<Resource, ReconPermissionScope> { { Resource::ReconAndSettlementAnalytics => ReconPermissionScope::Read,<|fim_suffix|> <|fim_middle|> _ => ReconPermissionScope::from(permission_group.scope()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use common_utils::{errors::CustomResult, id_type}; use crate::{core::errors, routes::SessionState}; pub async fn from_role_id_in_lineage( state: &SessionState, role_id: &str, merchant_id: &id_type::MerchantId, org_id: &id_type::OrganizationId, profile_id: &id_type::ProfileId, tenant_id: &id_type::TenantId, ) -> CustomResult<Self, errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use std::collections::HashMap; use api_models::enums::ReconPermissionScope; use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; use super::permission_groups::{RECON_OPS, RECON_REPORTS}; pub fn get_recon_acl(&self) -> HashMap<Resource, ReconPermissionScope> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router fn from(role: diesel_models::role::Role) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use common_utils::{errors::CustomResult, id_type}; use crate::{core::errors, routes::SessionState}; pub async fn from_role_id_org_id_tenant_id( state: &SessionState, role_id: &str, org_id: &id_type::OrganizationId, tenant_id: &id_type::TenantId, ) -> CustomResult<Self, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use common_utils::{errors::CustomResult, id_type}; use crate::{core::errors, routes::SessionState}; pub async fn from_role_id_in_lineage( state: &SessionState, role_id: &str, merchant_id: &id_type::MerchantId, org_id: &id_type::OrganizationId, profile_id: &id_type::ProfileId, tenant_id: &id_type::TenantId, ) -> CustomResult<Self, errors::StorageError> { if let Some(role) = predefined_roles::PREDEFINED_ROLES.get(role_id) { Ok(role.clone()) } else { state .global_store .find_role_by_role_id_in_lineage( role_id, merchant_id, org_id, profile_id, tenant_id, ) .await .map(Self::from) } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use super::{permission_groups::PermissionGroupExt, permissions::Permission}; pub fn check_permission_exists(&self, required_permission: Permission) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use std::collections::HashSet; use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; pub fn get_resources_set(&self) -> HashSet<Resource> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn is_updatable(&self) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn is_internal(&self) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn is_deletable(&self) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn is_invitable(&self) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; pub fn get_entity_type(&self) -> EntityType { self.entity_type }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; pub fn get_scope(&self) -> RoleScope { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router use std::collections::HashSet; use common_enums::{EntityType, PermissionGroup, Resource, RoleScope}; pub fn get_permission_groups(&self) -> Vec<PermissionGroup> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn get_role_name(&self) -> &str { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authorization/roles.rs | crate: router pub fn get_role_id(&self) -> &str { &self.role_id }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use std::collections::HashMap; use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Resource}; use super::permissions::{self, ResourceExt}; fn get_descriptions_for_groups( entity_type: EntityType, groups: Vec<PermissionGroup>, ) -> HashMap<Self, String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use super::permissions::{self, ResourceExt}; fn accessible_groups(&self) -> Vec<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Resource}; use super::permissions::{self, ResourceExt}; fn resources(&self) -> Vec<Resource> { { Self::Operations => OPERATIONS.to_vec(),<|fim_suffix|> <|fim_middle|> Self::ReconReports => RECON_REPORTS.to_vec(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use super::permissions::{self, ResourceExt}; fn accessible_groups(&self) -> Vec<Self> { { Self::OperationsView => vec![Self::OperationsView, Self::ConnectorsView],<|fim_suffix|> <|fim_middle|> Self::AccountManage => vec![Self::AccountView, Self::AccountManage], } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Resource}; use super::permissions::{self, ResourceExt}; fn resources(&self) -> Vec<Resource> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Resource}; use super::permissions::{self, ResourceExt}; fn parent(&self) -> ParentGroup { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/permission_groups.rs | crate: router use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Resource}; use super::permissions::{self, ResourceExt}; fn scope(&self) -> PermissionScope { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/info.rs | crate: router use common_enums::{ParentGroup, PermissionGroup}; fn get_group_description(group: PermissionGroup) -> &'static str { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/info.rs | crate: router use common_enums::{ParentGroup, PermissionGroup}; fn get_group_description(group: PermissionGroup) -> &'static str { { PermissionGroup::OperationsView => { "View Payments, Refunds, Payouts, Mandates, Disputes and Customers" }<|fim_suffix|> <|fim_middle|> PermissionGroup::ReconOpsManage => "Manage all reconciliation operations including reports and analytics", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/info.rs | crate: router use api_models::user_role::GroupInfo; use common_enums::{ParentGroup, PermissionGroup}; fn get_group_info_from_permission_group(group: PermissionGroup) -> GroupInfo { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authorization/info.rs | crate: router use api_models::user_role::GroupInfo; use common_enums::{ParentGroup, PermissionGroup}; pub fn get_group_authorization_info() -> Vec<GroupInfo> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; use masking::{ErasedMaskSerialize, Secret}; use storage_impl::errors::ApiClientError; use crate::{ core::metrics, routes::{app::settings::DecisionConfig, SessionState}, }; async fn call_decision_service<T: ErasedMaskSerialize + Send + 'static>( state: &SessionState, decision_config: &DecisionConfig, rule: T, method: common_utils::request::Method, ) -> CustomResult<(), ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; use masking::{ErasedMaskSerialize, Secret}; use storage_impl::errors::ApiClientError; use crate::{ core::metrics, routes::{app::settings::DecisionConfig, SessionState}, }; pub async fn add_api_key( state: &SessionState, api_key: Secret<String>, merchant_id: common_utils::id_type::MerchantId, key_id: common_utils::id_type::ApiKeyId, expiry: Option<u64>, ) -> CustomResult<(), ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; pub fn convert_expiry(expiry: time::PrimitiveDateTime) -> u64 { { i64::MIN..=0 => 0,<|fim_suffix|> <|fim_middle|> _ => output as u64, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use crate::{ core::metrics, routes::{app::settings::DecisionConfig, SessionState}, }; pub fn spawn_tracked_job<E, F>(future: F, request_type: &'static str) where E: std::fmt::Debug, F: futures::Future<Output = Result<(), E>> + Send + 'static, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; pub fn convert_expiry(expiry: time::PrimitiveDateTime) -> u64 { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; use masking::{ErasedMaskSerialize, Secret}; use storage_impl::errors::ApiClientError; use crate::{ core::metrics, routes::{app::settings::DecisionConfig, SessionState}, }; pub async fn revoke_api_key( state: &SessionState, api_key: Secret<String>, ) -> CustomResult<(), ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/decision.rs | crate: router use common_utils::{errors::CustomResult, request::RequestContent}; use masking::{ErasedMaskSerialize, Secret}; use storage_impl::errors::ApiClientError; use crate::{ core::metrics, routes::{app::settings::DecisionConfig, SessionState}, }; pub async fn add_publishable_key( state: &SessionState, api_key: Secret<String>, merchant_id: common_utils::id_type::MerchantId, expiry: Option<u64>, ) -> CustomResult<(), ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router use std::{borrow::Cow, string::ToString}; use actix_web::http::header::HeaderMap; use common_utils::{ crypto::VerifySignature, id_type::{ApiKeyId, MerchantId}, }; use error_stack::ResultExt; use hyperswitch_domain_models::errors::api_error_response::ApiErrorResponse; use crate::core::errors::RouterResult; pub fn from_headers(headers: &HeaderMap) -> RouterResult<Self> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router use common_utils::{ crypto::VerifySignature, id_type::{ApiKeyId, MerchantId}, }; fn append_api_key(prefix: &str, data: &Option<ApiKeyId>) -> String { { Some(inner) => format!("{}:{}", prefix, inner.get_string_repr()),<|fim_suffix|> <|fim_middle|> None => prefix.to_string(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router use common_utils::{ crypto::VerifySignature, id_type::{ApiKeyId, MerchantId}, }; fn append_api_key(prefix: &str, data: &Option<ApiKeyId>) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router fn append_option(prefix: &str, data: &Option<String>) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router fn generate_payload(&self) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication/detached.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{ crypto::VerifySignature, id_type::{ApiKeyId, MerchantId}, }; pub fn verify_checksum( &self, headers: &HeaderMap, algo: impl VerifySignature, secret: &[u8], ) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use common_utils::{errors::CustomResult, pii, types::theme::EmailThemeConfig}; use external_services::email::{EmailContents, EmailData, EmailError}; use crate::{ core::errors::{UserErrors, UserResult}, services::jwt, types::domain, }; async fn get_email_data(&self, base_url: &str) -> CustomResult<EmailContents, EmailError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use external_services::email::{EmailContents, EmailData, EmailError}; pub fn get_html_body(email_body: EmailBody) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use common_utils::{errors::CustomResult, pii, types::theme::EmailThemeConfig}; use external_services::email::{EmailContents, EmailData, EmailError}; async fn get_email_data(&self, _base_url: &str) -> CustomResult<EmailContents, EmailError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use api_models::user::dashboard_metadata::ProdIntent; use common_enums::{EntityType, MerchantProductType}; use common_utils::{errors::CustomResult, pii, types::theme::EmailThemeConfig}; use external_services::email::{EmailContents, EmailData, EmailError}; use crate::{configs, consts, routes::SessionState}; use crate::{ core::errors::{UserErrors, UserResult}, services::jwt, types::domain, }; pub fn new( state: &SessionState, data: ProdIntent, theme_id: Option<String>, theme_config: EmailThemeConfig, ) -> UserResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use api_models::user::dashboard_metadata::ProdIntent; use crate::{configs, consts, routes::SessionState}; pub fn get_base_url(state: &SessionState) -> &str { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use api_models::user::dashboard_metadata::ProdIntent; pub fn get_link_with_token( base_url: impl std::fmt::Display, token: impl std::fmt::Display, action: impl std::fmt::Display, auth_id: &Option<impl std::fmt::Display>, theme_id: &Option<impl std::fmt::Display>, ) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use crate::{ core::errors::{UserErrors, UserResult}, services::jwt, types::domain, }; pub fn get_flow(&self) -> domain::Origin { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router pub fn get_entity(&self) -> Option<&Entity> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use common_utils::{errors::CustomResult, pii, types::theme::EmailThemeConfig}; use external_services::email::{EmailContents, EmailData, EmailError}; use crate::{ core::errors::{UserErrors, UserResult}, services::jwt, types::domain, }; pub fn get_email(&self) -> UserResult<domain::UserEmail> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use external_services::email::{EmailContents, EmailData, EmailError}; use crate::{configs, consts, routes::SessionState}; use crate::{ core::errors::{UserErrors, UserResult}, services::jwt, types::domain, }; pub async fn new_token( email: domain::UserEmail, entity: Option<Entity>, flow: domain::Origin, settings: &configs::Settings, ) -> UserResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router pub fn get_entity_id(&self) -> &str { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use common_enums::{EntityType, MerchantProductType}; pub fn get_entity_type(&self) -> EntityType { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/email/types.rs | crate: router use external_services::email::{EmailContents, EmailData, EmailError}; pub fn get_html_body(email_body: EmailBody) -> String { { EmailBody::Verify { link, entity_name, entity_logo_url, primary_color, background_color, foreground_color, } => { format!( include_str!("assets/verify.html"), link = link, entity_name = entity_name, entity_logo_url = entity_logo_url, primary_color = primary_color, background_color = background_color, foreground_color = foreground_color ) } EmailBody::Reset { link, user_name, entity_name, entity_logo_url, primary_color, background_color, foreground_color, } => { format!( include_str!("assets/reset.html"), link = link, username = user_name, entity_name = entity_name, entity_logo_url = entity_logo_url, primary_color = primary_color, background_color = background_color, foreground_color = foreground_color ) } EmailBody::MagicLink { link, user_name, entity_name, entity_logo_url, primary_color, background_color, foreground_color, } => { format!( include_str!("assets/magic_link.html"), username = user_name, link = link, entity_name = entity_name, entity_logo_url = entity_logo_url, primary_color = primary_color, background_color = background_color, foreground_color = foreground_color ) }<|fim_suffix|> <|fim_middle|> EmailBody::ProFeatureRequest { feature_name, merchant_id, user_name, user_email, } => format!( "Dear Hyperswitch Support Team, Dashboard Pro Feature Request, Feature name : {feature_name} Merchant ID : {} Merchant Name : {user_name} Email : {user_email} (note: This is an auto generated email. Use merchant email for any further communications)", merchant_id.get_string_repr() ), EmailBody::ApiKeyExpiryReminder { expires_in, api_key_name, prefix, } => format!( include_str!("assets/api_key_expiry_reminder.html"), api_key_name = api_key_name, prefix = prefix, expires_in = expires_in, ), EmailBody::WelcomeToCommunity => { include_str!("assets/welcome_to_community.html").to_string() } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/error.rs | crate: src use reqwest::StatusCode; fn into_response(self) -> axum::response::Response { { Self::CustodianLocked => ( hyper::StatusCode::UNAUTHORIZED, axum::Json(ApiErrorResponse::new( error_codes::TE_00, "Custodian is locked".into(), None, )), ) .into_response(),<|fim_suffix|> <|fim_middle|> data @ Self::MerchantError => ( hyper::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(ApiErrorResponse::new( error_codes::TE_02, format!("{}", data), None, )), ) .into_response(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/error.rs | crate: src fn new(code: &'static str, message: String, data: Option<serde_json::Value>) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/error.rs | crate: src fn into_response(self) -> axum::response::Response { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/tenant.rs | crate: src use std::{collections::HashSet, sync::Arc}; use rustc_hash::FxHashMap; use tokio::sync::RwLock; use crate::config::TenantConfig; use crate::routes::key_custodian::CustodianKeyState; use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; /// /// # Panics /// /// If tenant specific AppState construction fails when `key_custodian` feature is disabled /// pub async fn new(global_config: GlobalConfig) -> Arc<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/tenant.rs | crate: src use std::{collections::HashSet, sync::Arc}; use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; pub async fn get_app_state_of_tenant( &self, tenant_id: &str, ) -> Result<Arc<TenantAppState>, ApiError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/tenant.rs | crate: src use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; pub async fn is_custodian_unlocked(&self, tenant_id: &str) -> Result<(), ApiError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/tenant.rs | crate: src use std::{collections::HashSet, sync::Arc}; use crate::config::TenantConfig; use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; pub async fn set_app_state(&self, state: TenantAppState) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/tenant.rs | crate: src use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; pub fn is_known_tenant(&self, tenant_id: &str) -> Result<(), ApiError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch-card-vault/src/tenant.rs | crate: src use std::{collections::HashSet, sync::Arc}; use crate::{api_client::ApiClient, app::TenantAppState, config::GlobalConfig, error::ApiError}; pub async fn get_app_state_of_tenant( &self, tenant_id: &str, ) -> Result<Arc<TenantAppState>, ApiError> { self.tenants_app_state .read() .await .get(tenant_id) .cloned() .ok_or(ApiError::CustodianLocked) }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; use error_stack::ResultExt; pub async fn fetch_raw_secrets( &mut self, ) -> error_stack::Result<(), error::ConfigurationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; fn test_hashicorp_case() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; fn test_aws_kms_case() { { SecretsManagementConfig::AwsKms { aws_kms } => { assert!(aws_kms.key_id == "123" && aws_kms.region == "abc") }<|fim_suffix|> <|fim_middle|> _ => assert!(false), } }
ast_fragments
// file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; fn test_hashicorp_case() { let data = r#" [secrets_management] secrets_manager = "hashi_corp_vault" [secrets_management.hashi_corp_vault] url = "123" token = "abc" "#; let parsed: TestDeser = serde_path_to_error::deserialize( config::Config::builder() .add_source(config::File::from_str(data, config::FileFormat::Toml)) .build() .unwrap(), ) .unwrap(); match parsed.secrets_management { SecretsManagementConfig::HashiCorpVault { hashi_corp_vault } => { assert!(hashi_corp_vault.url == "123" && hashi_corp_vault.token.expose() == "abc") } _ => assert!(false), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; fn test_aws_kms_case() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; fn test_non_case() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch-card-vault/src/config.rs | crate: src use std::{ collections::HashMap, ops::{Deref, DerefMut}, path::PathBuf, }; fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Development => write!(f, "development"), Self::Release => write!(f, "release"), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src pub const fn config_path(self) -> &'static str { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src pub const fn current_env() -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; use error_stack::ResultExt; pub fn validate(&self) -> error_stack::Result<(), error::ConfigurationError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; use std::{ collections::HashMap, ops::{Deref, DerefMut}, path::PathBuf, }; /// Config path. pub fn config_path(environment: &Env, explicit_config_path: Option<PathBuf>) -> PathBuf { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; pub fn builder( environment: &Env, ) -> Result<config::ConfigBuilder<config::builder::DefaultState>, config::ConfigError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; use std::{ collections::HashMap, ops::{Deref, DerefMut}, path::PathBuf, }; /// Function to build the configuration by picking it from default locations pub fn new_with_config_path( explicit_config_path: Option<PathBuf>, ) -> Result<Self, config::ConfigError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use crate::{ api_client::ApiClientConfig, crypto::secrets_manager::{ secrets_interface::SecretManager, secrets_management::SecretsManagementConfig, }, error, logger::config::Log, }; /// Function to build the configuration by picking it from default locations pub fn new() -> Result<Self, config::ConfigError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src use std::{ collections::HashMap, ops::{Deref, DerefMut}, path::PathBuf, }; /// Get the origin directory of the project pub fn workspace_path() -> PathBuf { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/config.rs | crate: src fn deserialize_hex<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error> where D: serde::Deserializer<'de>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch-card-vault/src/config.rs | crate: src /// /// # Panics /// /// Never, as tenant_id would already be validated from [`crate::custom_extractors::TenantId`] custom extractor /// pub fn from_global_config(global_config: &GlobalConfig, tenant_id: String) -> Self { Self { tenant_id: tenant_id.clone(), locker_secrets: global_config.secrets.clone(), #[allow(clippy::unwrap_used)] tenant_secrets: global_config .tenant_secrets .get(&tenant_id) .cloned() .unwrap(), #[cfg(feature = "external_key_manager")] external_key_manager: global_config.external_key_manager.clone(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/app.rs | crate: src use error_stack::ResultExt; use std::sync::Arc; use crate::{ api_client::ApiClient, config::{self, GlobalConfig, TenantConfig}, error, logger, routes::{self, routes_v2}, storage, tenant::GlobalAppState, utils, }; use crate::storage::caching::Caching; type Storage = Caching<storage::Storage>; type Storage = storage::Storage; /// /// Construct new app state with configuration /// pub async fn new( global_config: &GlobalConfig, tenant_config: TenantConfig, api_client: ApiClient, ) -> error_stack::Result<Self, error::ConfigurationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch-card-vault/src/app.rs | crate: src use error_stack::ResultExt; use std::sync::Arc; use crate::{ api_client::ApiClient, config::{self, GlobalConfig, TenantConfig}, error, logger, routes::{self, routes_v2}, storage, tenant::GlobalAppState, utils, }; use crate::storage::caching::Caching; type Storage = Caching<storage::Storage>; type Storage = storage::Storage; /// /// Construct new app state with configuration /// pub async fn new( global_config: &GlobalConfig, tenant_config: TenantConfig, api_client: ApiClient, ) -> error_stack::Result<Self, error::ConfigurationError> { #[allow(clippy::map_identity)] let db = storage::Storage::new( &global_config.database, &tenant_config.tenant_secrets.schema, ) .await .map( #[cfg(feature = "caching")] Caching::implement_cache(&global_config.cache), #[cfg(not(feature = "caching"))] std::convert::identity, ) .change_context(error::ConfigurationError::DatabaseError)?; Ok(Self { db, api_client, config: tenant_config, }) }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/app.rs | crate: src use axum::{extract::Request, routing::post}; use axum_server::tls_rustls::RustlsConfig; use tower_http::trace as tower_trace; use crate::middleware as custom_middleware; use axum::middleware; use std::sync::Arc; use crate::{ api_client::ApiClient, config::{self, GlobalConfig, TenantConfig}, error, logger, routes::{self, routes_v2}, storage, tenant::GlobalAppState, utils, }; /// /// The server responsible for the custodian APIs and main locker APIs this will perform all storage, retrieval and /// deletion operation /// pub async fn server_builder( global_app_state: Arc<GlobalAppState>, ) -> Result<(), error::ConfigurationError> where { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_n_equal() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_n_not_equal() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_n_equal() { let data = "Hello, World!"; let key = "key"; let algo1 = HmacSha512::<10>::new(key.as_bytes().to_vec().into()); let algo2 = HmacSha512::<10>::new(key.as_bytes().to_vec().into()); let hash1 = algo1.encode(data.as_bytes().to_vec().into()).unwrap(); let hash2 = algo2.encode(data.as_bytes().to_vec().into()).unwrap(); assert_eq!(hash1, hash2); }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_key_equal() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_key_not_equal() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_input_data_not_equal() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src fn test_input_data_equal() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src use masking::{PeekInterface, Secret}; use ring::hmac; fn encode(&self, input: Secret<Vec<u8>>) -> Self::ReturnType<Secret<Vec<u8>>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src use masking::{PeekInterface, Secret}; pub fn new(key: masking::Secret<Vec<u8>>) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/hash_manager/managers/sha.rs | crate: src use ring::hmac; fn encode(&self, input: Vec<u8>) -> Self::ReturnType<Vec<u8>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src use ring::aead::{self, BoundKey}; fn test_gcm_aes_256_decode_message() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src use crate::{ crypto::encryption_manager::encryption_interface::Encryption, error::{self, ContainerError}, }; use ring::aead::{self, BoundKey}; /// Returns the current nonce value as bytes. fn current(&self) -> [u8; ring::aead::NONCE_LEN] { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src fn test_gcm_aes_256_encode_message() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch-card-vault/src/crypto/encryption_manager/managers/aes.rs | crate: src use crate::{ crypto::encryption_manager::encryption_interface::Encryption, error::{self, ContainerError}, }; use error_stack::ResultExt; use ring::aead::{self, BoundKey}; pub fn generate_aes256_key() -> [u8; 32] { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments