text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_id_type_from_header_if_present<T>(&self, key: &str) -> RouterResult<Option<T>> where T: TryFrom< std::borrow::Cow<'static, str>, Error = error_stack::Report<errors::ValidationError>, >, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserIdFromAuth, AuthenticationType)> { let payload = parse_jwt_payload::<A, SinglePurposeOrLoginToken>(request_headers, state).await?; if payload.check_in_blacklist(state).await? { return Err(errors::ApiErrorResponse::InvalidJwtToken.into()); } let purpose_exists = payload.purpose.is_some(); let role_id_exists = payload.role_id.is_some(); if purpose_exists ^ role_id_exists { Ok(( UserIdFromAuth { user_id: payload.user_id.clone(), tenant_id: payload.tenant_id, }, AuthenticationType::SinglePurposeOrLoginJwt { user_id: payload.user_id, purpose: payload.purpose, role_id: payload.role_id, }, )) } else { Err(errors::ApiErrorResponse::InvalidJwtToken.into()) } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserIdFromAuth, AuthenticationType)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(Option<UserFromSinglePurposeToken>, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserFromSinglePurposeToken, AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn construct_authentication_data<A>( state: &A, merchant_id: &id_type::MerchantId, request_headers: &HeaderMap, profile_id: Option<id_type::ProfileId>, ) -> RouterResult<AuthenticationData> where A: SessionStateInfo + Sync, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn check_service_type( &self, required_service_type: &ExternalServiceType, ) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(UserFromTokenWithRoleInfo, AuthenticationType)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn check_service_type( &self, required_service_type: &ExternalServiceType, ) -> RouterResult<()> { Ok(fp_utils::when( &self.external_service_type != required_service_type, || { Err(errors::ApiErrorResponse::AccessForbidden { resource: required_service_type.to_string(), }) }, )?) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use common_utils::{date_time, fp_utils, id_type}; use super::jwt; use crate::configs::Settings; use crate::consts; use crate::core::errors::UserResult; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn new_token( user_id: String, merchant_id: id_type::MerchantId, settings: &Settings, external_service_type: ExternalServiceType, ) -> UserResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn throw_error_if_platform_merchant_authentication_required( request_headers: &HeaderMap, ) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn get_and_validate_connected_merchant_id( request_headers: &HeaderMap, merchant_account: &domain::MerchantAccount, ) -> RouterResult<Option<id_type::MerchantId>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn get_platform_merchant_account<A>( state: &A, request_headers: &HeaderMap, merchant_account: domain::MerchantAccount, ) -> RouterResult<(domain::MerchantAccount, Option<domain::MerchantAccount>)> where A: SessionStateInfo + Sync, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn auth_type<'a, T, A>( default_auth: &'a dyn AuthenticateAndFetch<T, A>, jwt_auth_type: &'a dyn AuthenticateAndFetch<T, A>, headers: &HeaderMap, ) -> &'a dyn AuthenticateAndFetch<T, A> where { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn strip_jwt_token(token: &str) -> RouterResult<&str> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use error_stack::{report, ResultExt}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_cookie_from_header(headers: &HeaderMap) -> RouterResult<&str> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_jwt_from_authorization_header(headers: &HeaderMap) -> RouterResult<&str> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use error_stack::{report, ResultExt}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_id_type_by_key_from_headers<T: FromStr>( key: String, headers: &HeaderMap, ) -> RouterResult<Option<T>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_header_value_by_key(key: String, headers: &HeaderMap) -> RouterResult<Option<&str>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_api_key(headers: &HeaderMap) -> RouterResult<&str> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation}; use serde::Serialize; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn decode_jwt<T>(token: &str, state: &impl SessionStateInfo) -> RouterResult<T> where T: serde::de::DeserializeOwned, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn is_jwt_auth(headers: &HeaderMap) -> bool { let header_map_struct = HeaderMapStruct::new(headers); match header_map_struct.get_auth_string_from_header() { Ok(auth_str) => auth_str.starts_with("Bearer"), Err(_) => get_cookie_from_header(headers) .and_then(cookies::get_jwt_from_cookies) .is_ok(), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn is_ephemeral_auth<A: SessionStateInfo + Sync + Send>( headers: &HeaderMap, ) -> RouterResult<Box<dyn AuthenticateAndFetch<AuthenticationData, A>>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_auth_type_and_flow<A: SessionStateInfo + Sync + Send>( headers: &HeaderMap, ) -> RouterResult<( Box<dyn AuthenticateAndFetch<AuthenticationData, A>>, api::AuthFlow, )> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); fn get_client_secret(&self) -> Option<&String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); fn get_client_secret(&self) -> Option<&String> { self.client_secret.as_ref() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn api_or_client_auth<'a, T, A>( api_auth: &'a dyn AuthenticateAndFetch<T, A>, client_auth: &'a dyn AuthenticateAndFetch<T, A>, headers: &HeaderMap, ) -> &'a dyn AuthenticateAndFetch<T, A> where { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_auth_string_from_header(&self) -> RouterResult<&str> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_organization_id_from_header(&self) -> RouterResult<id_type::OrganizationId> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); /// Get the id type from the header /// This can be used to extract lineage ids from the headers pub fn get_id_type_from_header< T: TryFrom< std::borrow::Cow<'static, str>, Error = error_stack::Report<errors::ValidationError>, >, >( &self, key: &str, ) -> RouterResult<T> { self.get_mandatory_header_value_by_key(key) .map(|val| val.to_owned()) .and_then(|header_value| { T::try_from(std::borrow::Cow::Owned(header_value)).change_context( errors::ApiErrorResponse::InvalidRequestData { message: format!("`{}` header is invalid", key), }, ) }) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use actix_web::http::header::HeaderMap; use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn get_mandatory_header_value_by_key( &self, key: &str, ) -> Result<&str, error_stack::Report<errors::ApiErrorResponse>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn new(headers: &'a HeaderMap) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn fetch_merchant_key_store_and_account<A: SessionStateInfo + Sync>( merchant_id: &id_type::MerchantId, state: &A, ) -> RouterResult<(domain::MerchantKeyStore, domain::MerchantAccount)> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn get_auth_type(&self) -> detached::PayloadType { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, _request_headers: &HeaderMap, _state: &A, ) -> RouterResult<(Option<T>, AuthenticationType)> { Ok((None, AuthenticationType::NoAuth)) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; async fn authenticate_and_fetch( &self, _request_headers: &HeaderMap, _state: &A, ) -> RouterResult<((), AuthenticationType)> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn get_merchant_id(&self) -> Option<&id_type::MerchantId> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn get_merchant_id(&self) -> Option<&id_type::MerchantId> { None }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use common_utils::{date_time, fp_utils, id_type}; use super::jwt; use crate::configs::Settings; use crate::consts; use crate::core::errors::UserResult; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn new_token( user_id: String, merchant_id: id_type::MerchantId, role_id: String, settings: &Settings, org_id: id_type::OrganizationId, profile_id: id_type::ProfileId, tenant_id: Option<id_type::TenantId>, ) -> UserResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use std::str::FromStr; use common_enums::TokenPurpose; use common_utils::{date_time, fp_utils, id_type}; use super::jwt; use crate::configs::Settings; use crate::consts; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub async fn new_token( user_id: String, purpose: TokenPurpose, origin: domain::Origin, settings: &Settings, path: Vec<TokenPurpose>, tenant_id: Option<id_type::TenantId>, ) -> UserResult<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use common_utils::{date_time, fp_utils, id_type}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); pub fn get_merchant_id(&self) -> Option<&id_type::MerchantId> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; fn data(&self) -> error_stack::Result<Self::Data, events::EventsError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/authentication.rs | crate: router use actix_web::http::header::HeaderMap; use common_utils::{date_time, fp_utils, id_type}; use error_stack::{report, ResultExt}; use self::blacklist::BlackList; use self::detached::ExtractedPayload; use self::detached::GetAuthType; use super::authorization::{self, permissions::Permission}; use crate::core::errors::UserResult; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, headers, routes::app::SessionStateInfo, services::api, types::{domain, storage}, utils::OptionExt, }; pub type AuthenticationDataWithUserId = (AuthenticationData, String); async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &A, ) -> RouterResult<(AuthenticationData, AuthenticationType)> { {let header_map_struct = HeaderMapStruct::new(request_headers);<|fim_suffix|> <|fim_middle|> Ok(( auth.clone(), AuthenticationType::ApiKey { merchant_id: auth.merchant_account.get_id().clone(), key_id: stored_api_key.key_id, }, ))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router fn get_hyper_loader_sdk(sdk_url: &str) -> String { format!("<script src=\"{sdk_url}\" onload=\"initializeSDK()\"></script>") } fn get_preload_link_html_template(sdk_url: &str) -> String { format!( r#"<link rel="preload" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800" as="style"> <link rel="preload" href="{sdk_url}" as="script">"#, sdk_url = sdk_url ) } pub fn get_payment_link_status( payment_link_data: PaymentLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { let mut tera = Tera::default(); // Add modification to css template with dynamic data let css_template = include_str!("../core/payment_link/payment_link_status/status.css").to_string(); let _ = tera.add_raw_template("payment_link_css", &css_template); let mut context = Context::new(); context.insert("css_color_scheme", &payment_link_data.css_script); let rendered_css = match tera.render("payment_link_css", &context) { pub fn get_payment_link_status( payment_link_data: PaymentLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router use common_utils::{ consts::{DEFAULT_TENANT, TENANT_HEADER, X_HS_LATENCY}, errors::{ErrorSwitch, ReportSwitchExt}, request::RequestContent, }; pub use hyperswitch_domain_models::{ api::{ ApplicationResponse, GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinks, PaymentLinkAction, PaymentLinkFormData, PaymentLinkStatusData, RedirectionFormData, }, payment_method_data::PaymentMethodData, router_response_types::RedirectForm, }; use tera::{Context, Error as TeraError, Tera}; use crate::{ configs::Settings, consts, core::{ api_locking, errors::{self, CustomResult}, payments, }, events::{ api_logs::{ApiEvent, ApiEventMetric, ApiEventsType}, connector_api_logs::ConnectorEvent, }, headers, logger, routes::{ app::{AppStateInfo, ReqState, SessionStateInfo}, metrics, AppState, SessionState, }, services::{ connector_integration_interface::RouterDataConversion, generic_link_response::build_generic_link_html, }, types::{self, api, ErrorResponse}, utils, }; fn build_payment_link_template( payment_link_data: PaymentLinkFormData, ) -> CustomResult<(Tera, Context), errors::ApiErrorResponse> { {let mut tera = Tera::default();<|fim_suffix|> <|fim_middle|> Ok((tera, context))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_server_error_json_response<T: body::MessageBody + 'static>( response: T, ) -> HttpResponse { HttpResponse::InternalServerError() .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_response_json_with_headers<T: body::MessageBody + 'static>( response: T, headers: Vec<(String, Maskable<String>)>, request_duration: Option<Duration>, ) -> HttpResponse { let mut response_builder = HttpResponse::Ok(); for (header_name, header_value) in headers { let is_sensitive_header = header_value.is_masked(); let mut header_value = header_value.into_inner(); if header_name == X_HS_LATENCY { if let Some(request_duration) = request_duration { if let Ok(external_latency) = header_value.parse::<u128>() { let updated_duration = request_duration.as_millis() - external_latency; pub fn http_response_json_with_headers<T: body::MessageBody + 'static>( response: T, headers: Vec<(String, Maskable<String>)>, request_duration: Option<Duration>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router use common_utils::{ consts::{DEFAULT_TENANT, TENANT_HEADER, X_HS_LATENCY}, errors::{ErrorSwitch, ReportSwitchExt}, request::RequestContent, }; use error_stack::{report, Report, ResultExt}; use serde_json::json; use self::request::{HeaderExt, RequestBuilderExt}; use crate::{ configs::Settings, consts, core::{ api_locking, errors::{self, CustomResult}, payments, }, events::{ api_logs::{ApiEvent, ApiEventMetric, ApiEventsType}, connector_api_logs::ConnectorEvent, }, headers, logger, routes::{ app::{AppStateInfo, ReqState, SessionStateInfo}, metrics, AppState, SessionState, }, services::{ connector_integration_interface::RouterDataConversion, generic_link_response::build_generic_link_html, }, types::{self, api, ErrorResponse}, utils, }; fn embed(self) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router while let Some(err) = source { if let Some(hyper_err) = err.downcast_ref::<hyper::Error>() { if hyper_err.is_incomplete_message() { return true; } } source = err.source(); } false } #[instrument(skip_all)] async fn handle_response( response: CustomResult<reqwest::Response, errors::ApiClientError>, ) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> { response .map(|response| async { logger::info!(?response); let status_code = response.status().as_u16(); let headers = Some(response.headers().to_owned()); match status_code { 200..=202 | 302 | 204 => { // If needed add log line // logger:: error!( error_parsing_response=?err); async fn handle_response( response: CustomResult<reqwest::Response, errors::ApiClientError>, ) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router )) } } } } None => Ok(router_data), } } } } #[instrument(skip_all)] pub async fn call_connector_api( state: &SessionState, request: Request, flow_name: &str, ) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> { let current_time = Instant::now(); let headers = request.headers.clone(); let url = request.url.clone(); let response = state .api_client .send_request(state, request, None, true) .await; pub async fn call_connector_api( state: &SessionState, request: Request, flow_name: &str, ) -> CustomResult<Result<types::Response, types::Response>, errors::ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router fn get_hyper_loader_sdk(sdk_url: &str) -> String { format!("<script src=\"{sdk_url}\" onload=\"initializeSDK()\"></script>") } fn get_preload_link_html_template(sdk_url: &str) -> String { format!( r#"<link rel="preload" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800" as="style"> <link rel="preload" href="{sdk_url}" as="script">"#, sdk_url = sdk_url ) } pub fn get_payment_link_status( payment_link_data: PaymentLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { let mut tera = Tera::default(); // Add modification to css template with dynamic data let css_template = include_str!("../core/payment_link/payment_link_status/status.css").to_string(); let _ = tera.add_raw_template("payment_link_css", &css_template); let mut context = Context::new(); context.insert("css_color_scheme", &payment_link_data.css_script); let rendered_css = match tera.render("payment_link_css", &context) { pub fn get_payment_link_status( payment_link_data: PaymentLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { {let mut tera = Tera::default();<|fim_suffix|> <|fim_middle|> match tera.render("payment_link_status", &context) { Ok(rendered_html) => Ok(rendered_html), Err(tera_error) => { crate::logger::warn!("{tera_error}"); Err(errors::ApiErrorResponse::InternalServerError)? } }}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router use std::{ collections::{HashMap, HashSet}, error::Error, fmt::Debug, future::Future, str, sync::Arc, time::{Duration, Instant}, }; fn get_hyper_loader_sdk(sdk_url: &str) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router use serde_json::json; fn test_mime_essence() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/api.rs | crate: router use std::{ collections::{HashMap, HashSet}, error::Error, fmt::Debug, future::Future, str, sync::Arc, time::{Duration, Instant}, }; fn get_hyper_loader_sdk(sdk_url: &str) -> String { format!("<script src=\"{sdk_url}\" onload=\"initializeSDK()\"></script>") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router include_str!("../core/payment_link/payment_link_initiate/payment_link_initiator.js") .to_string(); context.insert("payment_link_initiator", &payment_link_initiator); tera.render("payment_link", &context) .map_err(|tera_error: TeraError| { crate::logger::warn!("{tera_error}"); report!(errors::ApiErrorResponse::InternalServerError) }) .attach_printable("Error while rendering open payment link's HTML template") } pub fn build_secure_payment_link_html( payment_link_data: PaymentLinkFormData, ) -> CustomResult<String, errors::ApiErrorResponse> { let (tera, mut context) = build_payment_link_template(payment_link_data) .attach_printable("Failed to build payment link's HTML template")?; let payment_link_initiator = include_str!("../core/payment_link/payment_link_initiate/secure_payment_link_initiator.js") .to_string(); context.insert("payment_link_initiator", &payment_link_initiator); tera.render("payment_link", &context) .map_err(|tera_error: TeraError| { crate::logger::warn!("{tera_error}"); pub fn build_secure_payment_link_html( payment_link_data: PaymentLinkFormData, ) -> CustomResult<String, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router "hyperloader_sdk_link", &get_hyper_loader_sdk(&payment_link_data.sdk_url), ); context.insert("locale_template", &locale_template); context.insert("rendered_css", &rendered_css); context.insert("rendered_js", &rendered_js); context.insert("logging_template", &logging_template); Ok((tera, context)) } pub fn build_payment_link_html( payment_link_data: PaymentLinkFormData, ) -> CustomResult<String, errors::ApiErrorResponse> { let (tera, mut context) = build_payment_link_template(payment_link_data) .attach_printable("Failed to build payment link's HTML template")?; let payment_link_initiator = include_str!("../core/payment_link/payment_link_initiate/payment_link_initiator.js") .to_string(); context.insert("payment_link_initiator", &payment_link_initiator); tera.render("payment_link", &context) .map_err(|tera_error: TeraError| { crate::logger::warn!("{tera_error}"); pub fn build_payment_link_html( payment_link_data: PaymentLinkFormData, ) -> CustomResult<String, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/services/api.rs | crate: router redirection_response: api::RedirectionResponse, ) -> HttpResponse { HttpResponse::Ok() .content_type(mime::APPLICATION_JSON) .append_header(( "Location", redirection_response.return_url_with_query_params, )) .status(http::StatusCode::FOUND) .body(response) } pub fn http_response_err<T: body::MessageBody + 'static>(response: T) -> HttpResponse { HttpResponse::BadRequest() .content_type(mime::APPLICATION_JSON) .body(response) } pub trait Authenticate { fn get_client_secret(&self) -> Option<&String> { None } } #[cfg(feature = "v1")] pub fn http_response_err<T: body::MessageBody + 'static>(response: T) -> HttpResponse { HttpResponse::BadRequest() .content_type(mime::APPLICATION_JSON) .body(response) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router res_builder.insert_header((HeaderName::from_static(key), header_val)); } } } res_builder.body(res) } pub fn http_response_ok() -> HttpResponse { HttpResponse::Ok().finish() } pub fn http_redirect_response<T: body::MessageBody + 'static>( response: T, redirection_response: api::RedirectionResponse, ) -> HttpResponse { HttpResponse::Ok() .content_type(mime::APPLICATION_JSON) .append_header(( "Location", redirection_response.return_url_with_query_params, )) .status(http::StatusCode::FOUND) .body(response) } pub fn http_redirect_response<T: body::MessageBody + 'static>( response: T, redirection_response: api::RedirectionResponse, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router if let Some(headers) = optional_headers { for (key, value) in headers { if let Ok(header_val) = HeaderValue::try_from(value) { res_builder.insert_header((HeaderName::from_static(key), header_val)); } } } res_builder.body(res) } pub fn http_response_ok() -> HttpResponse { HttpResponse::Ok().finish() } pub fn http_redirect_response<T: body::MessageBody + 'static>( response: T, redirection_response: api::RedirectionResponse, ) -> HttpResponse { HttpResponse::Ok() .content_type(mime::APPLICATION_JSON) .append_header(( "Location", redirection_response.return_url_with_query_params, pub fn http_response_ok() -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router pub fn http_response_plaintext<T: body::MessageBody + 'static>(res: T) -> HttpResponse { HttpResponse::Ok().content_type(mime::TEXT_PLAIN).body(res) } pub fn http_response_file_data<T: body::MessageBody + 'static>( res: T, content_type: mime::Mime, ) -> HttpResponse { HttpResponse::Ok().content_type(content_type).body(res) } pub fn http_response_html_data<T: body::MessageBody + 'static>( res: T, optional_headers: Option<HashSet<(&'static str, String)>>, ) -> HttpResponse { let mut res_builder = HttpResponse::Ok(); res_builder.content_type(mime::TEXT_HTML); if let Some(headers) = optional_headers { for (key, value) in headers { if let Ok(header_val) = HeaderValue::try_from(value) { res_builder.insert_header((HeaderName::from_static(key), header_val)); } } pub fn http_response_html_data<T: body::MessageBody + 'static>( res: T, optional_headers: Option<HashSet<(&'static str, String)>>, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router response_builder.append_header((header_name, header_value)); } response_builder .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_response_plaintext<T: body::MessageBody + 'static>(res: T) -> HttpResponse { HttpResponse::Ok().content_type(mime::TEXT_PLAIN).body(res) } pub fn http_response_file_data<T: body::MessageBody + 'static>( res: T, content_type: mime::Mime, ) -> HttpResponse { HttpResponse::Ok().content_type(content_type).body(res) } pub fn http_response_html_data<T: body::MessageBody + 'static>( res: T, optional_headers: Option<HashSet<(&'static str, String)>>, ) -> HttpResponse { let mut res_builder = HttpResponse::Ok(); res_builder.content_type(mime::TEXT_HTML); pub fn http_response_file_data<T: body::MessageBody + 'static>( res: T, content_type: mime::Mime, ) -> HttpResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router if is_sensitive_header { header_value.set_sensitive(true); } response_builder.append_header((header_name, header_value)); } response_builder .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_response_plaintext<T: body::MessageBody + 'static>(res: T) -> HttpResponse { HttpResponse::Ok().content_type(mime::TEXT_PLAIN).body(res) } pub fn http_response_file_data<T: body::MessageBody + 'static>( res: T, content_type: mime::Mime, ) -> HttpResponse { HttpResponse::Ok().content_type(content_type).body(res) } pub fn http_response_html_data<T: body::MessageBody + 'static>( res: T, pub fn http_response_plaintext<T: body::MessageBody + 'static>(res: T) -> HttpResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router impl EmbedError for Report<hyperswitch_domain_models::errors::api_error_response::ApiErrorResponse> { } pub fn http_response_json<T: body::MessageBody + 'static>(response: T) -> HttpResponse { HttpResponse::Ok() .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_server_error_json_response<T: body::MessageBody + 'static>( response: T, ) -> HttpResponse { HttpResponse::InternalServerError() .content_type(mime::APPLICATION_JSON) .body(response) } pub fn http_response_json_with_headers<T: body::MessageBody + 'static>( response: T, headers: Vec<(String, Maskable<String>)>, request_duration: Option<Duration>, ) -> HttpResponse { pub fn http_server_error_json_response<T: body::MessageBody + 'static>( response: T, ) -> HttpResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router let response_code = res.status().as_u16(); tracing::Span::current().record("status_code", response_code); let end_instant = Instant::now(); let request_duration = end_instant.saturating_duration_since(start_instant); logger::info!( tag = ?Tag::EndRequest, time_taken_ms = request_duration.as_millis(), ); res } pub fn log_and_return_error_response<T>(error: Report<T>) -> HttpResponse where T: error_stack::Context + Clone + ResponseError, Report<T>: EmbedError, { logger::error!(?error); HttpResponse::from_error(error.embed().current_context().clone()) } pub trait EmbedError: Sized { fn embed(self) -> Self { self } pub fn log_and_return_error_response<T>(error: Report<T>) -> HttpResponse where T: error_stack::Context + Clone + ResponseError, Report<T>: EmbedError, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router use std::{ collections::{HashMap, HashSet}, error::Error, fmt::Debug, future::Future, str, sync::Arc, time::{Duration, Instant}, }; use tera::{Context, Error as TeraError, Tera}; fn is_connection_closed_before_message_could_complete(error: &reqwest::Error) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router } Err(err) => { logger::info!( call_connector_api_error=?err ); } } handle_response(response).await } #[instrument(skip_all)] pub async fn send_request( state: &SessionState, request: Request, option_timeout_secs: Option<u64>, ) -> CustomResult<reqwest::Response, errors::ApiClientError> { logger::info!(method=?request.method, headers=?request.headers, payload=?request.body, ?request); let url = url::Url::parse(&request.url).change_context(errors::ApiClientError::UrlParsingFailed)?; let client = client::create_client( &state.conf.proxy, request.certificate, pub async fn send_request( state: &SessionState, request: Request, option_timeout_secs: Option<u64>, ) -> CustomResult<reqwest::Response, errors::ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router status_code.to_string(), flow.to_string(), merchant_id.to_owned(), ); output } #[instrument( skip(request, state, func, api_auth, payload), fields(request_method, request_url_path, status_code) )] pub async fn server_wrap<'a, T, U, Q, F, Fut, E>( flow: impl router_env::types::FlowMetric, state: web::Data<AppState>, request: &'a HttpRequest, payload: T, func: F, api_auth: &dyn AuthenticateAndFetch<U, SessionState>, lock_action: api_locking::LockAction, ) -> HttpResponse where F: Fn(SessionState, U, T, ReqState) -> Fut, Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>, Q: Serialize + Debug + ApiEventMetric + 'a, pub async fn server_wrap<'a, T, U, Q, F, Fut, E>( flow: impl router_env::types::FlowMetric, state: web::Data<AppState>, request: &'a HttpRequest, payload: T, func: F, api_auth: &dyn AuthenticateAndFetch<U, SessionState>, lock_action: api_locking::LockAction, ) -> HttpResponse where F: Fn(SessionState, U, T, ReqState) -> Fut, Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>, Q: Serialize + Debug + ApiEventMetric + 'a, T: Debug + Serialize + ApiEventMetric, ApplicationResponse<Q>: Debug, E: ErrorSwitch<api_models::errors::types::ApiErrorResponse> + error_stack::Context, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router #[derive(Clone, Copy, PartialEq, Eq)] pub enum AuthFlow { Client, Merchant, } #[allow(clippy::too_many_arguments)] #[instrument( skip(request, payload, state, func, api_auth, incoming_request_header), fields(merchant_id) )] pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>( flow: &'a impl router_env::types::FlowMetric, state: web::Data<AppState>, incoming_request_header: &HeaderMap, request: &'a HttpRequest, payload: T, func: F, api_auth: &dyn AuthenticateAndFetch<U, SessionState>, lock_action: api_locking::LockAction, ) -> CustomResult<ApplicationResponse<Q>, OErr> where F: Fn(SessionState, U, T, ReqState) -> Fut, 'b: 'a, pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>( flow: &'a impl router_env::types::FlowMetric, state: web::Data<AppState>, incoming_request_header: &HeaderMap, request: &'a HttpRequest, payload: T, func: F, api_auth: &dyn AuthenticateAndFetch<U, SessionState>, lock_action: api_locking::LockAction, ) -> CustomResult<ApplicationResponse<Q>, OErr> where F: Fn(SessionState, U, T, ReqState) -> Fut, 'b: 'a, Fut: Future<Output = CustomResult<ApplicationResponse<Q>, E>>, Q: Serialize + Debug + 'a + ApiEventMetric, T: Debug + Serialize + ApiEventMetric, E: ErrorSwitch<OErr> + error_stack::Context, OErr: ResponseError + error_stack::Context + Serialize, errors::ApiErrorResponse: ErrorSwitch<OErr>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api.rs | crate: router pub type BoxedBillingConnectorPaymentsSyncIntegrationInterface<T, Req, Res> = BoxedConnectorIntegrationInterface< T, common_types::BillingConnectorPaymentsSyncFlowData, Req, Res, >; /// Handle the flow by interacting with connector module /// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger` /// In other cases, It will be created if required, even if it is not passed #[instrument(skip_all, fields(connector_name, payment_method))] pub async fn execute_connector_processing_step< 'b, 'a, T, ResourceCommonData: Clone + RouterDataConversion<T, Req, Resp> + 'static, Req: Debug + Clone + 'static, Resp: Debug + Clone + 'static, >( state: &'b SessionState, connector_integration: BoxedConnectorIntegrationInterface<T, ResourceCommonData, Req, Resp>, req: &'b types::RouterData<T, Req, Resp>, call_connector_action: payments::CallConnectorAction, connector_request: Option<Request>, pub async fn execute_connector_processing_step< 'b, 'a, T, ResourceCommonData: Clone + RouterDataConversion<T, Req, Resp> + 'static, Req: Debug + Clone + 'static, Resp: Debug + Clone + 'static, >( state: &'b SessionState, connector_integration: BoxedConnectorIntegrationInterface<T, ResourceCommonData, Req, Resp>, req: &'b types::RouterData<T, Req, Resp>, call_connector_action: payments::CallConnectorAction, connector_request: Option<Request>, ) -> CustomResult<types::RouterData<T, Req, Resp>, errors::ConnectorError> where T: Clone + Debug + 'static, // BoxedConnectorIntegration<T, Req, Resp>: 'b, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use masking::{ExposeInterface, PeekInterface}; use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; pub fn create_client( proxy_config: &Proxy, client_certificate: Option<masking::Secret<String>>, client_certificate_key: Option<masking::Secret<String>>, ) -> CustomResult<reqwest::Client, ApiClientError> { { (Some(encoded_certificate), Some(encoded_certificate_key)) => { let client_builder = get_client_builder(proxy_config)?; let identity = create_identity_from_certificate_and_key( encoded_certificate.clone(), encoded_certificate_key, )?; let certificate_list = create_certificate(encoded_certificate)?; let client_builder = certificate_list .into_iter() .fold(client_builder, |client_builder, certificate| { client_builder.add_root_certificate(certificate) }); client_builder .identity(identity) .use_rustls_tls() .build() .change_context(ApiClientError::ClientConstructionFailed) .attach_printable("Failed to construct client with certificate and certificate key") }<|fim_suffix|> <|fim_middle|> _ => get_base_client(proxy_config), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use std::time::Duration; use http::{HeaderValue, Method}; use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn get_client_builder( proxy_config: &Proxy, ) -> CustomResult<reqwest::ClientBuilder, ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; async fn send_request( &self, state: &SessionState, request: Request, option_timeout_secs: Option<u64>, _forward_to_kafka: bool, ) -> CustomResult<reqwest::Response, ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; fn multipart(&mut self, form: Form) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router fn add_flow_name(&mut self, _flow_name: String) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use router_env::tracing_actix_web::RequestId; fn add_request_id(&mut self, _request_id: RequestId) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; async fn send_request( &self, _state: &SessionState, _request: Request, _option_timeout_secs: Option<u64>, _forward_to_kafka: bool, ) -> CustomResult<reqwest::Response, ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use http::{HeaderValue, Method}; use masking::{ExposeInterface, PeekInterface}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn request_with_certificate( &self, _method: Method, _url: String, _certificate: Option<masking::Secret<String>>, _certificate_key: Option<masking::Secret<String>>, ) -> CustomResult<Box<dyn RequestBuilder>, ApiClientError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use http::{HeaderValue, Method}; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn request( &self, _method: Method, _url: String, ) -> CustomResult<Box<dyn RequestBuilder>, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; async fn send_request( &self, state: &SessionState, request: Request, option_timeout_secs: Option<u64>, _forward_to_kafka: bool, ) -> CustomResult<reqwest::Response, ApiClientError> { crate::services::send_request(state, request, option_timeout_secs).await }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use http::{HeaderValue, Method}; use masking::{ExposeInterface, PeekInterface}; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn request_with_certificate( &self, method: Method, url: String, certificate: Option<masking::Secret<String>>, certificate_key: Option<masking::Secret<String>>, ) -> CustomResult<Box<dyn RequestBuilder>, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use http::{HeaderValue, Method}; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn request( &self, method: Method, url: String, ) -> CustomResult<Box<dyn RequestBuilder>, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn send( self, ) -> CustomResult< Box< (dyn core::future::Future<Output = Result<reqwest::Response, reqwest::Error>> + 'static), >, ApiClientError, > { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use http::{HeaderValue, Method}; use super::{request::Maskable, Request}; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn header(&mut self, key: String, value: Maskable<String>) -> CustomResult<(), ApiClientError> { { Maskable::Masked(hvalue) => HeaderValue::from_str(hvalue.peek()).map(|mut h| { h.set_sensitive(true); h }),<|fim_suffix|> <|fim_middle|> Maskable::Normal(hvalue) => HeaderValue::from_str(&hvalue), } }
ast_fragments
// file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; fn multipart(&mut self, form: Form) { self.inner = self.inner.take().map(|r| r.multipart(form)); }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use std::time::Duration; fn timeout(&mut self, timeout: Duration) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router fn url_encoded_form(&mut self, body: serde_json::Value) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router fn json(&mut self, body: serde_json::Value) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use masking::{ExposeInterface, PeekInterface}; use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; pub fn get_reqwest_client( &self, client_certificate: Option<masking::Secret<String>>, client_certificate_key: Option<masking::Secret<String>>, ) -> CustomResult<reqwest::Client, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; pub fn new(proxy_config: &Proxy) -> CustomResult<Self, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use error_stack::ResultExt; use masking::{ExposeInterface, PeekInterface}; use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; pub fn create_certificate( encoded_certificate: masking::Secret<String>, ) -> Result<Vec<reqwest::Certificate>, error_stack::Report<ApiClientError>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use error_stack::ResultExt; use masking::{ExposeInterface, PeekInterface}; use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; pub fn create_identity_from_certificate_and_key( encoded_certificate: masking::Secret<String>, encoded_certificate_key: masking::Secret<String>, ) -> Result<reqwest::Identity, error_stack::Report<ApiClientError>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/client.rs | crate: router use reqwest::multipart::Form; use crate::{ configs::settings::Proxy, consts::BASE64_ENGINE, core::errors::{ApiClientError, CustomResult}, routes::SessionState, }; fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, ApiClientError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_pm_collect_link_status_html( link_data: &GenericLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { let mut tera = Tera::default(); let mut context = Context::new(); // Insert dynamic context in CSS let css_dynamic_context = "{{ color_scheme }}"; let css_template = include_str!("../../core/generic_link/payment_method_collect/status/styles.css") .to_string(); let final_css = format!("{}\n{}", css_dynamic_context, css_template); let _ = tera.add_raw_template("pm_collect_link_status_styles", &final_css); context.insert("color_scheme", &link_data.css_data); let css_style_tag = tera .render("pm_collect_link_status_styles", &context) .map(|css| format!("<style>{}</style>", css)) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to render payment method collect link status CSS template")?; // Insert dynamic context in JS let js_dynamic_context = "{{ collect_link_status_context }}"; let js_template = include_str!("../../core/generic_link/payment_method_collect/status/script.js").to_string(); let final_js = format!("{}\n{}", js_dynamic_context, js_template); let _ = tera.add_raw_template("pm_collect_link_status_script", &final_js); context.insert("collect_link_status_context", &link_data.js_data); let js_script_tag = tera .render("pm_collect_link_status_script", &context) .map(|js| format!("<script>{}</script>", js)) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to render payment method collect link status JS template")?; // Build HTML let html_template = include_str!("../../core/generic_link/payment_method_collect/status/index.html") .to_string(); let _ = tera.add_raw_template("payment_method_collect_status_link", &html_template); context.insert("css_style_tag", &css_style_tag); context.insert("js_script_tag", &js_script_tag); tera.render("payment_method_collect_status_link", &context) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to render payment method collect link status HTML template") }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_payout_link_status_html( link_data: &GenericLinkStatusData, locale: &str, ) -> CustomResult<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_pm_collect_link_html( link_data: &GenericLinkFormData, ) -> CustomResult<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_payout_link_html( link_data: &GenericLinkFormData, locale: &str, ) -> CustomResult<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; fn build_html_template( link_data: &GenericLinkFormData, document: &'static str, styles: &'static str, ) -> CustomResult<(Tera, Context), errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_pm_collect_link_status_html( link_data: &GenericLinkStatusData, ) -> CustomResult<String, errors::ApiErrorResponse> { {let mut tera = Tera::default();<|fim_suffix|> <|fim_middle|> tera.render("payment_method_collect_status_link", &context) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to render payment method collect link status HTML template")}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_payout_link_status_html( link_data: &GenericLinkStatusData, locale: &str, ) -> CustomResult<String, errors::ApiErrorResponse> { {let mut tera = Tera::default();<|fim_suffix|> <|fim_middle|> tera.render("payout_status_link", &context) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to render payout link status HTML template")}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use tera::{Context, Tera}; use crate::core::errors; pub fn build_generic_expired_link_html( link_data: &GenericExpiredLinkData, ) -> CustomResult<String, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/services/api/generic_link_response.rs | crate: router use common_utils::errors::CustomResult; use hyperswitch_domain_models::api::{ GenericExpiredLinkData, GenericLinkFormData, GenericLinkStatusData, GenericLinksData, }; use super::build_secure_payment_link_html; use crate::core::errors; pub fn build_generic_link_html( boxed_generic_link_data: GenericLinksData, locale: String, ) -> CustomResult<String, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments