text stringlengths 70 351k | source stringclasses 4 values |
|---|---|
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/request_id.rs | crate: src
use hyper::Request;
use tower_http::request_id::{MakeRequestId, RequestId};
fn make_request_id<B>(&mut self, _request: &Request<B>) -> Option<RequestId> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto.rs | crate: src
use std::{ops::Deref, sync::Arc};
use crate::errors::{self, CustomResult};
pub type Backend = dyn KeyManagement + Send + Sync;
pub fn client(&self) -> &Arc<Backend> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto.rs | crate: src
use std::{ops::Deref, sync::Arc};
pub type Backend = dyn KeyManagement + Send + Sync;
pub fn new(client: Arc<Backend>) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto.rs | crate: src
use masking::StrongSecret;
use crate::errors::{self, CustomResult};
async fn decrypt_key(
&self,
input: StrongSecret<Vec<u8>>,
) -> CustomResult<StrongSecret<Vec<u8>>, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto.rs | crate: src
use masking::StrongSecret;
use crate::errors::{self, CustomResult};
async fn encrypt_key(
&self,
input: StrongSecret<Vec<u8>>,
) -> CustomResult<StrongSecret<Vec<u8>>, errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto.rs | crate: src
use masking::StrongSecret;
use crate::errors::{self, CustomResult};
async fn generate_key(
&self,
) -> CustomResult<(Source, StrongSecret<[u8; 32]>), errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/multitenancy.rs | crate: src
use crate::{
app::{AppState, SessionState, StorageState},
consts::TENANT_HEADER,
errors::{self, ApiErrorContainer, SwitchError, ToContainerError},
};
use error_stack::ResultExt;
use hyper::header;
pub type MultiTenant<T> = FxHashMap<TenantId, T>;
fn extract_tenant(
state: &AppState,
header: &header::HeaderValue,
) -> errors::CustomResult<TenantState, errors::ParsingError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/multitenancy.rs | crate: src
use crate::{
app::{AppState, SessionState, StorageState},
consts::TENANT_HEADER,
errors::{self, ApiErrorContainer, SwitchError, ToContainerError},
};
use error_stack::ResultExt;
use hyper::header;
use std::sync::Arc;
async fn from_request_parts(
parts: &mut axum::http::request::Parts,
state: &Arc<AppState>,
) -> Result<Self, Self::Rejection> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/multitenancy.rs | crate: src
use crate::{
app::{AppState, SessionState, StorageState},
consts::TENANT_HEADER,
errors::{self, ApiErrorContainer, SwitchError, ToContainerError},
};
pub type MultiTenant<T> = FxHashMap<TenantId, T>;
pub(crate) fn get_db_pool(&self) -> &StorageState {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/multitenancy.rs | crate: src
use crate::{
app::{AppState, SessionState, StorageState},
consts::TENANT_HEADER,
errors::{self, ApiErrorContainer, SwitchError, ToContainerError},
};
use std::sync::Arc;
pub type MultiTenant<T> = FxHashMap<TenantId, T>;
pub fn new(session: Arc<SessionState>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/multitenancy.rs | crate: src
pub type MultiTenant<T> = FxHashMap<TenantId, T>;
pub fn new(val: String) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/blake3.rs | crate: src
use masking::{PeekInterface, Secret, StrongSecret};
pub fn hash(&self, token: Secret<String>) -> [u8; 32] {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use core::fmt;
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
use masking::StrongSecret;
fn encrypt(&self, input: StrongSecret<Vec<u8>>) -> Self::DataReturn<'_> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
fn visit_str<E>(self, value: &str) -> Result<GcmAes256, E>
where
E: de::Error,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use core::fmt;
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
fn advance(&mut self) -> Result<aead::Nonce, ring::error::Unspecified> {
let mut nonce = [0_u8; aead::NONCE_LEN];
nonce.copy_from_slice(&self.0.to_be_bytes()[Self::SEQUENCE_NUMBER_START_INDEX..]);
// Increment sequence number
self.0 = self.0.wrapping_add(1);
// Return previous sequence number as bytes
Ok(aead::Nonce::assume_unique_for_key(nonce))
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
/// Constructs a nonce sequence from bytes
fn from_bytes(bytes: [u8; aead::NONCE_LEN]) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
/// Returns the current nonce value as bytes.
fn current(&self) -> [u8; aead::NONCE_LEN] {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use error_stack::ResultExt;
use core::fmt;
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use masking::PeekInterface;
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
use masking::StrongSecret;
/// Generate a random nonce sequence.
fn new() -> Result<Self, ring::error::Unspecified> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use error_stack::ResultExt;
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use masking::StrongSecret;
pub async fn from_vec(
key: StrongSecret<Vec<u8>>,
) -> errors::CustomResult<Self, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use masking::StrongSecret;
pub fn new(key: StrongSecret<[u8; 32]>) -> errors::CustomResult<Self, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/aes256.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
};
use serde::de::{self, Deserialize, Deserializer, Unexpected, Visitor};
use ring::aead::{self, BoundKey, OpeningKey, SealingKey, UnboundKey};
fn key(&self) -> &[u8] {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/kms.rs | crate: src
use crate::{
crypto::{Crypto, Source},
errors::{self, CustomResult, SwitchError},
services::aws::AwsKmsClient,
};
use aws_sdk_kms::primitives::Blob;
use masking::{PeekInterface, StrongSecret};
async fn generate_key(
&self,
) -> errors::CustomResult<(Source, StrongSecret<[u8; 32]>), errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/vault.rs | crate: src
use crate::consts::base64::BASE64_ENGINE;
use crate::errors::{self, CryptoError, CustomResult};
use error_stack::report;
use masking::{PeekInterface, StrongSecret};
use std::pin::Pin;
use vaultrs::{api, transit};
fn decrypt(&self, input: StrongSecret<Vec<u8>>) -> Self::DataReturn<'_> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/crypto/vault.rs | crate: src
use vaultrs::client::{VaultClient, VaultClientSettingsBuilder};
pub fn new(settings: VaultSettings) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/types/requests/encryption.rs | crate: src
use crate::types::{core::Identifier, method::EncryptionType};
fn test_enc_request_deserialize() {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/health.rs | crate: src
use crate::{app::AppState, env::observability as logger, metrics};
use axum::extract::State;
use std::sync::Arc;
pub(crate) async fn heath_check(
State(_): State<Arc<AppState>>,
) -> (hyper::StatusCode, &'static str) {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/custodian.rs | crate: src
use base64::Engine;
use error_stack::{ensure, ResultExt};
use hyper::header;
use crate::consts::base64::BASE64_ENGINE;
use crate::errors::{ApiErrorContainer, CustomResult, ParsingError, SwitchError, ToContainerError};
fn extract_credential(
header: &header::HeaderValue,
) -> CustomResult<(String, String), ParsingError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/custodian.rs | crate: src
use std::sync::Arc;
use axum::http::request;
use hyper::header;
use crate::app::AppState;
async fn from_request_parts(
parts: &mut request::Parts,
_state: &Arc<AppState>,
) -> Result<Self, Self::Rejection> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/custodian.rs | crate: src
use masking::{PeekInterface, Secret, StrongSecret};
use crate::multitenancy::TenantState;
pub fn into_access_token(self, state: &TenantState) -> Option<StrongSecret<String>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/custodian.rs | crate: src
use masking::{PeekInterface, Secret, StrongSecret};
pub fn new(keys: Option<(String, String)>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use error_stack::ensure;
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
use super::custodian::Custodian;
async fn encrypt(
self,
state: &TenantState,
identifier: &Identifier,
custodian: Custodian,
) -> errors::CustomResult<EncryptedData, errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use error_stack::ensure;
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
use super::custodian::Custodian;
async fn decrypt(
self,
state: &TenantState,
identifier: &Identifier,
custodian: Custodian,
) -> errors::CustomResult<DecryptedDataGroup, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use error_stack::ensure;
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
use super::custodian::Custodian;
async fn encrypt(
self,
state: &TenantState,
identifier: &Identifier,
custodian: Custodian,
) -> errors::CustomResult<EncryptedDataGroup, errors::CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use error_stack::ensure;
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
use super::custodian::Custodian;
async fn decrypt(
self,
state: &TenantState,
identifier: &Identifier,
custodian: Custodian,
) -> errors::CustomResult<DecryptedData, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use error_stack::ensure;
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
async fn decrypt(self, state: &TenantState) -> errors::CustomResult<Key, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/core/crypto/crux.rs | crate: src
use crate::{
crypto::{aes256::GcmAes256, Crypto, Source},
errors::{self, SwitchError},
multitenancy::TenantState,
storage::types::{DataKey, DataKeyNew},
types::{
key::Version, DecryptedData, DecryptedDataGroup, EncryptedData, EncryptedDataGroup,
Identifier, Key,
},
};
async fn encrypt(
self,
state: &TenantState,
) -> errors::CustomResult<DataKeyNew, errors::CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/storage/types/dek.rs | crate: src
fn from(value: DataKeyNew) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/storage/adapter/cassandra.rs | crate: src
use crate::storage::{adapter::Cassandra, errors, Config, DbState};
async fn get_conn<'a>(
&'a self,
) -> errors::CustomResult<Self::Conn<'a>, errors::ConnectionError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/storage/adapter/cassandra.rs | crate: src
use crate::storage::{adapter::Cassandra, errors, Config, DbState};
async fn from_config(config: &Config, schema: &str) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/env/metrics.rs | crate: src
use opentelemetry_sdk::{metrics::SdkMeterProvider, Resource};
fn drop(&mut self) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/env/metrics.rs | crate: src
use opentelemetry::global;
use opentelemetry_sdk::{metrics::SdkMeterProvider, Resource};
use prometheus::default_registry;
pub(super) fn setup_metrics_pipeline() -> MetricsGuard {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/errors/crypto.rs | crate: src
use error_stack::report;
use crate::env::observability as logger;
fn switch(self) -> super::CustomResult<T, CryptoError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch-encryption-service/src/errors/crypto.rs | crate: src
fn switch(self) -> super::CustomResult<T, CryptoError> {
self.map_err(|err| err.change_context(CryptoError::InvalidValue))
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/errors/crypto.rs | crate: src
use error_stack::report;
fn switch(self) -> super::CustomResult<(), CryptoError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch-encryption-service/src/routes/datakey.rs | crate: src
use axum::{routing::post, Router};
use std::sync::Arc;
use crate::{app::AppState, core};
pub fn server(state: Arc<AppState>) -> Router<Arc<AppState>> {
Router::new()
.route("/create", post(core::create_data_key))
.route("/rotate", post(core::rotate_data_key))
.route("/transfer", post(core::transfer_data_key))
.with_state(state)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch-encryption-service/src/routes/crypto.rs | crate: src
use crate::{app::AppState, core};
use axum::{routing::post, Router};
use std::sync::Arc;
pub fn server(state: Arc<AppState>) -> Router<Arc<AppState>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/mock_db.rs | crate: storage_impl
use common_utils::{errors::CustomResult, types::keymanager::KeyManagerState};
use futures::lock::{Mutex, MutexGuard};
use hyperswitch_domain_models::{
behaviour::{Conversion, ReverseConversion},
merchant_key_store::MerchantKeyStore,
payments::{payment_attempt::PaymentAttempt, PaymentIntent},
};
use crate::{errors::StorageError, redis::RedisStore};
pub async fn update_resource<D, R>(
&self,
state: &KeyManagerState,
key_store: &MerchantKeyStore,
mut resources: MutexGuard<'_, Vec<D>>,
resource_updated: D,
filter_fn: impl Fn(&&mut D) -> bool,
error_message: String,
) -> CustomResult<R, StorageError>
where
D: Sync + ReverseConversion<R> + Clone,
R: Conversion,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/mock_db.rs | crate: storage_impl
use common_utils::{errors::CustomResult, types::keymanager::KeyManagerState};
use futures::lock::{Mutex, MutexGuard};
use hyperswitch_domain_models::{
behaviour::{Conversion, ReverseConversion},
merchant_key_store::MerchantKeyStore,
payments::{payment_attempt::PaymentAttempt, PaymentIntent},
};
use crate::{errors::StorageError, redis::RedisStore};
pub async fn find_resources<D, R>(
&self,
state: &KeyManagerState,
key_store: &MerchantKeyStore,
resources: MutexGuard<'_, Vec<D>>,
filter_fn: impl Fn(&&D) -> bool,
error_message: String,
) -> CustomResult<Vec<R>, StorageError>
where
D: Sync + ReverseConversion<R> + Clone,
R: Conversion,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/mock_db.rs | crate: storage_impl
use std::sync::Arc;
use error_stack::ResultExt;
use hyperswitch_domain_models::{
behaviour::{Conversion, ReverseConversion},
merchant_key_store::MerchantKeyStore,
payments::{payment_attempt::PaymentAttempt, PaymentIntent},
};
use redis_interface::RedisSettings;
use crate::{errors::StorageError, redis::RedisStore};
pub async fn new(redis: &RedisSettings) -> error_stack::Result<Self, StorageError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/storage_impl/src/mock_db.rs | crate: storage_impl
use common_utils::{errors::CustomResult, types::keymanager::KeyManagerState};
use futures::lock::{Mutex, MutexGuard};
use hyperswitch_domain_models::{
behaviour::{Conversion, ReverseConversion},
merchant_key_store::MerchantKeyStore,
payments::{payment_attempt::PaymentAttempt, PaymentIntent},
};
use crate::{errors::StorageError, redis::RedisStore};
pub async fn find_resource<D, R>(
&self,
state: &KeyManagerState,
key_store: &MerchantKeyStore,
resources: MutexGuard<'_, Vec<D>>,
filter_fn: impl Fn(&&D) -> bool,
error_message: String,
) -> CustomResult<R, StorageError>
where
D: Sync + ReverseConversion<R> + Clone,
R: Conversion,
{
let resource = resources.iter().find(filter_fn).cloned();
match resource {
Some(res) => Ok(res
.convert(
state,
key_store.key.get_inner(),
key_store.merchant_id.clone().into(),
)
.await
.change_context(StorageError::DecryptionError)?),
None => Err(StorageError::ValueNotFound(error_message).into()),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/callback_mapper.rs | crate: storage_impl
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/storage_impl/src/callback_mapper.rs | crate: storage_impl
use diesel_models::callback_mapper::CallbackMapper as DieselCallbackMapper;
fn to_storage_model(self) -> Self::StorageModel {
DieselCallbackMapper {
id: self.id,
type_: self.type_,
data: self.data,
created_at: self.created_at,
last_modified_at: self.last_modified_at,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
fn from(value: QueueStrategy) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
fn get_dbname(&self) -> &str {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
fn get_port(&self) -> u16 {
self.port
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
fn get_host(&self) -> &str {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
use masking::Secret;
fn get_password(&self) -> Secret<String> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/config.rs | crate: storage_impl
fn get_username(&self) -> &str {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/connection.rs | crate: storage_impl
use bb8::PooledConnection;
use common_utils::errors;
use diesel::PgConnection;
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
pub async fn pg_connection_write<T: crate::DatabaseStore>(
store: &T,
) -> errors::CustomResult<
PooledConnection<'_, async_bb8_diesel::ConnectionManager<PgConnection>>,
crate::errors::StorageError,
> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/connection.rs | crate: storage_impl
use bb8::PooledConnection;
use common_utils::errors;
use diesel::PgConnection;
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
pub async fn pg_connection_read<T: crate::DatabaseStore>(
store: &T,
) -> errors::CustomResult<
PooledConnection<'_, async_bb8_diesel::ConnectionManager<PgConnection>>,
crate::errors::StorageError,
> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/connection.rs | crate: storage_impl
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
pub async fn redis_connection(
redis: &redis_interface::RedisSettings,
) -> redis_interface::RedisConnectionPool {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/redis.rs | crate: storage_impl
use std::sync::{atomic, Arc};
use self::{kv_store::RedisConnInterface, pub_sub::PubSubInterface};
fn get_redis_conn(
&self,
) -> error_stack::Result<
Arc<redis_interface::RedisConnectionPool>,
redis_interface::errors::RedisError,
> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/redis.rs | crate: storage_impl
use std::sync::{atomic, Arc};
use self::{kv_store::RedisConnInterface, pub_sub::PubSubInterface};
pub fn set_error_callback(&self, callback: tokio::sync::oneshot::Sender<()>) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/redis.rs | crate: storage_impl
use std::sync::{atomic, Arc};
pub async fn new(
conf: &redis_interface::RedisSettings,
) -> error_stack::Result<Self, redis_interface::errors::RedisError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/storage_impl/src/mock_db/redis_conn.rs | crate: storage_impl
use std::sync::Arc;
use redis_interface::errors::RedisError;
use crate::redis::kv_store::RedisConnInterface;
fn get_redis_conn(
&self,
) -> Result<Arc<redis_interface::RedisConnectionPool>, error_stack::Report<RedisError>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/consts.rs | crate: common_utils
/// Default limit for payouts list API
pub fn default_payouts_list_limit() -> u32 {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/consts.rs | crate: common_utils
/// Default limit for payments list API
pub fn default_payments_list_limit() -> u32 {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/common_utils/src/events.rs | crate: common_utils
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Miscellaneous)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/fp_utils.rs | crate: common_utils
/// This function wraps the evaluated result of `f` into current context,
/// based on the condition provided into the `predicate`
pub fn when<W: Applicative<(), WrappedSelf<()> = W>, F>(predicate: bool, f: F) -> W
where
F: FnOnce() -> W,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/fp_utils.rs | crate: common_utils
fn pure(v: R) -> Self::WrappedSelf<R> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
/// Hollow implementation, for windows compatibility
pub fn close(self) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
/// Dummy handler for signals in windows (empty)
pub fn handle(&self) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
pub fn get_allowed_signals() -> Result<DummySignal, std::io::Error> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
pub fn get_allowed_signals() -> Result<signal_hook_tokio::SignalsInfo, std::io::Error> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
use tokio::sync::mpsc;
pub async fn signal_handler(_sig: DummySignal, _sender: mpsc::Sender<()>) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/signals.rs | crate: common_utils
use router_env::logger;
use tokio::sync::mpsc;
pub async fn signal_handler(mut sig: signal_hook_tokio::Signals, sender: mpsc::Sender<()>) {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/access_token.rs | crate: common_utils
use std::fmt::Display;
use crate::id_type;
/// Create a key for fetching the access token from redis
pub fn create_access_token_key(
merchant_id: &id_type::MerchantId,
merchant_connector_id_or_connector_name: impl Display,
) -> String {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/hashing.rs | crate: common_utils
use masking::{PeekInterface, Secret, Strategy};
fn from(value: Secret<String, T>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/common_utils/src/hashing.rs | crate: common_utils
use serde::{Deserialize, Serialize, Serializer};
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let hashed_value = blake3::hash(self.0.peek().as_bytes()).to_hex();
hashed_value.serialize(serializer)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/errors.rs | crate: common_utils
pub type CustomResult<T, E> = error_stack::Result<T, E>;
fn switch(&self) -> T {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/errors.rs | crate: common_utils
pub type CustomResult<T, E> = error_stack::Result<T, E>;
fn switch(self) -> Result<T, error_stack::Report<U>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use core::fmt::Debug;
use std::str::FromStr;
use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use router_env::{instrument, logger, tracing};
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
pub async fn call_encryption_service<T, R>(
state: &KeyManagerState,
method: Method,
endpoint: &str,
request_body: T,
) -> errors::CustomResult<R, errors::KeyManagerClientError>
where
T: GetKeymanagerTenant + ConvertRaw + Send + Sync + 'static + Debug,
R: serde::de::DeserializeOwned,
{
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use std::str::FromStr;
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
fn get_api_encryption_client(
state: &KeyManagerState,
) -> errors::CustomResult<reqwest::Client, errors::KeyManagerClientError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
pub async fn transfer_key_to_key_manager(
state: &KeyManagerState,
request_body: EncryptionTransferRequest,
) -> errors::CustomResult<DataKeyCreateResponse, errors::KeyManagerError> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
pub async fn create_key_in_key_manager(
state: &KeyManagerState,
request_body: EncryptionCreateRequest,
) -> errors::CustomResult<DataKeyCreateResponse, errors::KeyManagerError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use masking::{PeekInterface, StrongSecret};
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
fn convert_raw(self) -> Result<Self::Output, errors::KeyManagerClientError> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
fn convert_raw(self) -> Result<Self::Output, errors::KeyManagerClientError> {
Ok(self)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/keymanager.rs | crate: common_utils
use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use crate::{
consts::{BASE64_ENGINE, TENANT_HEADER},
errors,
types::keymanager::{
BatchDecryptDataRequest, DataKeyCreateResponse, DecryptDataRequest,
EncryptionCreateRequest, EncryptionTransferRequest, GetKeymanagerTenant, KeyManagerState,
TransientBatchDecryptDataRequest, TransientDecryptDataRequest,
},
};
pub async fn send_encryption_request<T>(
state: &KeyManagerState,
headers: HeaderMap,
url: String,
method: Method,
request_body: T,
) -> errors::CustomResult<reqwest::Response, errors::KeyManagerClientError>
where
T: ConvertRaw,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/metrics/utils.rs | crate: common_utils
use std::time;
use router_env::opentelemetry;
pub async fn record_operation_time<F, R>(
future: F,
metric: &opentelemetry::metrics::Histogram<f64>,
key_value: &[opentelemetry::KeyValue],
) -> R
where
F: futures::Future<Output = R>,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/metrics/utils.rs | crate: common_utils
use std::time;
pub async fn time_future<F, R>(future: F) -> (R, time::Duration)
where
F: futures::Future<Output = R>,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
/// Get higher lineages from the current lineage
pub fn get_same_and_higher_lineages(self) -> Vec<Self> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use crate::{
events::{ApiEventMetric, ApiEventsType},
id_type, impl_api_event_type,
};
/// Get the profile_id from the lineage
pub fn profile_id(&self) -> Option<&id_type::ProfileId> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use crate::{
events::{ApiEventMetric, ApiEventsType},
id_type, impl_api_event_type,
};
/// Get the merchant_id from the lineage
pub fn merchant_id(&self) -> Option<&id_type::MerchantId> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use crate::{
events::{ApiEventMetric, ApiEventsType},
id_type, impl_api_event_type,
};
/// Get the org_id from the lineage
pub fn org_id(&self) -> Option<&id_type::OrganizationId> {
{
Self::Tenant { .. } => None,<|fim_suffix|>
<|fim_middle|>
Self::Organization { org_id, .. }
| Self::Merchant { org_id, .. }
| Self::Profile { org_id, .. } => Some(org_id),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use crate::{
events::{ApiEventMetric, ApiEventsType},
id_type, impl_api_event_type,
};
/// Get the tenant_id from the lineage
pub fn tenant_id(&self) -> &id_type::TenantId {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use common_enums::EntityType;
/// Get the entity_type from the lineage
pub fn entity_type(&self) -> EntityType {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/common_utils/src/types/theme.rs | crate: common_utils
use common_enums::EntityType;
use crate::{
events::{ApiEventMetric, ApiEventsType},
id_type, impl_api_event_type,
};
/// Constructor for ThemeLineage
pub fn new(
entity_type: EntityType,
tenant_id: id_type::TenantId,
org_id: id_type::OrganizationId,
merchant_id: id_type::MerchantId,
profile_id: id_type::ProfileId,
) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/common_utils/src/types/primitive_wrappers.rs | crate: common_utils
fn to_sql<'b>(
&'b self,
out: &mut diesel::serialize::Output<'b, '_, DB>,
) -> diesel::serialize::Result {
self.0.to_sql(out)
} | ast_fragments |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.