Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(file_storage): add Google Cloud Storage backend through its S3-compatible XML API (#14879)
Jagana6f6cb3058d4
diff --git a/Cargo.lock b/Cargo.lockindex c64c3fb20b..85a63c7078 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -917,9 +917,9 @@ dependencies = [[[package]]name = "aws-sdk-s3"-version = "1.65.0"+version = "1.79.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d3ba2c5c0f2618937ce3d4a5ad574b86775576fa24006bcb3128c6e2cbf3c34e"+checksum = "a8f63ba8f5fca32061c7d62d866ef65470edde38d4c5f8a0ebb8ff40a0521e1c"dependencies = ["aws-credential-types","aws-runtime",@@ -927,7 +927,7 @@ dependencies = ["aws-smithy-async","aws-smithy-checksums","aws-smithy-eventstream",- "aws-smithy-http 0.60.12",+ "aws-smithy-http 0.62.1","aws-smithy-json 0.61.3","aws-smithy-runtime","aws-smithy-runtime-api",@@ -939,6 +939,7 @@ dependencies = ["hex","hmac","http 0.2.12",+ "http 1.3.1","http-body 0.4.6","lru","once_cell",@@ -1079,15 +1080,16 @@ dependencies = [[[package]]name = "aws-smithy-checksums"-version = "0.60.13"+version = "0.63.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ba1a71073fca26775c8b5189175ea8863afb1c9ea2cceb02a5de5ad9dfbaa795"+checksum = "b65d21e1ba6f2cdec92044f904356a19f5ad86961acf015741106cdfafd747c0"dependencies = [- "aws-smithy-http 0.60.12",+ "aws-smithy-http 0.62.1","aws-smithy-types","bytes 1.10.1","crc32c","crc32fast",+ "crc64fast-nvme","hex","http 0.2.12","http-body 0.4.6",@@ -1136,6 +1138,7 @@ version = "0.62.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "99335bec6cdc50a346fda1437f9fefe33abf8c99060739a546a16457f2862ca9"dependencies = [+ "aws-smithy-eventstream","aws-smithy-runtime-api","aws-smithy-types","bytes 1.10.1",@@ -2519,6 +2522,15 @@ dependencies = ["cfg-if 1.0.0",]+[[package]]+name = "crc64fast-nvme"+version = "1.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "38fe9239af6a04e140c7424d36d1615f37f1804700c17d5339af162add9022e0"+dependencies = [+ "crc",+]+[[package]]name = "criterion"version = "0.5.1"diff --git a/config/config.example.toml b/config/config.example.tomlindex 9029383911..d7bcb41958 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -1428,7 +1428,7 @@ account_updater_topic = "topic" # Kafka topic to be used for account upd# File storage configuration[file_storage]-file_storage_backend = "aws_s3" # File storage backend to be used (file_system | aws_s3 | oci_object_storage)+file_storage_backend = "aws_s3" # File storage backend to be used (file_system | aws_s3 | oci_object_storage | gcs_object_storage)[file_storage.aws_s3]region = "us-east-1" # The AWS region used by the AWS S3 for file storage@@ -1442,6 +1442,15 @@ bucket_name = "bucket1" # The AWS S3 bucket name for file storage# region = "us-ashburn-1" # The OCI region identifier of the bucket# bucket_name = "bucket1" # The OCI Object Storage bucket name for file storage+# Used when file_storage_backend = "gcs_object_storage" (requires the `gcs_object_storage` feature,+# included in release builds). Files go through Cloud Storage's XML API (S3 interoperability),+# signed with a service account's Cloud Storage HMAC key (not the AWS credential chain).+# [file_storage.gcs_object_storage]+# bucket_name = "bucket1" # The Cloud Storage bucket name for file storage+# hmac_access_id = "GOOG1E..." # Access ID of the service account's HMAC key+# hmac_secret = "secret" # Secret of the service account's HMAC key+# region = "auto" # Optional; the region requests are signed for (defaults to auto)+[secrets_management]secrets_manager = "aws_kms" # Secrets manager client to be used (no_encryption | aws_kms | hashicorp_vault | gcp_kms | oci_kms)diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex 3b21822ce9..4019a82f08 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -130,7 +130,7 @@ account_updater_topic = "topic" # Kafka topic to be used for Account Upd# File storage configuration[file_storage]-file_storage_backend = "aws_s3" # File storage backend to be used (file_system | aws_s3 | oci_object_storage)+file_storage_backend = "aws_s3" # File storage backend to be used (file_system | aws_s3 | oci_object_storage | gcs_object_storage)[file_storage.aws_s3]region = "bucket_region" # The AWS region used by AWS S3 for file storage@@ -144,6 +144,15 @@ bucket_name = "bucket" # The AWS S3 bucket name for file storage# region = "bucket_region" # The OCI region identifier of the bucket, such as us-ashburn-1# bucket_name = "bucket" # The OCI Object Storage bucket name for file storage+# Used when file_storage_backend = "gcs_object_storage" (requires the `gcs_object_storage` feature,+# included in release builds). Files go through Cloud Storage's XML API (S3 interoperability),+# signed with a service account's Cloud Storage HMAC key (not the AWS credential chain).+# [file_storage.gcs_object_storage]+# bucket_name = "bucket" # The Cloud Storage bucket name for file storage+# hmac_access_id = "GOOG1E..." # Access ID of the service account's HMAC key+# hmac_secret = "secret" # Secret of the service account's HMAC key+# region = "auto" # Optional; the region requests are signed for (defaults to auto)+# This section provides configs for currency conversion api[forex_api]api_key = "" # Api key for making request to foreign exchange Api@@ -497,7 +506,7 @@ service = "dynamo" # Service namebase_url = "http://127.0.0.1:8080" #Base URL[theme.storage]-file_storage_backend = "aws_s3" # Theme storage backend to be used (file_system | aws_s3 | oci_object_storage)+file_storage_backend = "aws_s3" # Theme storage backend to be used (file_system | aws_s3 | oci_object_storage | gcs_object_storage)[theme.storage.aws_s3]region = "bucket_region" # AWS region where the S3 bucket for theme storage is located@@ -509,6 +518,12 @@ bucket_name = "bucket" # AWS S3 bucket name for theme storage# region = "bucket_region" # OCI region identifier where the theme storage bucket is located# bucket_name = "bucket" # OCI Object Storage bucket name for theme storage+# Used when file_storage_backend = "gcs_object_storage"; see [file_storage.gcs_object_storage].+# [theme.storage.gcs_object_storage]+# bucket_name = "bucket" # Cloud Storage bucket name for theme storage+# hmac_access_id = "GOOG1E..." # Access ID of the service account's HMAC key+# hmac_secret = "secret" # Secret of the service account's HMAC key+[theme.email_config]entity_name = "Hyperswitch" # Name of the entity to be showed in emailsentity_logo_url = "https://example.com/logo.svg" # Logo URL of the entity to be used in emailsdiff --git a/crates/cloud_services/Cargo.toml b/crates/cloud_services/Cargo.tomlindex bf2954a795..cf1f10fb39 100644--- a/crates/cloud_services/Cargo.toml+++ b/crates/cloud_services/Cargo.toml@@ -12,6 +12,7 @@ license.workspace = truedefault = []s3 = ["dep:aws-config", "dep:aws-sdk-s3", "dep:url"]oci_object_storage = ["s3"]+gcs_object_storage = ["s3"]aws_kms = ["dep:aws-config", "dep:aws-sdk-kms", "dep:base64"]gcp_kms = ["dep:google-cloud-kms", "dep:google-cloud-gax", "dep:base64"]ses = [@@ -31,7 +32,7 @@ aws-config = { version = "1.5.10", optional = true, features = ["behavior-version-latest",] }aws-sdk-kms = { version = "1.51.0", optional = true }-aws-sdk-s3 = { version = "1.65.0", optional = true }+aws-sdk-s3 = { version = "1.79.0", optional = true }aws-sdk-sesv2 = { version = "1.57.0", optional = true }aws-sdk-sts = { version = "1.51.0", optional = true }aws-smithy-runtime = { version = "1.8.3", optional = true }diff --git a/crates/cloud_services/src/lib.rs b/crates/cloud_services/src/lib.rsindex 3db035476e..607e1a220a 100644--- a/crates/cloud_services/src/lib.rs+++ b/crates/cloud_services/src/lib.rs@@ -3,15 +3,16 @@//! Each backend sits behind its own Cargo feature, so a service only compiles the providers it//! uses://!-//! | Feature | Module | Backend |-//! |----------------------|------------------|---------------------------------------------------|-//! | `s3` | [`storage::s3`] | AWS S3 |-//! | `oci_object_storage` | [`storage::oci`] | OCI Object Storage, through its S3-compatible API |-//! | `aws_kms` | [`kms::aws`] | AWS KMS |-//! | `gcp_kms` | [`kms::gcp`] | GCP Cloud KMS |-//! | `oci_kms` | [`kms::oci`] | OCI Vault KMS |-//! | `ses` | [`email::ses`] | AWS SES, as an STS-assumed role |-//! | `smtp` | [`email::smtp`] | Any SMTP server (OCI Email Delivery, SendGrid, …) |+//! | Feature | Module | Backend |+//! |----------------------|------------------|---------------------------------------------------------|+//! | `s3` | [`storage::s3`] | AWS S3 |+//! | `oci_object_storage` | [`storage::oci`] | OCI Object Storage, through its S3-compatible API |+//! | `gcs_object_storage` | [`storage::gcs`] | Google Cloud Storage, through its S3-compatible XML API |+//! | `aws_kms` | [`kms::aws`] | AWS KMS |+//! | `gcp_kms` | [`kms::gcp`] | GCP Cloud KMS |+//! | `oci_kms` | [`kms::oci`] | OCI Vault KMS |+//! | `ses` | [`email::ses`] | AWS SES, as an STS-assumed role |+//! | `smtp` | [`email::smtp`] | Any SMTP server (OCI Email Delivery, SendGrid, …) |//!//! Errors are plain [`std::error::Error`] types so callers can wrap them in whatever error//! handling they use.diff --git a/crates/cloud_services/src/storage.rs b/crates/cloud_services/src/storage.rsindex 5bb650831a..5bcd452645 100644--- a/crates/cloud_services/src/storage.rs+++ b/crates/cloud_services/src/storage.rs@@ -1,5 +1,7 @@//! Object storage clients.+#[cfg(feature = "gcs_object_storage")]+pub mod gcs;#[cfg(feature = "oci_object_storage")]pub mod oci;#[cfg(feature = "s3")]diff --git a/crates/cloud_services/src/storage/gcs.rs b/crates/cloud_services/src/storage/gcs.rsnew file mode 100644index 0000000000..abbc563e4c--- /dev/null+++ b/crates/cloud_services/src/storage/gcs.rs@@ -0,0 +1,240 @@+//! Google Cloud Storage, accessed through its XML API's Amazon S3 interoperability.++use aws_sdk_s3::config::Credentials;++use super::{+ s3::{S3Endpoint, S3Storage},+ InvalidStorageConfig,+};++/// The XML API endpoint of Google Cloud Storage, the same for every bucket location.+const GCS_XML_API_ENDPOINT: &str = "https://storage.googleapis.com";++/// The signing region Google Cloud Storage accepts for buckets in any location.+const GCS_DEFAULT_SIGNING_REGION: &str = "auto";++/// Configuration for Google Cloud Storage.+///+/// Requests go to the XML API endpoint with the bucket in the path, since Google's TLS+/// certificate does not cover bucket names that contain dots. They are signed with a Cloud+/// Storage HMAC key of a service account, taken from this configuration rather than the AWS+/// credential chain, so the process can still use AWS services with its own credentials.+#[derive(serde::Deserialize, Clone, Default)]+#[serde(default)]+pub struct GcsObjectStorageConfig {+ /// The bucket to send file uploads+ bucket_name: String,+ /// The access ID of the service account's HMAC key, such as `GOOG1E...`+ hmac_access_id: String,+ /// The secret of the service account's HMAC key+ hmac_secret: String,+ /// The region requests are signed for. Cloud Storage accepts `auto` for buckets in any+ /// location, which is used when this is unset.+ region: Option<String>,+}++impl std::fmt::Debug for GcsObjectStorageConfig {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct("GcsObjectStorageConfig")+ .field("bucket_name", &self.bucket_name)+ .field("hmac_access_id", &self.hmac_access_id)+ .field("hmac_secret", &"***")+ .field("region", &self.region)+ .finish()+ }+}++impl GcsObjectStorageConfig {+ /// Validates the Google Cloud Storage configuration, returning a description of the first+ /// problem.+ pub fn validate(&self) -> Result<(), InvalidStorageConfig> {+ if self.bucket_name.trim().is_empty() {+ return Err(InvalidStorageConfig(+ "gcs object storage bucket name must not be empty",+ ));+ }++ if self.hmac_access_id.trim().is_empty() {+ return Err(InvalidStorageConfig(+ "gcs object storage hmac access id must not be empty",+ ));+ }++ if self.hmac_secret.trim().is_empty() {+ return Err(InvalidStorageConfig(+ "gcs object storage hmac secret must not be empty",+ ));+ }++ if self+ .region+ .as_deref()+ .is_some_and(|region| region.trim().is_empty())+ {+ return Err(InvalidStorageConfig(+ "gcs object storage region must not be empty when set",+ ));+ }++ Ok(())+ }++ /// The region requests are signed for.+ fn signing_region(&self) -> &str {+ self.region.as_deref().unwrap_or(GCS_DEFAULT_SIGNING_REGION)+ }++ /// The XML API endpoint, addressed path-style.+ fn endpoint() -> S3Endpoint {+ S3Endpoint {+ url: Some(GCS_XML_API_ENDPOINT.to_owned()),+ force_path_style: true,+ }+ }++ /// The HMAC key requests are signed with.+ fn credentials(&self) -> Credentials {+ Credentials::new(+ &self.hmac_access_id,+ &self.hmac_secret,+ None,+ None,+ "gcs_object_storage",+ )+ }+}++impl S3Storage {+ /// Creates a file storage client for Google Cloud Storage.+ pub async fn new_gcs(config: &GcsObjectStorageConfig) -> Self {+ Self::with_endpoint(+ config.signing_region(),+ &config.bucket_name,+ &GcsObjectStorageConfig::endpoint(),+ Some(config.credentials()),+ )+ .await+ }+}++#[cfg(test)]+mod tests {+ use std::time::Duration;++ use super::*;+ use crate::storage::s3::tests::presigned_url;++ fn config(bucket_name: &str, region: Option<&str>) -> GcsObjectStorageConfig {+ GcsObjectStorageConfig {+ bucket_name: bucket_name.to_owned(),+ hmac_access_id: "GOOG1EXAMPLEACCESSID".to_owned(),+ hmac_secret: "example-hmac-secret".to_owned(),+ region: region.map(str::to_owned),+ }+ }++ #[test]+ fn validate_requires_a_bucket_an_hmac_key_and_a_non_empty_region_when_set() {+ assert_eq!(config("bucket", None).validate(), Ok(()));+ assert_eq!(config("bucket", Some("asia-south1")).validate(), Ok(()));+ assert_eq!(+ config(" ", None).validate(),+ Err(InvalidStorageConfig(+ "gcs object storage bucket name must not be empty"+ ))+ );+ assert_eq!(+ GcsObjectStorageConfig {+ hmac_access_id: String::new(),+ ..config("bucket", None)+ }+ .validate(),+ Err(InvalidStorageConfig(+ "gcs object storage hmac access id must not be empty"+ ))+ );+ assert_eq!(+ GcsObjectStorageConfig {+ hmac_secret: " ".to_owned(),+ ..config("bucket", None)+ }+ .validate(),+ Err(InvalidStorageConfig(+ "gcs object storage hmac secret must not be empty"+ ))+ );+ assert_eq!(+ config("bucket", Some("")).validate(),+ Err(InvalidStorageConfig(+ "gcs object storage region must not be empty when set"+ ))+ );+ }++ #[test]+ fn debug_redacts_the_hmac_secret() {+ let debug = format!("{:?}", config("bucket", None));++ assert!(debug.contains("GOOG1EXAMPLEACCESSID"), "{debug}");+ assert!(!debug.contains("example-hmac-secret"), "{debug}");+ }++ #[tokio::test]+ async fn signs_with_the_configured_hmac_key() {+ #[allow(clippy::expect_used)]+ let url = S3Storage::new_gcs(&config("bucket", None))+ .await+ .get_presigned_download_url("files/file_key", Duration::from_secs(60), None)+ .await+ .expect("presigning is local and should succeed");++ assert!(+ url.as_str()+ .starts_with("https://storage.googleapis.com/bucket/files/file_key?"),+ "{url}"+ );+ assert!(+ url.as_str()+ .contains("X-Amz-Credential=GOOG1EXAMPLEACCESSID%2F"),+ "{url}"+ );+ assert!(+ url.as_str().contains("%2Fauto%2Fs3%2Faws4_request"),+ "{url}"+ );+ }++ #[test]+ fn signs_for_auto_unless_a_region_is_set() {+ assert_eq!(config("bucket", None).signing_region(), "auto");+ assert_eq!(+ config("bucket", Some("asia-south1")).signing_region(),+ "asia-south1"+ );+ }++ #[tokio::test]+ async fn addresses_the_bucket_in_the_path_of_the_xml_api_endpoint() {+ let url = presigned_url(&GcsObjectStorageConfig::endpoint(), "my.bucket", None).await;++ assert!(+ url.starts_with("https://storage.googleapis.com/my.bucket/files/file_key?"),+ "{url}"+ );+ }++ #[tokio::test]+ async fn ignores_an_endpoint_from_the_environment() {+ let url = presigned_url(+ &GcsObjectStorageConfig::endpoint(),+ "bucket",+ Some("https://endpoint.from.env"),+ )+ .await;++ assert!(+ url.starts_with("https://storage.googleapis.com/bucket/"),+ "{url}"+ );+ }+}diff --git a/crates/cloud_services/src/storage/oci.rs b/crates/cloud_services/src/storage/oci.rsindex 18f115a81c..d0fd5cee37 100644--- a/crates/cloud_services/src/storage/oci.rs+++ b/crates/cloud_services/src/storage/oci.rs@@ -65,7 +65,13 @@ fn is_hostname_label(value: &str) -> bool {impl S3Storage {/// Creates a file storage client for OCI Object Storage.pub async fn new_oci(config: &OciObjectStorageConfig) -> Self {- Self::with_endpoint(&config.region, &config.bucket_name, &config.endpoint()).await+ Self::with_endpoint(+ &config.region,+ &config.bucket_name,+ &config.endpoint(),+ None,+ )+ .await}}diff --git a/crates/cloud_services/src/storage/s3.rs b/crates/cloud_services/src/storage/s3.rsindex 58123e4610..2e051aafae 100644--- a/crates/cloud_services/src/storage/s3.rs+++ b/crates/cloud_services/src/storage/s3.rs@@ -1,7 +1,9 @@-//! S3 object storage, for AWS S3 and S3-compatible stores such as OCI Object Storage.+//! S3 object storage, for AWS S3 and S3-compatible stores such as OCI Object Storage and Google+//! Cloud Storage.use aws_config::{meta::region::RegionProviderChain, Region};use aws_sdk_s3::{+ config::{Credentials, RequestChecksumCalculation, ResponseChecksumValidation},operation::{abort_multipart_upload::AbortMultipartUploadError,complete_multipart_upload::CompleteMultipartUploadError,@@ -51,10 +53,15 @@ pub(crate) struct S3Endpoint {pub(crate) force_path_style: bool,}-/// Builds the S3 client, applying the endpoint overrides on top of the SDK config. With the-/// default [`S3Endpoint`] this is the same client as `Client::new(sdk_config)`.+/// Builds the S3 client, applying the endpoint overrides on top of the SDK config.+///+/// Checksums are only computed and validated when an operation requires them, as the SDK did+/// before 1.69. S3-compatible stores such as Google Cloud Storage reject the flexible checksums+/// (`x-amz-checksum-*` headers, `aws-chunked` bodies) the SDK otherwise sends with every upload.fn build_client(endpoint: &S3Endpoint, sdk_config: &aws_config::SdkConfig) -> Client {- let mut s3_config = aws_sdk_s3::config::Builder::from(sdk_config);+ let mut s3_config = aws_sdk_s3::config::Builder::from(sdk_config)+ .request_checksum_calculation(RequestChecksumCalculation::WhenRequired)+ .response_checksum_validation(ResponseChecksumValidation::WhenRequired);if let Some(url) = &endpoint.url {s3_config = s3_config.endpoint_url(url);}@@ -76,17 +83,30 @@ pub struct S3Storage {impl S3Storage {/// Creates a new AWS S3 file storage client.pub async fn new(config: &S3StorageConfig) -> Self {- Self::with_endpoint(&config.region, &config.bucket_name, &S3Endpoint::default()).await+ Self::with_endpoint(+ &config.region,+ &config.bucket_name,+ &S3Endpoint::default(),+ None,+ )+ .await}- /// Creates a client for an S3-compatible store reached through `endpoint`.+ /// Creates a client for an S3-compatible store reached through `endpoint`. Requests are+ /// signed with `credentials` when given, otherwise with the SDK's default credential chain+ /// (environment, profile, web identity, instance metadata).pub(crate) async fn with_endpoint(region: &str,bucket_name: &str,endpoint: &S3Endpoint,+ credentials: Option<Credentials>,) -> Self {let region_provider = RegionProviderChain::first_try(Region::new(region.to_owned()));- let sdk_config = aws_config::from_env().region(region_provider).load().await;+ let mut loader = aws_config::from_env().region(region_provider);+ if let Some(credentials) = credentials {+ loader = loader.credentials_provider(credentials);+ }+ let sdk_config = loader.load().await;Self {inner_client: build_client(endpoint, &sdk_config),bucket_name: bucket_name.to_owned(),@@ -315,7 +335,7 @@ pub enum S3StorageError {pub(crate) mod tests {use std::time::Duration;- use aws_sdk_s3::config::{BehaviorVersion, Credentials, SharedCredentialsProvider};+ use aws_sdk_s3::config::{BehaviorVersion, SharedCredentialsProvider};use super::*;@@ -377,6 +397,20 @@ pub(crate) mod tests {);}+ #[test]+ fn checksums_are_only_sent_and_validated_when_required() {+ let client = build_client(&S3Endpoint::default(), &sdk_config(None));++ assert_eq!(+ client.config().request_checksum_calculation(),+ Some(&RequestChecksumCalculation::WhenRequired)+ );+ assert_eq!(+ client.config().response_checksum_validation(),+ Some(&ResponseChecksumValidation::WhenRequired)+ );+ }+#[tokio::test]async fn aws_config_uses_virtual_hosted_aws_endpoint() {let url = presigned_url(&S3Endpoint::default(), "bucket", None).await;diff --git a/crates/external_services/Cargo.toml b/crates/external_services/Cargo.tomlindex af1374fc46..69319fe686 100644--- a/crates/external_services/Cargo.toml+++ b/crates/external_services/Cargo.toml@@ -12,6 +12,7 @@ aws_kms = ["dep:cloud_services", "cloud_services/aws_kms"]email = ["dep:cloud_services", "cloud_services/ses", "cloud_services/smtp"]aws_s3 = ["dep:cloud_services", "cloud_services/s3"]oci_object_storage = ["dep:cloud_services", "cloud_services/oci_object_storage"]+gcs_object_storage = ["dep:cloud_services", "cloud_services/gcs_object_storage"]gcp_kms = ["dep:cloud_services", "cloud_services/gcp_kms"]oci_kms = ["dep:cloud_services", "cloud_services/oci_kms"]hashicorp-vault = ["dep:vaultrs"]diff --git a/crates/external_services/src/file_storage.rs b/crates/external_services/src/file_storage.rsindex 1b2d5c4836..03940ac86c 100644--- a/crates/external_services/src/file_storage.rs+++ b/crates/external_services/src/file_storage.rs@@ -5,8 +5,12 @@ use std::sync::Arc;use common_utils::errors::CustomResult;/// Includes functionality for AWS S3 storage operations, and the S3 client that OCI Object-/// Storage also uses.-#[cfg(any(feature = "aws_s3", feature = "oci_object_storage"))]+/// Storage and Google Cloud Storage also use.+#[cfg(any(+ feature = "aws_s3",+ feature = "oci_object_storage",+ feature = "gcs_object_storage"+))]mod aws_s3;mod file_system;@@ -15,6 +19,10 @@ mod file_system;#[cfg(feature = "oci_object_storage")]mod oci_object_storage;+/// Includes functionality for Google Cloud Storage, through its XML API.+#[cfg(feature = "gcs_object_storage")]+mod gcs_object_storage;+/// Enum representing different file storage configurations, allowing for multiple storage schemes.#[derive(Debug, Clone, Default, serde::Deserialize)]#[serde(tag = "file_storage_backend")]@@ -32,6 +40,12 @@ pub enum FileStorageConfig {/// Configuration for OCI Object Storage.oci_object_storage: oci_object_storage::OciFileStorageConfig,},+ /// Google Cloud Storage configuration.+ #[cfg(feature = "gcs_object_storage")]+ GcsObjectStorage {+ /// Configuration for Google Cloud Storage.+ gcs_object_storage: gcs_object_storage::GcsFileStorageConfig,+ },/// Local file system storage configuration.#[default]FileSystem,@@ -45,6 +59,8 @@ impl FileStorageConfig {Self::AwsS3 { aws_s3 } => aws_s3.validate()?,#[cfg(feature = "oci_object_storage")]Self::OciObjectStorage { oci_object_storage } => oci_object_storage.validate()?,+ #[cfg(feature = "gcs_object_storage")]+ Self::GcsObjectStorage { gcs_object_storage } => gcs_object_storage.validate()?,Self::FileSystem => {}}@@ -60,6 +76,10 @@ impl FileStorageConfig {Self::OciObjectStorage { oci_object_storage } => {Arc::new(oci_object_storage::client(oci_object_storage).await)}+ #[cfg(feature = "gcs_object_storage")]+ Self::GcsObjectStorage { gcs_object_storage } => {+ Arc::new(gcs_object_storage::client(gcs_object_storage).await)+ }Self::FileSystem => Arc::new(file_system::FileSystem),}}@@ -201,7 +221,11 @@ impl<'a> MultipartUpload<'a> {#[derive(Debug, Clone, thiserror::Error)]pub enum InvalidFileStorageConfig {/// The configuration of a cloud storage backend is invalid.- #[cfg(any(feature = "aws_s3", feature = "oci_object_storage"))]+ #[cfg(any(+ feature = "aws_s3",+ feature = "oci_object_storage",+ feature = "gcs_object_storage"+ ))]#[error("file_storage: {0}")]CloudStorage(#[from] cloud_services::storage::InvalidStorageConfig),}diff --git a/crates/external_services/src/file_storage/aws_s3.rs b/crates/external_services/src/file_storage/aws_s3.rsindex b91a1f2b31..57744ac58f 100644--- a/crates/external_services/src/file_storage/aws_s3.rs+++ b/crates/external_services/src/file_storage/aws_s3.rs@@ -1,5 +1,7 @@//! Hyperswitch adapter over the shared [`cloud_services`] S3 client.+#[cfg(feature = "gcs_object_storage")]+use cloud_services::storage::gcs::GcsObjectStorageConfig;#[cfg(feature = "oci_object_storage")]use cloud_services::storage::oci::OciObjectStorageConfig;use cloud_services::storage::s3::S3Storage;@@ -33,6 +35,14 @@ impl AwsFileStorageClient {inner: S3Storage::new_oci(config).await,}}++ /// Creates a file storage client for Google Cloud Storage, through its XML API.+ #[cfg(feature = "gcs_object_storage")]+ pub(super) async fn new_gcs(config: &GcsObjectStorageConfig) -> Self {+ Self {+ inner: S3Storage::new_gcs(config).await,+ }+ }}#[async_trait::async_trait]@@ -231,4 +241,44 @@ mod tests {Err("file_storage: oci object storage bucket name must not be empty".to_owned()));}++ #[cfg(feature = "gcs_object_storage")]+ #[test]+ fn gcs_object_storage_backend_config_deserializes_and_validates() {+ for gcs_object_storage in [+ serde_json::json!({+ "bucket_name": "bucket",+ "hmac_access_id": "GOOG1EXAMPLEACCESSID",+ "hmac_secret": "secret",+ }),+ serde_json::json!({+ "bucket_name": "bucket",+ "hmac_access_id": "GOOG1EXAMPLEACCESSID",+ "hmac_secret": "secret",+ "region": "asia-south1",+ }),+ ] {+ let config = file_storage_config(serde_json::json!({+ "file_storage_backend": "gcs_object_storage",+ "gcs_object_storage": gcs_object_storage,+ }));++ assert!(matches!(config, FileStorageConfig::GcsObjectStorage { .. }));+ assert!(config.validate().is_ok());+ }+ }++ #[cfg(feature = "gcs_object_storage")]+ #[test]+ fn gcs_object_storage_backend_reports_invalid_config() {+ let config = file_storage_config(serde_json::json!({+ "file_storage_backend": "gcs_object_storage",+ "gcs_object_storage": {},+ }));++ assert_eq!(+ config.validate().map_err(|error| error.to_string()),+ Err("file_storage: gcs object storage bucket name must not be empty".to_owned())+ );+ }}diff --git a/crates/external_services/src/file_storage/gcs_object_storage.rs b/crates/external_services/src/file_storage/gcs_object_storage.rsnew file mode 100644index 0000000000..258b737111--- /dev/null+++ b/crates/external_services/src/file_storage/gcs_object_storage.rs@@ -0,0 +1,10 @@+//! Google Cloud Storage, accessed through its XML API's Amazon S3 interoperability.++pub use cloud_services::storage::gcs::GcsObjectStorageConfig as GcsFileStorageConfig;++use super::aws_s3::AwsFileStorageClient;++/// Creates a file storage client for Google Cloud Storage.+pub(super) async fn client(config: &GcsFileStorageConfig) -> AwsFileStorageClient {+ AwsFileStorageClient::new_gcs(config).await+}diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex be015955cb..f0ad967097 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -61,6 +61,7 @@ stripe = []gcp_kms = ["external_services/gcp_kms"]oci_kms = ["external_services/oci_kms"]oci_object_storage = ["external_services/oci_object_storage"]+gcs_object_storage = ["external_services/gcs_object_storage"]release = ["stripe","email",@@ -72,6 +73,7 @@ release = ["oci_kms","external_services/aws_s3","oci_object_storage",+ "gcs_object_storage","keymanager_mtls","keymanager_create","encryption_service",