id stringlengths 20 153 | type stringclasses 1 value | granularity stringclasses 14 values | content stringlengths 16 84.3k | metadata dict |
|---|---|---|---|---|
connector-service_snippet_5419210580886904799_1700_30 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
InformationOnly,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GooglePayAuthMethod {
/// Contain pan data only
PanOnly,
/// Contain cryptogram data along with pan data
#[serde(rename = "CRYPTOGRAM_3DS")]
Cryptogram,
}
#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum ProductType {
#[default]
Physical,
Digital,
Travel,
Ride,
Event,
Accommodation,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebhookTransformationStatus {
/// Transformation completed successfully, no further action needed
Complete,
/// Transformation incomplete, requires second call for final status
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1700,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1700_50 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
InformationOnly,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GooglePayAuthMethod {
/// Contain pan data only
PanOnly,
/// Contain cryptogram data along with pan data
#[serde(rename = "CRYPTOGRAM_3DS")]
Cryptogram,
}
#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum ProductType {
#[default]
Physical,
Digital,
Travel,
Ride,
Event,
Accommodation,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebhookTransformationStatus {
/// Transformation completed successfully, no further action needed
Complete,
/// Transformation incomplete, requires second call for final status
Incomplete,
}
#[derive(Clone, Debug, PartialEq)]
pub enum CallConnectorAction {
Trigger,
HandleResponse(Vec<u8>),
}
#[derive(
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
Hash,
)]
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1700,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1725_15 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebhookTransformationStatus {
/// Transformation completed successfully, no further action needed
Complete,
/// Transformation incomplete, requires second call for final status
Incomplete,
}
#[derive(Clone, Debug, PartialEq)]
pub enum CallConnectorAction {
Trigger,
HandleResponse(Vec<u8>),
}
#[derive(
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1725,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1725_30 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebhookTransformationStatus {
/// Transformation completed successfully, no further action needed
Complete,
/// Transformation incomplete, requires second call for final status
Incomplete,
}
#[derive(Clone, Debug, PartialEq)]
pub enum CallConnectorAction {
Trigger,
HandleResponse(Vec<u8>),
}
#[derive(
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
Hash,
)]
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1725,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1725_50 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebhookTransformationStatus {
/// Transformation completed successfully, no further action needed
Complete,
/// Transformation incomplete, requires second call for final status
Incomplete,
}
#[derive(Clone, Debug, PartialEq)]
pub enum CallConnectorAction {
Trigger,
HandleResponse(Vec<u8>),
}
#[derive(
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
Hash,
)]
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
#[derive(
Clone,
Debug,
Default,
Hash,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum StripeChargeType {
#[default]
Direct,
Destination,
}
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1725,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1750_15 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
#[derive(
Clone,
Debug,
Default,
Hash,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1750,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1750_30 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
#[derive(
Clone,
Debug,
Default,
Hash,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum StripeChargeType {
#[default]
Direct,
Destination,
}
#[derive(
Default,
Clone,
Debug,
Eq,
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1750,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1750_50 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
#[derive(
Clone,
Debug,
Default,
Hash,
Eq,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum StripeChargeType {
#[default]
Direct,
Destination,
}
#[derive(
Default,
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthorizationStatus {
Success,
Failure,
// Processing state is before calling connector
#[default]
Processing,
// Requires merchant action
Unresolved,
}
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1750,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1775_15 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(
Default,
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1775,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1775_30 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(
Default,
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthorizationStatus {
Success,
Failure,
// Processing state is before calling connector
#[default]
Processing,
// Requires merchant action
Unresolved,
}
#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum DecoupledAuthenticationType {
#[default]
Challenge,
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1775,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_5419210580886904799_1775_50 | clm | snippet | // connector-service/backend/common_enums/src/enums.rs
#[derive(
Default,
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthorizationStatus {
Success,
Failure,
// Processing state is before calling connector
#[default]
Processing,
// Requires merchant action
Unresolved,
}
#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum DecoupledAuthenticationType {
#[default]
Challenge,
Frictionless,
}
| {
"chunk": null,
"crate": "ucs_common_enums",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 32,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 1775,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_0_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
use std::{collections::HashMap, fmt, ops::Deref, str::FromStr, sync::LazyLock};
use common_utils::{
consts::{MAX_CARD_NUMBER_LENGTH, MIN_CARD_NUMBER_LENGTH},
date_time, ValidationError,
};
use error_stack::report;
use hyperswitch_masking::{PeekInterface, Strategy, StrongSecret, WithType};
use regex::Regex;
use serde::{
de::{self},
Deserialize, Deserializer, Serialize,
};
use thiserror::Error;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_0_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
use std::{collections::HashMap, fmt, ops::Deref, str::FromStr, sync::LazyLock};
use common_utils::{
consts::{MAX_CARD_NUMBER_LENGTH, MIN_CARD_NUMBER_LENGTH},
date_time, ValidationError,
};
use error_stack::report;
use hyperswitch_masking::{PeekInterface, Strategy, StrongSecret, WithType};
use regex::Regex;
use serde::{
de::{self},
Deserialize, Deserializer, Serialize,
};
use thiserror::Error;
#[derive(Debug, Deserialize, Serialize, Error)]
#[error("{0}")]
pub struct CardNumberValidationErr(&'static str);
/// Card number
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct CardNumber(StrongSecret<String, CardNumberStrategy>);
//Network Token
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct NetworkToken(StrongSecret<String, CardNumberStrategy>);
impl CardNumber {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_0_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
use std::{collections::HashMap, fmt, ops::Deref, str::FromStr, sync::LazyLock};
use common_utils::{
consts::{MAX_CARD_NUMBER_LENGTH, MIN_CARD_NUMBER_LENGTH},
date_time, ValidationError,
};
use error_stack::report;
use hyperswitch_masking::{PeekInterface, Strategy, StrongSecret, WithType};
use regex::Regex;
use serde::{
de::{self},
Deserialize, Deserializer, Serialize,
};
use thiserror::Error;
#[derive(Debug, Deserialize, Serialize, Error)]
#[error("{0}")]
pub struct CardNumberValidationErr(&'static str);
/// Card number
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct CardNumber(StrongSecret<String, CardNumberStrategy>);
//Network Token
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct NetworkToken(StrongSecret<String, CardNumberStrategy>);
impl CardNumber {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
}
pub fn is_cobadged_card(&self) -> Result<bool, error_stack::Report<ValidationError>> {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_25_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct NetworkToken(StrongSecret<String, CardNumberStrategy>);
impl CardNumber {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_25_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct NetworkToken(StrongSecret<String, CardNumberStrategy>);
impl CardNumber {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
}
pub fn is_cobadged_card(&self) -> Result<bool, error_stack::Report<ValidationError>> {
/// Regex to identify card networks
static CARD_NETWORK_REGEX: LazyLock<HashMap<&str, Result<Regex, regex::Error>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_25_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct NetworkToken(StrongSecret<String, CardNumberStrategy>);
impl CardNumber {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
}
pub fn is_cobadged_card(&self) -> Result<bool, error_stack::Report<ValidationError>> {
/// Regex to identify card networks
static CARD_NETWORK_REGEX: LazyLock<HashMap<&str, Result<Regex, regex::Error>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(
"Mastercard",
Regex::new(r"^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])"),
);
map.insert("American Express", Regex::new(r"^3[47]"));
map.insert("Visa", Regex::new(r"^4"));
map.insert(
"Discover",
Regex::new(
r"^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)",
),
);
map.insert(
"Maestro",
Regex::new(r"^(5018|5081|5044|504681|504993|5020|502260|5038|5893|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775|600206|627741)"),
);
map.insert(
"RuPay",
Regex::new(r"^(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4]|817290|817368|817378|353800|82)"),
);
map.insert("Diners Club", Regex::new(r"^(36|38|39|30[0-5])"));
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_50_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
/// Regex to identify card networks
static CARD_NETWORK_REGEX: LazyLock<HashMap<&str, Result<Regex, regex::Error>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(
"Mastercard",
Regex::new(r"^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])"),
);
map.insert("American Express", Regex::new(r"^3[47]"));
map.insert("Visa", Regex::new(r"^4"));
map.insert(
"Discover",
Regex::new(
r"^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)",
),
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_50_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
/// Regex to identify card networks
static CARD_NETWORK_REGEX: LazyLock<HashMap<&str, Result<Regex, regex::Error>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(
"Mastercard",
Regex::new(r"^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])"),
);
map.insert("American Express", Regex::new(r"^3[47]"));
map.insert("Visa", Regex::new(r"^4"));
map.insert(
"Discover",
Regex::new(
r"^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)",
),
);
map.insert(
"Maestro",
Regex::new(r"^(5018|5081|5044|504681|504993|5020|502260|5038|5893|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775|600206|627741)"),
);
map.insert(
"RuPay",
Regex::new(r"^(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4]|817290|817368|817378|353800|82)"),
);
map.insert("Diners Club", Regex::new(r"^(36|38|39|30[0-5])"));
map.insert("JCB", Regex::new(r"^35(2[89]|[3-8][0-9])"));
map.insert("CarteBlanche", Regex::new(r"^389[0-9]{11}$"));
map.insert("Sodex", Regex::new(r"^(637513)"));
map.insert("BAJAJ", Regex::new(r"^(203040)"));
map.insert("CartesBancaires", Regex::new(r"^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))"));
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_50_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
/// Regex to identify card networks
static CARD_NETWORK_REGEX: LazyLock<HashMap<&str, Result<Regex, regex::Error>>> =
LazyLock::new(|| {
let mut map = HashMap::new();
map.insert(
"Mastercard",
Regex::new(r"^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])"),
);
map.insert("American Express", Regex::new(r"^3[47]"));
map.insert("Visa", Regex::new(r"^4"));
map.insert(
"Discover",
Regex::new(
r"^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)",
),
);
map.insert(
"Maestro",
Regex::new(r"^(5018|5081|5044|504681|504993|5020|502260|5038|5893|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775|600206|627741)"),
);
map.insert(
"RuPay",
Regex::new(r"^(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4]|817290|817368|817378|353800|82)"),
);
map.insert("Diners Club", Regex::new(r"^(36|38|39|30[0-5])"));
map.insert("JCB", Regex::new(r"^35(2[89]|[3-8][0-9])"));
map.insert("CarteBlanche", Regex::new(r"^389[0-9]{11}$"));
map.insert("Sodex", Regex::new(r"^(637513)"));
map.insert("BAJAJ", Regex::new(r"^(203040)"));
map.insert("CartesBancaires", Regex::new(r"^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))"));
map
});
let mut no_of_supported_card_networks = 0;
let card_number_str = self.get_card_no();
for (_, regex) in CARD_NETWORK_REGEX.iter() {
let card_regex = match regex.as_ref() {
Ok(regex) => Ok(regex),
Err(_) => Err(report!(ValidationError::InvalidValue {
message: "Invalid regex expression".into(),
})),
}?;
if card_regex.is_match(&card_number_str) {
no_of_supported_card_networks += 1;
if no_of_supported_card_networks > 1 {
break;
}
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_75_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
map.insert("JCB", Regex::new(r"^35(2[89]|[3-8][0-9])"));
map.insert("CarteBlanche", Regex::new(r"^389[0-9]{11}$"));
map.insert("Sodex", Regex::new(r"^(637513)"));
map.insert("BAJAJ", Regex::new(r"^(203040)"));
map.insert("CartesBancaires", Regex::new(r"^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))"));
map
});
let mut no_of_supported_card_networks = 0;
let card_number_str = self.get_card_no();
for (_, regex) in CARD_NETWORK_REGEX.iter() {
let card_regex = match regex.as_ref() {
Ok(regex) => Ok(regex),
Err(_) => Err(report!(ValidationError::InvalidValue {
message: "Invalid regex expression".into(),
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_75_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
map.insert("JCB", Regex::new(r"^35(2[89]|[3-8][0-9])"));
map.insert("CarteBlanche", Regex::new(r"^389[0-9]{11}$"));
map.insert("Sodex", Regex::new(r"^(637513)"));
map.insert("BAJAJ", Regex::new(r"^(203040)"));
map.insert("CartesBancaires", Regex::new(r"^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))"));
map
});
let mut no_of_supported_card_networks = 0;
let card_number_str = self.get_card_no();
for (_, regex) in CARD_NETWORK_REGEX.iter() {
let card_regex = match regex.as_ref() {
Ok(regex) => Ok(regex),
Err(_) => Err(report!(ValidationError::InvalidValue {
message: "Invalid regex expression".into(),
})),
}?;
if card_regex.is_match(&card_number_str) {
no_of_supported_card_networks += 1;
if no_of_supported_card_networks > 1 {
break;
}
}
}
Ok(no_of_supported_card_networks > 1)
}
}
impl NetworkToken {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_75_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
map.insert("JCB", Regex::new(r"^35(2[89]|[3-8][0-9])"));
map.insert("CarteBlanche", Regex::new(r"^389[0-9]{11}$"));
map.insert("Sodex", Regex::new(r"^(637513)"));
map.insert("BAJAJ", Regex::new(r"^(203040)"));
map.insert("CartesBancaires", Regex::new(r"^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))"));
map
});
let mut no_of_supported_card_networks = 0;
let card_number_str = self.get_card_no();
for (_, regex) in CARD_NETWORK_REGEX.iter() {
let card_regex = match regex.as_ref() {
Ok(regex) => Ok(regex),
Err(_) => Err(report!(ValidationError::InvalidValue {
message: "Invalid regex expression".into(),
})),
}?;
if card_regex.is_match(&card_number_str) {
no_of_supported_card_networks += 1;
if no_of_supported_card_networks > 1 {
break;
}
}
}
Ok(no_of_supported_card_networks > 1)
}
}
impl NetworkToken {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_100_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(no_of_supported_card_networks > 1)
}
}
impl NetworkToken {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_100_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(no_of_supported_card_networks > 1)
}
}
impl NetworkToken {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
}
}
impl FromStr for CardNumber {
type Err = CardNumberValidationErr;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_100_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(no_of_supported_card_networks > 1)
}
}
impl NetworkToken {
pub fn get_card_isin(&self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}
pub fn get_extended_card_bin(&self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(&self) -> String {
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(&self) -> String {
self.0
.peek()
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>()
}
}
impl FromStr for CardNumber {
type Err = CardNumberValidationErr;
fn from_str(card_number: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_cards = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let card_number = card_number.split_whitespace().collect::<String>();
let is_card_valid = sanitize_card_number(&card_number)?;
if valid_test_cards.contains(&card_number.as_str()) || is_card_valid {
Ok(Self(StrongSecret::new(card_number)))
} else {
Err(CardNumberValidationErr("card number invalid"))
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_125_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
impl FromStr for CardNumber {
type Err = CardNumberValidationErr;
fn from_str(card_number: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_cards = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_125_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
impl FromStr for CardNumber {
type Err = CardNumberValidationErr;
fn from_str(card_number: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_cards = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let card_number = card_number.split_whitespace().collect::<String>();
let is_card_valid = sanitize_card_number(&card_number)?;
if valid_test_cards.contains(&card_number.as_str()) || is_card_valid {
Ok(Self(StrongSecret::new(card_number)))
} else {
Err(CardNumberValidationErr("card number invalid"))
}
}
}
impl FromStr for NetworkToken {
type Err = CardNumberValidationErr;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_125_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
impl FromStr for CardNumber {
type Err = CardNumberValidationErr;
fn from_str(card_number: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_cards = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let card_number = card_number.split_whitespace().collect::<String>();
let is_card_valid = sanitize_card_number(&card_number)?;
if valid_test_cards.contains(&card_number.as_str()) || is_card_valid {
Ok(Self(StrongSecret::new(card_number)))
} else {
Err(CardNumberValidationErr("card number invalid"))
}
}
}
impl FromStr for NetworkToken {
type Err = CardNumberValidationErr;
fn from_str(network_token: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_network_tokens = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let network_token = network_token.split_whitespace().collect::<String>();
let is_network_token_valid = sanitize_card_number(&network_token)?;
if valid_test_network_tokens.contains(&network_token.as_str()) || is_network_token_valid {
Ok(Self(StrongSecret::new(network_token)))
} else {
Err(CardNumberValidationErr("network token invalid"))
}
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_150_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
impl FromStr for NetworkToken {
type Err = CardNumberValidationErr;
fn from_str(network_token: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_network_tokens = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let network_token = network_token.split_whitespace().collect::<String>();
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_150_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
impl FromStr for NetworkToken {
type Err = CardNumberValidationErr;
fn from_str(network_token: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_network_tokens = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let network_token = network_token.split_whitespace().collect::<String>();
let is_network_token_valid = sanitize_card_number(&network_token)?;
if valid_test_network_tokens.contains(&network_token.as_str()) || is_network_token_valid {
Ok(Self(StrongSecret::new(network_token)))
} else {
Err(CardNumberValidationErr("network token invalid"))
}
}
}
pub fn sanitize_card_number(card_number: &str) -> Result<bool, CardNumberValidationErr> {
let is_card_number_valid = Ok(card_number)
.and_then(validate_card_number_chars)
.and_then(validate_card_number_length)
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_150_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
impl FromStr for NetworkToken {
type Err = CardNumberValidationErr;
fn from_str(network_token: &str) -> Result<Self, Self::Err> {
// Valid test cards for threedsecureio
let valid_test_network_tokens = [
"4000100511112003",
"6000100611111203",
"3000100811111072",
"9000100111111111",
];
let network_token = network_token.split_whitespace().collect::<String>();
let is_network_token_valid = sanitize_card_number(&network_token)?;
if valid_test_network_tokens.contains(&network_token.as_str()) || is_network_token_valid {
Ok(Self(StrongSecret::new(network_token)))
} else {
Err(CardNumberValidationErr("network token invalid"))
}
}
}
pub fn sanitize_card_number(card_number: &str) -> Result<bool, CardNumberValidationErr> {
let is_card_number_valid = Ok(card_number)
.and_then(validate_card_number_chars)
.and_then(validate_card_number_length)
.map(|number| luhn(&number))?;
Ok(is_card_number_valid)
}
/// # Panics
///
/// Never, as a single character will never be greater than 10, or `u8`
pub fn validate_card_number_chars(number: &str) -> Result<Vec<u8>, CardNumberValidationErr> {
let data = number.chars().try_fold(
Vec::with_capacity(MAX_CARD_NUMBER_LENGTH),
|mut data, character| {
data.push(
#[allow(clippy::expect_used)]
character
.to_digit(10)
.ok_or(CardNumberValidationErr(
"invalid character found in card number",
))?
.try_into()
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_175_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub fn sanitize_card_number(card_number: &str) -> Result<bool, CardNumberValidationErr> {
let is_card_number_valid = Ok(card_number)
.and_then(validate_card_number_chars)
.and_then(validate_card_number_length)
.map(|number| luhn(&number))?;
Ok(is_card_number_valid)
}
/// # Panics
///
/// Never, as a single character will never be greater than 10, or `u8`
pub fn validate_card_number_chars(number: &str) -> Result<Vec<u8>, CardNumberValidationErr> {
let data = number.chars().try_fold(
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_175_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub fn sanitize_card_number(card_number: &str) -> Result<bool, CardNumberValidationErr> {
let is_card_number_valid = Ok(card_number)
.and_then(validate_card_number_chars)
.and_then(validate_card_number_length)
.map(|number| luhn(&number))?;
Ok(is_card_number_valid)
}
/// # Panics
///
/// Never, as a single character will never be greater than 10, or `u8`
pub fn validate_card_number_chars(number: &str) -> Result<Vec<u8>, CardNumberValidationErr> {
let data = number.chars().try_fold(
Vec::with_capacity(MAX_CARD_NUMBER_LENGTH),
|mut data, character| {
data.push(
#[allow(clippy::expect_used)]
character
.to_digit(10)
.ok_or(CardNumberValidationErr(
"invalid character found in card number",
))?
.try_into()
.expect("error while converting a single character to u8"), // safety, a single character will never be greater `u8`
);
Ok::<Vec<u8>, CardNumberValidationErr>(data)
},
)?;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_175_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub fn sanitize_card_number(card_number: &str) -> Result<bool, CardNumberValidationErr> {
let is_card_number_valid = Ok(card_number)
.and_then(validate_card_number_chars)
.and_then(validate_card_number_length)
.map(|number| luhn(&number))?;
Ok(is_card_number_valid)
}
/// # Panics
///
/// Never, as a single character will never be greater than 10, or `u8`
pub fn validate_card_number_chars(number: &str) -> Result<Vec<u8>, CardNumberValidationErr> {
let data = number.chars().try_fold(
Vec::with_capacity(MAX_CARD_NUMBER_LENGTH),
|mut data, character| {
data.push(
#[allow(clippy::expect_used)]
character
.to_digit(10)
.ok_or(CardNumberValidationErr(
"invalid character found in card number",
))?
.try_into()
.expect("error while converting a single character to u8"), // safety, a single character will never be greater `u8`
);
Ok::<Vec<u8>, CardNumberValidationErr>(data)
},
)?;
Ok(data)
}
pub fn validate_card_number_length(number: Vec<u8>) -> Result<Vec<u8>, CardNumberValidationErr> {
if number.len() >= MIN_CARD_NUMBER_LENGTH && number.len() <= MAX_CARD_NUMBER_LENGTH {
Ok(number)
} else {
Err(CardNumberValidationErr("invalid card number length"))
}
}
#[allow(clippy::as_conversions)]
pub fn luhn(number: &[u8]) -> bool {
number
.iter()
.rev()
.enumerate()
.map(|(idx, element)| {
((*element * 2) / 10 + (*element * 2) % 10) * ((idx as u8) % 2)
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_200_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
.expect("error while converting a single character to u8"), // safety, a single character will never be greater `u8`
);
Ok::<Vec<u8>, CardNumberValidationErr>(data)
},
)?;
Ok(data)
}
pub fn validate_card_number_length(number: Vec<u8>) -> Result<Vec<u8>, CardNumberValidationErr> {
if number.len() >= MIN_CARD_NUMBER_LENGTH && number.len() <= MAX_CARD_NUMBER_LENGTH {
Ok(number)
} else {
Err(CardNumberValidationErr("invalid card number length"))
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_200_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
.expect("error while converting a single character to u8"), // safety, a single character will never be greater `u8`
);
Ok::<Vec<u8>, CardNumberValidationErr>(data)
},
)?;
Ok(data)
}
pub fn validate_card_number_length(number: Vec<u8>) -> Result<Vec<u8>, CardNumberValidationErr> {
if number.len() >= MIN_CARD_NUMBER_LENGTH && number.len() <= MAX_CARD_NUMBER_LENGTH {
Ok(number)
} else {
Err(CardNumberValidationErr("invalid card number length"))
}
}
#[allow(clippy::as_conversions)]
pub fn luhn(number: &[u8]) -> bool {
number
.iter()
.rev()
.enumerate()
.map(|(idx, element)| {
((*element * 2) / 10 + (*element * 2) % 10) * ((idx as u8) % 2)
+ (*element) * (((idx + 1) as u8) % 2)
})
.sum::<u8>()
% 10
== 0
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_200_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
.expect("error while converting a single character to u8"), // safety, a single character will never be greater `u8`
);
Ok::<Vec<u8>, CardNumberValidationErr>(data)
},
)?;
Ok(data)
}
pub fn validate_card_number_length(number: Vec<u8>) -> Result<Vec<u8>, CardNumberValidationErr> {
if number.len() >= MIN_CARD_NUMBER_LENGTH && number.len() <= MAX_CARD_NUMBER_LENGTH {
Ok(number)
} else {
Err(CardNumberValidationErr("invalid card number length"))
}
}
#[allow(clippy::as_conversions)]
pub fn luhn(number: &[u8]) -> bool {
number
.iter()
.rev()
.enumerate()
.map(|(idx, element)| {
((*element * 2) / 10 + (*element * 2) % 10) * ((idx as u8) % 2)
+ (*element) * (((idx + 1) as u8) % 2)
})
.sum::<u8>()
% 10
== 0
}
impl TryFrom<String> for CardNumber {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl TryFrom<String> for NetworkToken {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl Deref for CardNumber {
type Target = StrongSecret<String, CardNumberStrategy>;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_225_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
+ (*element) * (((idx + 1) as u8) % 2)
})
.sum::<u8>()
% 10
== 0
}
impl TryFrom<String> for CardNumber {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_225_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
+ (*element) * (((idx + 1) as u8) % 2)
})
.sum::<u8>()
% 10
== 0
}
impl TryFrom<String> for CardNumber {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl TryFrom<String> for NetworkToken {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl Deref for CardNumber {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_225_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
+ (*element) * (((idx + 1) as u8) % 2)
})
.sum::<u8>()
% 10
== 0
}
impl TryFrom<String> for CardNumber {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl TryFrom<String> for NetworkToken {
type Error = CardNumberValidationErr;
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value)
}
}
impl Deref for CardNumber {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl Deref for NetworkToken {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl<'de> Deserialize<'de> for CardNumber {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}
impl<'de> Deserialize<'de> for NetworkToken {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_250_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl Deref for NetworkToken {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl<'de> Deserialize<'de> for CardNumber {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_250_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl Deref for NetworkToken {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl<'de> Deserialize<'de> for CardNumber {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}
impl<'de> Deserialize<'de> for NetworkToken {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}
pub enum CardNumberStrategy {}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_250_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl Deref for NetworkToken {
type Target = StrongSecret<String, CardNumberStrategy>;
fn deref(&self) -> &StrongSecret<String, CardNumberStrategy> {
&self.0
}
}
impl<'de> Deserialize<'de> for CardNumber {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}
impl<'de> Deserialize<'de> for NetworkToken {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Self::from_str(&s).map_err(serde::de::Error::custom)
}
}
pub enum CardNumberStrategy {}
impl<T> Strategy<T> for CardNumberStrategy
where
T: AsRef<str>,
{
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let val_str: &str = val.as_ref();
if val_str.len() < 15 || val_str.len() > 19 {
return WithType::fmt(val, f);
}
if let Some(value) = val_str.get(..6) {
write!(f, "{}{}", value, "*".repeat(val_str.len() - 6))
} else {
WithType::fmt(val, f)
}
}
}
impl prost::Message for CardNumber {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_275_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
pub enum CardNumberStrategy {}
impl<T> Strategy<T> for CardNumberStrategy
where
T: AsRef<str>,
{
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let val_str: &str = val.as_ref();
if val_str.len() < 15 || val_str.len() > 19 {
return WithType::fmt(val, f);
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_275_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
pub enum CardNumberStrategy {}
impl<T> Strategy<T> for CardNumberStrategy
where
T: AsRef<str>,
{
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let val_str: &str = val.as_ref();
if val_str.len() < 15 || val_str.len() > 19 {
return WithType::fmt(val, f);
}
if let Some(value) = val_str.get(..6) {
write!(f, "{}{}", value, "*".repeat(val_str.len() - 6))
} else {
WithType::fmt(val, f)
}
}
}
impl prost::Message for CardNumber {
fn encode_raw(&self, buf: &mut impl bytes::BufMut) {
if !self.0.peek().is_empty() {
prost::encoding::string::encode(1, self.0.peek(), buf);
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_275_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
}
pub enum CardNumberStrategy {}
impl<T> Strategy<T> for CardNumberStrategy
where
T: AsRef<str>,
{
fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let val_str: &str = val.as_ref();
if val_str.len() < 15 || val_str.len() > 19 {
return WithType::fmt(val, f);
}
if let Some(value) = val_str.get(..6) {
write!(f, "{}{}", value, "*".repeat(val_str.len() - 6))
} else {
WithType::fmt(val, f)
}
}
}
impl prost::Message for CardNumber {
fn encode_raw(&self, buf: &mut impl bytes::BufMut) {
if !self.0.peek().is_empty() {
prost::encoding::string::encode(1, self.0.peek(), buf);
}
}
fn merge_field(
&mut self,
tag: u32,
wire_type: prost::encoding::WireType,
buf: &mut impl bytes::Buf,
ctx: prost::encoding::DecodeContext,
) -> Result<(), prost::DecodeError> {
if tag == 1 {
let mut temp_string = String::new();
prost::encoding::string::merge(wire_type, &mut temp_string, buf, ctx)?;
*self = CardNumber(StrongSecret::new(temp_string));
Ok(())
} else {
prost::encoding::skip_field(wire_type, tag, buf, ctx)
}
}
fn encoded_len(&self) -> usize {
if !self.0.peek().is_empty() {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_300_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn encode_raw(&self, buf: &mut impl bytes::BufMut) {
if !self.0.peek().is_empty() {
prost::encoding::string::encode(1, self.0.peek(), buf);
}
}
fn merge_field(
&mut self,
tag: u32,
wire_type: prost::encoding::WireType,
buf: &mut impl bytes::Buf,
ctx: prost::encoding::DecodeContext,
) -> Result<(), prost::DecodeError> {
if tag == 1 {
let mut temp_string = String::new();
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_300_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn encode_raw(&self, buf: &mut impl bytes::BufMut) {
if !self.0.peek().is_empty() {
prost::encoding::string::encode(1, self.0.peek(), buf);
}
}
fn merge_field(
&mut self,
tag: u32,
wire_type: prost::encoding::WireType,
buf: &mut impl bytes::Buf,
ctx: prost::encoding::DecodeContext,
) -> Result<(), prost::DecodeError> {
if tag == 1 {
let mut temp_string = String::new();
prost::encoding::string::merge(wire_type, &mut temp_string, buf, ctx)?;
*self = CardNumber(StrongSecret::new(temp_string));
Ok(())
} else {
prost::encoding::skip_field(wire_type, tag, buf, ctx)
}
}
fn encoded_len(&self) -> usize {
if !self.0.peek().is_empty() {
prost::encoding::string::encoded_len(1, self.0.peek())
} else {
0
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_300_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
fn encode_raw(&self, buf: &mut impl bytes::BufMut) {
if !self.0.peek().is_empty() {
prost::encoding::string::encode(1, self.0.peek(), buf);
}
}
fn merge_field(
&mut self,
tag: u32,
wire_type: prost::encoding::WireType,
buf: &mut impl bytes::Buf,
ctx: prost::encoding::DecodeContext,
) -> Result<(), prost::DecodeError> {
if tag == 1 {
let mut temp_string = String::new();
prost::encoding::string::merge(wire_type, &mut temp_string, buf, ctx)?;
*self = CardNumber(StrongSecret::new(temp_string));
Ok(())
} else {
prost::encoding::skip_field(wire_type, tag, buf, ctx)
}
}
fn encoded_len(&self) -> usize {
if !self.0.peek().is_empty() {
prost::encoding::string::encoded_len(1, self.0.peek())
} else {
0
}
}
fn clear(&mut self) {
*self = CardNumber::default();
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use hyperswitch_masking::Secret;
use super::*;
#[test]
fn valid_card_number() {
let s = "371449635398431";
assert_eq!(
CardNumber::from_str(s).unwrap(),
CardNumber(StrongSecret::from_str(s).unwrap())
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_325_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
prost::encoding::string::encoded_len(1, self.0.peek())
} else {
0
}
}
fn clear(&mut self) {
*self = CardNumber::default();
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_325_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
prost::encoding::string::encoded_len(1, self.0.peek())
} else {
0
}
}
fn clear(&mut self) {
*self = CardNumber::default();
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use hyperswitch_masking::Secret;
use super::*;
#[test]
fn valid_card_number() {
let s = "371449635398431";
assert_eq!(
CardNumber::from_str(s).unwrap(),
CardNumber(StrongSecret::from_str(s).unwrap())
);
}
#[test]
fn invalid_card_number_length() {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_325_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
prost::encoding::string::encoded_len(1, self.0.peek())
} else {
0
}
}
fn clear(&mut self) {
*self = CardNumber::default();
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use hyperswitch_masking::Secret;
use super::*;
#[test]
fn valid_card_number() {
let s = "371449635398431";
assert_eq!(
CardNumber::from_str(s).unwrap(),
CardNumber(StrongSecret::from_str(s).unwrap())
);
}
#[test]
fn invalid_card_number_length() {
let s = "371446";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid card number length".to_string()
);
}
#[test]
fn card_number_with_non_digit_character() {
let s = "371446431 A";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid character found in card number".to_string()
);
}
#[test]
fn invalid_card_number() {
let s = "371446431";
assert_eq!(
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_350_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
);
}
#[test]
fn invalid_card_number_length() {
let s = "371446";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid card number length".to_string()
);
}
#[test]
fn card_number_with_non_digit_character() {
let s = "371446431 A";
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_350_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
);
}
#[test]
fn invalid_card_number_length() {
let s = "371446";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid card number length".to_string()
);
}
#[test]
fn card_number_with_non_digit_character() {
let s = "371446431 A";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid character found in card number".to_string()
);
}
#[test]
fn invalid_card_number() {
let s = "371446431";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"card number invalid".to_string()
);
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_350_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
);
}
#[test]
fn invalid_card_number_length() {
let s = "371446";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid card number length".to_string()
);
}
#[test]
fn card_number_with_non_digit_character() {
let s = "371446431 A";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"invalid character found in card number".to_string()
);
}
#[test]
fn invalid_card_number() {
let s = "371446431";
assert_eq!(
CardNumber::from_str(s).unwrap_err().to_string(),
"card number invalid".to_string()
);
}
#[test]
fn card_number_no_whitespace() {
let s = "3714 4963 5398 431";
assert_eq!(
CardNumber::from_str(s).unwrap().to_string(),
"371449*********"
);
}
#[test]
fn test_valid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> =
Secret::new("1234567890987654".to_string());
assert_eq!("123456**********", format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> = Secret::new("9123456789".to_string());
assert_eq!("*** alloc::string::String ***", format!("{secret:?}"));
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_375_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
CardNumber::from_str(s).unwrap_err().to_string(),
"card number invalid".to_string()
);
}
#[test]
fn card_number_no_whitespace() {
let s = "3714 4963 5398 431";
assert_eq!(
CardNumber::from_str(s).unwrap().to_string(),
"371449*********"
);
}
#[test]
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_375_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
CardNumber::from_str(s).unwrap_err().to_string(),
"card number invalid".to_string()
);
}
#[test]
fn card_number_no_whitespace() {
let s = "3714 4963 5398 431";
assert_eq!(
CardNumber::from_str(s).unwrap().to_string(),
"371449*********"
);
}
#[test]
fn test_valid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> =
Secret::new("1234567890987654".to_string());
assert_eq!("123456**********", format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> = Secret::new("9123456789".to_string());
assert_eq!("*** alloc::string::String ***", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_strong_secret_masking() {
let card_number = CardNumber::from_str("3714 4963 5398 431").unwrap();
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_375_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
CardNumber::from_str(s).unwrap_err().to_string(),
"card number invalid".to_string()
);
}
#[test]
fn card_number_no_whitespace() {
let s = "3714 4963 5398 431";
assert_eq!(
CardNumber::from_str(s).unwrap().to_string(),
"371449*********"
);
}
#[test]
fn test_valid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> =
Secret::new("1234567890987654".to_string());
assert_eq!("123456**********", format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_masking() {
let secret: Secret<String, CardNumberStrategy> = Secret::new("9123456789".to_string());
assert_eq!("*** alloc::string::String ***", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_strong_secret_masking() {
let card_number = CardNumber::from_str("3714 4963 5398 431").unwrap();
let secret = &(*card_number);
assert_eq!("371449*********", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""3714 4963 5398 431""#).unwrap();
let secret = card_number.to_string();
assert_eq!(r#""371449*********""#, format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""1234 5678""#);
let error_msg = card_number.unwrap_err().to_string();
assert_eq!(error_msg, "card number invalid".to_string());
}
}
#[derive(Clone, Debug, Serialize)]
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_400_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
#[test]
fn test_valid_card_number_strong_secret_masking() {
let card_number = CardNumber::from_str("3714 4963 5398 431").unwrap();
let secret = &(*card_number);
assert_eq!("371449*********", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""3714 4963 5398 431""#).unwrap();
let secret = card_number.to_string();
assert_eq!(r#""371449*********""#, format!("{secret:?}"));
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_400_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
#[test]
fn test_valid_card_number_strong_secret_masking() {
let card_number = CardNumber::from_str("3714 4963 5398 431").unwrap();
let secret = &(*card_number);
assert_eq!("371449*********", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""3714 4963 5398 431""#).unwrap();
let secret = card_number.to_string();
assert_eq!(r#""371449*********""#, format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""1234 5678""#);
let error_msg = card_number.unwrap_err().to_string();
assert_eq!(error_msg, "card number invalid".to_string());
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationMonth(StrongSecret<u8>);
impl CardExpirationMonth {
pub fn two_digits(&self) -> String {
format!("{:02}", self.0.peek())
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_400_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
}
#[test]
fn test_valid_card_number_strong_secret_masking() {
let card_number = CardNumber::from_str("3714 4963 5398 431").unwrap();
let secret = &(*card_number);
assert_eq!("371449*********", format!("{secret:?}"));
}
#[test]
fn test_valid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""3714 4963 5398 431""#).unwrap();
let secret = card_number.to_string();
assert_eq!(r#""371449*********""#, format!("{secret:?}"));
}
#[test]
fn test_invalid_card_number_deserialization() {
let card_number = serde_json::from_str::<CardNumber>(r#""1234 5678""#);
let error_msg = card_number.unwrap_err().to_string();
assert_eq!(error_msg, "card number invalid".to_string());
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationMonth(StrongSecret<u8>);
impl CardExpirationMonth {
pub fn two_digits(&self) -> String {
format!("{:02}", self.0.peek())
}
}
impl TryFrom<u8> for CardExpirationMonth {
type Error = error_stack::Report<ValidationError>;
fn try_from(month: u8) -> Result<Self, Self::Error> {
if (1..=12).contains(&month) {
Ok(Self(StrongSecret::new(month)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration month".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationMonth {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_425_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct CardExpirationMonth(StrongSecret<u8>);
impl CardExpirationMonth {
pub fn two_digits(&self) -> String {
format!("{:02}", self.0.peek())
}
}
impl TryFrom<u8> for CardExpirationMonth {
type Error = error_stack::Report<ValidationError>;
fn try_from(month: u8) -> Result<Self, Self::Error> {
if (1..=12).contains(&month) {
Ok(Self(StrongSecret::new(month)))
} else {
Err(report!(ValidationError::InvalidValue {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_425_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct CardExpirationMonth(StrongSecret<u8>);
impl CardExpirationMonth {
pub fn two_digits(&self) -> String {
format!("{:02}", self.0.peek())
}
}
impl TryFrom<u8> for CardExpirationMonth {
type Error = error_stack::Report<ValidationError>;
fn try_from(month: u8) -> Result<Self, Self::Error> {
if (1..=12).contains(&month) {
Ok(Self(StrongSecret::new(month)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration month".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationMonth {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let month = u8::deserialize(deserializer)?;
month.try_into().map_err(de::Error::custom)
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_425_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
pub struct CardExpirationMonth(StrongSecret<u8>);
impl CardExpirationMonth {
pub fn two_digits(&self) -> String {
format!("{:02}", self.0.peek())
}
}
impl TryFrom<u8> for CardExpirationMonth {
type Error = error_stack::Report<ValidationError>;
fn try_from(month: u8) -> Result<Self, Self::Error> {
if (1..=12).contains(&month) {
Ok(Self(StrongSecret::new(month)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration month".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationMonth {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let month = u8::deserialize(deserializer)?;
month.try_into().map_err(de::Error::custom)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationYear(StrongSecret<u16>);
impl CardExpirationYear {
pub fn get_year(&self) -> u16 {
*self.0.peek()
}
}
impl TryFrom<u16> for CardExpirationYear {
type Error = error_stack::Report<ValidationError>;
fn try_from(year: u16) -> Result<Self, Self::Error> {
let curr_year = u16::try_from(date_time::now().year()).map_err(|_| {
report!(ValidationError::InvalidValue {
message: "invalid year".to_string()
})
})?;
if year >= curr_year {
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_450_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
{
let month = u8::deserialize(deserializer)?;
month.try_into().map_err(de::Error::custom)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationYear(StrongSecret<u16>);
impl CardExpirationYear {
pub fn get_year(&self) -> u16 {
*self.0.peek()
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_450_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
{
let month = u8::deserialize(deserializer)?;
month.try_into().map_err(de::Error::custom)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationYear(StrongSecret<u16>);
impl CardExpirationYear {
pub fn get_year(&self) -> u16 {
*self.0.peek()
}
}
impl TryFrom<u16> for CardExpirationYear {
type Error = error_stack::Report<ValidationError>;
fn try_from(year: u16) -> Result<Self, Self::Error> {
let curr_year = u16::try_from(date_time::now().year()).map_err(|_| {
report!(ValidationError::InvalidValue {
message: "invalid year".to_string()
})
})?;
if year >= curr_year {
Ok(Self(StrongSecret::<u16>::new(year)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration year".to_string()
}))
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_450_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
{
let month = u8::deserialize(deserializer)?;
month.try_into().map_err(de::Error::custom)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct CardExpirationYear(StrongSecret<u16>);
impl CardExpirationYear {
pub fn get_year(&self) -> u16 {
*self.0.peek()
}
}
impl TryFrom<u16> for CardExpirationYear {
type Error = error_stack::Report<ValidationError>;
fn try_from(year: u16) -> Result<Self, Self::Error> {
let curr_year = u16::try_from(date_time::now().year()).map_err(|_| {
report!(ValidationError::InvalidValue {
message: "invalid year".to_string()
})
})?;
if year >= curr_year {
Ok(Self(StrongSecret::<u16>::new(year)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration year".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationYear {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let year = u16::deserialize(deserializer)?;
year.try_into().map_err(de::Error::custom)
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 43,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_475_15 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(Self(StrongSecret::<u16>::new(year)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration year".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationYear {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let year = u16::deserialize(deserializer)?;
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_475_30 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(Self(StrongSecret::<u16>::new(year)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration year".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationYear {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let year = u16::deserialize(deserializer)?;
year.try_into().map_err(de::Error::custom)
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 18,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-8249660221355203845_475_50 | clm | snippet | // connector-service/backend/cards/src/validate.rs
Ok(Self(StrongSecret::<u16>::new(year)))
} else {
Err(report!(ValidationError::InvalidValue {
message: "invalid card expiration year".to_string()
}))
}
}
}
impl<'de> Deserialize<'de> for CardExpirationYear {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let year = u16::deserialize(deserializer)?;
year.try_into().map_err(de::Error::custom)
}
}
| {
"chunk": null,
"crate": "ucs_cards",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 18,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_0_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
#![allow(clippy::unwrap_used)]
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::Instant,
};
use error_stack::ResultExt;
use http_body::Body as HttpBody;
use lazy_static::lazy_static;
use prometheus::{
self, register_histogram_vec, register_int_counter_vec, Encoder, HistogramVec, IntCounterVec,
TextEncoder,
};
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_0_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
#![allow(clippy::unwrap_used)]
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::Instant,
};
use error_stack::ResultExt;
use http_body::Body as HttpBody;
use lazy_static::lazy_static;
use prometheus::{
self, register_histogram_vec, register_int_counter_vec, Encoder, HistogramVec, IntCounterVec,
TextEncoder,
};
use tower::{Layer, Service};
// Define latency buckets for histograms
const LATENCY_BUCKETS: &[f64] = &[
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
];
lazy_static! {
pub static ref GRPC_SERVER_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_TOTAL",
"Total number of gRPC requests received",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUESTS_SUCCESSFUL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_SUCCESSFUL",
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_0_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
#![allow(clippy::unwrap_used)]
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::Instant,
};
use error_stack::ResultExt;
use http_body::Body as HttpBody;
use lazy_static::lazy_static;
use prometheus::{
self, register_histogram_vec, register_int_counter_vec, Encoder, HistogramVec, IntCounterVec,
TextEncoder,
};
use tower::{Layer, Service};
// Define latency buckets for histograms
const LATENCY_BUCKETS: &[f64] = &[
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
];
lazy_static! {
pub static ref GRPC_SERVER_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_TOTAL",
"Total number of gRPC requests received",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUESTS_SUCCESSFUL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_SUCCESSFUL",
"Total number of gRPC requests successful",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUEST_LATENCY: HistogramVec = register_histogram_vec!(
"GRPC_SERVER_REQUEST_LATENCY",
"Request latency in seconds",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_LATENCY: HistogramVec = register_histogram_vec!(
"EXTERNAL_SERVICE_API_CALLS_LATENCY_SECONDS",
"Latency of external service API calls",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_TOTAL_API_CALLS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_TOTAL_API_CALLS",
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_25_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUESTS_SUCCESSFUL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_SUCCESSFUL",
"Total number of gRPC requests successful",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUEST_LATENCY: HistogramVec = register_histogram_vec!(
"GRPC_SERVER_REQUEST_LATENCY",
"Request latency in seconds",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_25_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUESTS_SUCCESSFUL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_SUCCESSFUL",
"Total number of gRPC requests successful",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUEST_LATENCY: HistogramVec = register_histogram_vec!(
"GRPC_SERVER_REQUEST_LATENCY",
"Request latency in seconds",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_LATENCY: HistogramVec = register_histogram_vec!(
"EXTERNAL_SERVICE_API_CALLS_LATENCY_SECONDS",
"Latency of external service API calls",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_TOTAL_API_CALLS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_TOTAL_API_CALLS",
"Total number of external service API calls",
&["method", "service", "connector"]
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_ERRORS: IntCounterVec = register_int_counter_vec!(
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_25_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUESTS_SUCCESSFUL: IntCounterVec = register_int_counter_vec!(
"GRPC_SERVER_REQUESTS_SUCCESSFUL",
"Total number of gRPC requests successful",
&["method", "service", "connector"]
)
.unwrap();
pub static ref GRPC_SERVER_REQUEST_LATENCY: HistogramVec = register_histogram_vec!(
"GRPC_SERVER_REQUEST_LATENCY",
"Request latency in seconds",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_LATENCY: HistogramVec = register_histogram_vec!(
"EXTERNAL_SERVICE_API_CALLS_LATENCY_SECONDS",
"Latency of external service API calls",
&["method", "service", "connector"],
LATENCY_BUCKETS.to_vec()
)
.unwrap();
pub static ref EXTERNAL_SERVICE_TOTAL_API_CALLS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_TOTAL_API_CALLS",
"Total number of external service API calls",
&["method", "service", "connector"]
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_ERRORS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_API_CALLS_ERRORS",
"Total number of errors in external service API calls",
&["method", "service", "connector", "error"]
)
.unwrap();
}
// Middleware Layer that automatically handles all gRPC methods
#[derive(Clone)]
pub struct GrpcMetricsLayer;
#[allow(clippy::new_without_default)]
impl GrpcMetricsLayer {
pub fn new() -> Self {
Self
}
}
impl<S> Layer<S> for GrpcMetricsLayer {
type Service = GrpcMetricsService<S>;
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_50_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
"Total number of external service API calls",
&["method", "service", "connector"]
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_ERRORS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_API_CALLS_ERRORS",
"Total number of errors in external service API calls",
&["method", "service", "connector", "error"]
)
.unwrap();
}
// Middleware Layer that automatically handles all gRPC methods
#[derive(Clone)]
pub struct GrpcMetricsLayer;
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_50_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
"Total number of external service API calls",
&["method", "service", "connector"]
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_ERRORS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_API_CALLS_ERRORS",
"Total number of errors in external service API calls",
&["method", "service", "connector", "error"]
)
.unwrap();
}
// Middleware Layer that automatically handles all gRPC methods
#[derive(Clone)]
pub struct GrpcMetricsLayer;
#[allow(clippy::new_without_default)]
impl GrpcMetricsLayer {
pub fn new() -> Self {
Self
}
}
impl<S> Layer<S> for GrpcMetricsLayer {
type Service = GrpcMetricsService<S>;
fn layer(&self, service: S) -> Self::Service {
GrpcMetricsService::new(service)
}
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_50_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
"Total number of external service API calls",
&["method", "service", "connector"]
)
.unwrap();
pub static ref EXTERNAL_SERVICE_API_CALLS_ERRORS: IntCounterVec = register_int_counter_vec!(
"EXTERNAL_SERVICE_API_CALLS_ERRORS",
"Total number of errors in external service API calls",
&["method", "service", "connector", "error"]
)
.unwrap();
}
// Middleware Layer that automatically handles all gRPC methods
#[derive(Clone)]
pub struct GrpcMetricsLayer;
#[allow(clippy::new_without_default)]
impl GrpcMetricsLayer {
pub fn new() -> Self {
Self
}
}
impl<S> Layer<S> for GrpcMetricsLayer {
type Service = GrpcMetricsService<S>;
fn layer(&self, service: S) -> Self::Service {
GrpcMetricsService::new(service)
}
}
// Middleware Service that intercepts all gRPC calls
#[derive(Clone)]
pub struct GrpcMetricsService<S> {
inner: S,
}
impl<S> GrpcMetricsService<S> {
pub fn new(inner: S) -> Self {
Self { inner }
}
}
impl<S, B> Service<hyper::Request<B>> for GrpcMetricsService<S>
where
S: Service<hyper::Request<B>, Response = hyper::Response<B>> + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
B: HttpBody + Send + 'static,
{
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_75_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
fn layer(&self, service: S) -> Self::Service {
GrpcMetricsService::new(service)
}
}
// Middleware Service that intercepts all gRPC calls
#[derive(Clone)]
pub struct GrpcMetricsService<S> {
inner: S,
}
impl<S> GrpcMetricsService<S> {
pub fn new(inner: S) -> Self {
Self { inner }
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_75_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
fn layer(&self, service: S) -> Self::Service {
GrpcMetricsService::new(service)
}
}
// Middleware Service that intercepts all gRPC calls
#[derive(Clone)]
pub struct GrpcMetricsService<S> {
inner: S,
}
impl<S> GrpcMetricsService<S> {
pub fn new(inner: S) -> Self {
Self { inner }
}
}
impl<S, B> Service<hyper::Request<B>> for GrpcMetricsService<S>
where
S: Service<hyper::Request<B>, Response = hyper::Response<B>> + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
B: HttpBody + Send + 'static,
{
type Response = hyper::Response<B>;
type Error = S::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_75_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
fn layer(&self, service: S) -> Self::Service {
GrpcMetricsService::new(service)
}
}
// Middleware Service that intercepts all gRPC calls
#[derive(Clone)]
pub struct GrpcMetricsService<S> {
inner: S,
}
impl<S> GrpcMetricsService<S> {
pub fn new(inner: S) -> Self {
Self { inner }
}
}
impl<S, B> Service<hyper::Request<B>> for GrpcMetricsService<S>
where
S: Service<hyper::Request<B>, Response = hyper::Response<B>> + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
B: HttpBody + Send + 'static,
{
type Response = hyper::Response<B>;
type Error = S::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, mut req: hyper::Request<B>) -> Self::Future {
let clone = self.inner.clone();
let mut inner = std::mem::replace(&mut self.inner, clone);
let start_time = Instant::now();
// Extract method name from gRPC path
let method_name = extract_grpc_method_name(&req);
let service_name = extract_grpc_service_name(&req);
// Extract connector from request headers/metadata
let connector = extract_connector_from_request(&req);
// Increment total requests counter
GRPC_SERVER_REQUESTS_TOTAL
.with_label_values(&[&method_name, &service_name, &connector])
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_100_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
type Response = hyper::Response<B>;
type Error = S::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, mut req: hyper::Request<B>) -> Self::Future {
let clone = self.inner.clone();
let mut inner = std::mem::replace(&mut self.inner, clone);
let start_time = Instant::now();
// Extract method name from gRPC path
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_100_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
type Response = hyper::Response<B>;
type Error = S::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, mut req: hyper::Request<B>) -> Self::Future {
let clone = self.inner.clone();
let mut inner = std::mem::replace(&mut self.inner, clone);
let start_time = Instant::now();
// Extract method name from gRPC path
let method_name = extract_grpc_method_name(&req);
let service_name = extract_grpc_service_name(&req);
// Extract connector from request headers/metadata
let connector = extract_connector_from_request(&req);
// Increment total requests counter
GRPC_SERVER_REQUESTS_TOTAL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
req.extensions_mut().insert(service_name.clone());
Box::pin(async move {
let result = inner.call(req).await;
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_100_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
type Response = hyper::Response<B>;
type Error = S::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, mut req: hyper::Request<B>) -> Self::Future {
let clone = self.inner.clone();
let mut inner = std::mem::replace(&mut self.inner, clone);
let start_time = Instant::now();
// Extract method name from gRPC path
let method_name = extract_grpc_method_name(&req);
let service_name = extract_grpc_service_name(&req);
// Extract connector from request headers/metadata
let connector = extract_connector_from_request(&req);
// Increment total requests counter
GRPC_SERVER_REQUESTS_TOTAL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
req.extensions_mut().insert(service_name.clone());
Box::pin(async move {
let result = inner.call(req).await;
// Record metrics based on response
match &result {
Ok(response) => {
// Check gRPC status from response
if is_grpc_success(response) {
GRPC_SERVER_REQUESTS_SUCCESSFUL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
}
}
Err(_) => {
// Network/transport level error
}
}
// Record latency
let duration = start_time.elapsed().as_secs_f64();
GRPC_SERVER_REQUEST_LATENCY
.with_label_values(&[&method_name, &service_name, &connector])
.observe(duration);
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_125_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
.inc();
req.extensions_mut().insert(service_name.clone());
Box::pin(async move {
let result = inner.call(req).await;
// Record metrics based on response
match &result {
Ok(response) => {
// Check gRPC status from response
if is_grpc_success(response) {
GRPC_SERVER_REQUESTS_SUCCESSFUL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
}
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_125_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
.inc();
req.extensions_mut().insert(service_name.clone());
Box::pin(async move {
let result = inner.call(req).await;
// Record metrics based on response
match &result {
Ok(response) => {
// Check gRPC status from response
if is_grpc_success(response) {
GRPC_SERVER_REQUESTS_SUCCESSFUL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
}
}
Err(_) => {
// Network/transport level error
}
}
// Record latency
let duration = start_time.elapsed().as_secs_f64();
GRPC_SERVER_REQUEST_LATENCY
.with_label_values(&[&method_name, &service_name, &connector])
.observe(duration);
result
})
}
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_125_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
.inc();
req.extensions_mut().insert(service_name.clone());
Box::pin(async move {
let result = inner.call(req).await;
// Record metrics based on response
match &result {
Ok(response) => {
// Check gRPC status from response
if is_grpc_success(response) {
GRPC_SERVER_REQUESTS_SUCCESSFUL
.with_label_values(&[&method_name, &service_name, &connector])
.inc();
}
}
Err(_) => {
// Network/transport level error
}
}
// Record latency
let duration = start_time.elapsed().as_secs_f64();
GRPC_SERVER_REQUEST_LATENCY
.with_label_values(&[&method_name, &service_name, &connector])
.observe(duration);
result
})
}
}
// Extract gRPC method name from HTTP request
fn extract_grpc_method_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(method) = path.rfind('/') {
let method_name = &path[method + 1..];
if !method_name.is_empty() {
return method_name.to_string();
}
}
"unknown_method".to_string()
}
fn extract_grpc_service_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(pos) = path.rfind('/') {
let full_service = &path[1..pos];
if let Some(service_name) = full_service.rsplit('.').next() {
return service_name.to_string();
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_150_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
result
})
}
}
// Extract gRPC method name from HTTP request
fn extract_grpc_method_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(method) = path.rfind('/') {
let method_name = &path[method + 1..];
if !method_name.is_empty() {
return method_name.to_string();
}
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_150_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
result
})
}
}
// Extract gRPC method name from HTTP request
fn extract_grpc_method_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(method) = path.rfind('/') {
let method_name = &path[method + 1..];
if !method_name.is_empty() {
return method_name.to_string();
}
}
"unknown_method".to_string()
}
fn extract_grpc_service_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(pos) = path.rfind('/') {
let full_service = &path[1..pos];
if let Some(service_name) = full_service.rsplit('.').next() {
return service_name.to_string();
}
}
"unknown_service".to_string()
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_150_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
result
})
}
}
// Extract gRPC method name from HTTP request
fn extract_grpc_method_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(method) = path.rfind('/') {
let method_name = &path[method + 1..];
if !method_name.is_empty() {
return method_name.to_string();
}
}
"unknown_method".to_string()
}
fn extract_grpc_service_name<B>(req: &hyper::Request<B>) -> String {
let path = req.uri().path();
if let Some(pos) = path.rfind('/') {
let full_service = &path[1..pos];
if let Some(service_name) = full_service.rsplit('.').next() {
return service_name.to_string();
}
}
"unknown_service".to_string()
}
// Extract connector information from request
fn extract_connector_from_request<B>(req: &hyper::Request<B>) -> String {
if let Some(connector) = req.headers().get("x-connector") {
if let Ok(connector_str) = connector.to_str() {
return connector_str.to_string();
}
}
"unknown".to_string()
}
// Check if gRPC response indicates success
fn is_grpc_success<B>(response: &hyper::Response<B>) -> bool {
// gRPC success is based on grpc-status header, not HTTP status
if let Some(grpc_status) = response.headers().get("grpc-status") {
if let Ok(status_str) = grpc_status.to_str() {
if let Ok(status_code) = status_str.parse::<i32>() {
if status_code == 0 {
return true; // gRPC OK
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_175_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
}
}
"unknown_service".to_string()
}
// Extract connector information from request
fn extract_connector_from_request<B>(req: &hyper::Request<B>) -> String {
if let Some(connector) = req.headers().get("x-connector") {
if let Ok(connector_str) = connector.to_str() {
return connector_str.to_string();
}
}
"unknown".to_string()
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_175_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
}
}
"unknown_service".to_string()
}
// Extract connector information from request
fn extract_connector_from_request<B>(req: &hyper::Request<B>) -> String {
if let Some(connector) = req.headers().get("x-connector") {
if let Ok(connector_str) = connector.to_str() {
return connector_str.to_string();
}
}
"unknown".to_string()
}
// Check if gRPC response indicates success
fn is_grpc_success<B>(response: &hyper::Response<B>) -> bool {
// gRPC success is based on grpc-status header, not HTTP status
if let Some(grpc_status) = response.headers().get("grpc-status") {
if let Ok(status_str) = grpc_status.to_str() {
if let Ok(status_code) = status_str.parse::<i32>() {
if status_code == 0 {
return true; // gRPC OK
} else {
return false;
}
} else {
return false;
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_175_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
}
}
"unknown_service".to_string()
}
// Extract connector information from request
fn extract_connector_from_request<B>(req: &hyper::Request<B>) -> String {
if let Some(connector) = req.headers().get("x-connector") {
if let Ok(connector_str) = connector.to_str() {
return connector_str.to_string();
}
}
"unknown".to_string()
}
// Check if gRPC response indicates success
fn is_grpc_success<B>(response: &hyper::Response<B>) -> bool {
// gRPC success is based on grpc-status header, not HTTP status
if let Some(grpc_status) = response.headers().get("grpc-status") {
if let Ok(status_str) = grpc_status.to_str() {
if let Ok(status_code) = status_str.parse::<i32>() {
if status_code == 0 {
return true; // gRPC OK
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
true
}
// Metrics handler
pub async fn metrics_handler() -> error_stack::Result<String, MetricsError> {
let mut buffer = Vec::new();
let encoder = TextEncoder::new();
let metric_families = prometheus::gather();
encoder
.encode(&metric_families, &mut buffer)
.change_context(MetricsError::EncodingError)?;
String::from_utf8(buffer).change_context(MetricsError::Utf8Error)
}
#[derive(Debug, thiserror::Error)]
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_200_15 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
true
}
// Metrics handler
pub async fn metrics_handler() -> error_stack::Result<String, MetricsError> {
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_200_30 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
true
}
// Metrics handler
pub async fn metrics_handler() -> error_stack::Result<String, MetricsError> {
let mut buffer = Vec::new();
let encoder = TextEncoder::new();
let metric_families = prometheus::gather();
encoder
.encode(&metric_families, &mut buffer)
.change_context(MetricsError::EncodingError)?;
String::from_utf8(buffer).change_context(MetricsError::Utf8Error)
}
#[derive(Debug, thiserror::Error)]
pub enum MetricsError {
#[error("Error encoding metrics")]
EncodingError,
#[error("Error converting metrics to utf8")]
Utf8Error,
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_6066888807983657858_200_50 | clm | snippet | // connector-service/backend/external-services/src/shared_metrics.rs
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
true
}
// Metrics handler
pub async fn metrics_handler() -> error_stack::Result<String, MetricsError> {
let mut buffer = Vec::new();
let encoder = TextEncoder::new();
let metric_families = prometheus::gather();
encoder
.encode(&metric_families, &mut buffer)
.change_context(MetricsError::EncodingError)?;
String::from_utf8(buffer).change_context(MetricsError::Utf8Error)
}
#[derive(Debug, thiserror::Error)]
pub enum MetricsError {
#[error("Error encoding metrics")]
EncodingError,
#[error("Error converting metrics to utf8")]
Utf8Error,
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 31,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-7416499650036175072_0_15 | clm | snippet | // connector-service/backend/external-services/src/service.rs
use std::{collections::HashMap, str::FromStr, time::Duration};
use common_enums::ApiClientError;
use common_utils::{
ext_traits::AsyncExt,
lineage,
request::{Method, Request, RequestContent},
};
use domain_types::{
connector_types::{ConnectorResponseHeaders, RawConnectorRequestResponse},
errors::{ApiErrorResponse, ConnectorError},
router_data_v2::RouterDataV2,
router_response_types::Response,
types::Proxy,
};
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
connector-service_snippet_-7416499650036175072_0_30 | clm | snippet | // connector-service/backend/external-services/src/service.rs
use std::{collections::HashMap, str::FromStr, time::Duration};
use common_enums::ApiClientError;
use common_utils::{
ext_traits::AsyncExt,
lineage,
request::{Method, Request, RequestContent},
};
use domain_types::{
connector_types::{ConnectorResponseHeaders, RawConnectorRequestResponse},
errors::{ApiErrorResponse, ConnectorError},
router_data_v2::RouterDataV2,
router_response_types::Response,
types::Proxy,
};
use hyperswitch_masking::Secret;
use injector;
pub trait ConnectorRequestReference {
fn get_connector_request_reference_id(&self) -> &str;
}
pub trait AdditionalHeaders {
fn get_vault_headers(&self) -> Option<&HashMap<String, Secret<String>>>;
}
impl ConnectorRequestReference for domain_types::connector_types::PaymentFlowData {
fn get_connector_request_reference_id(&self) -> &str {
&self.connector_request_reference_id
}
| {
"chunk": null,
"crate": "external-services",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.