diff --git a/object_store/src/aws/checksum.rs b/object_store/src/aws/checksum.rs index c787c28a8df0..57762b641ac6 100644 --- a/object_store/src/aws/checksum.rs +++ b/object_store/src/aws/checksum.rs @@ -16,6 +16,7 @@ // under the License. use ring::digest::{self, digest as ring_digest}; +use std::str::FromStr; #[allow(non_camel_case_types)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -47,13 +48,21 @@ impl std::fmt::Display for Checksum { } } -impl TryFrom<&String> for Checksum { - type Error = (); +impl FromStr for Checksum { + type Err = (); - fn try_from(value: &String) -> Result { - match value.to_lowercase().as_str() { + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { "sha256" => Ok(Self::SHA256), _ => Err(()), } } } + +impl TryFrom<&String> for Checksum { + type Error = (); + + fn try_from(value: &String) -> Result { + value.parse() + } +} diff --git a/object_store/src/aws/mod.rs b/object_store/src/aws/mod.rs index 34d468f395a4..f1a5bfb772f3 100644 --- a/object_store/src/aws/mod.rs +++ b/object_store/src/aws/mod.rs @@ -423,7 +423,7 @@ pub struct AmazonS3Builder { /// When set to true, unsigned payload option has to be used unsigned_payload: bool, /// Checksum algorithm which has to be used for object integrity check during upload - checksum_algorithm: Option, + checksum_algorithm: Option, /// Metadata endpoint, see metadata_endpoint: Option, /// Profile name, see @@ -434,30 +434,17 @@ pub struct AmazonS3Builder { /// Configuration keys for [`AmazonS3Builder`] /// -/// Configuration via keys can be dome via the [`try_with_option`](AmazonS3Builder::try_with_option) -/// or [`with_options`](AmazonS3Builder::try_with_options) methods on the builder. +/// Configuration via keys can be done via [`AmazonS3Builder::with_config`] /// /// # Example /// ``` -/// use std::collections::HashMap; -/// use object_store::aws::{AmazonS3Builder, AmazonS3ConfigKey}; -/// -/// let options = HashMap::from([ -/// ("aws_access_key_id", "my-access-key-id"), -/// ("aws_secret_access_key", "my-secret-access-key"), -/// ]); -/// let typed_options = vec![ -/// (AmazonS3ConfigKey::DefaultRegion, "my-default-region"), -/// ]; -/// let aws = AmazonS3Builder::new() -/// .try_with_options(options) -/// .unwrap() -/// .try_with_options(typed_options) -/// .unwrap() -/// .try_with_option(AmazonS3ConfigKey::Region, "my-region") -/// .unwrap(); +/// # use object_store::aws::{AmazonS3Builder, AmazonS3ConfigKey}; +/// let builder = AmazonS3Builder::new() +/// .with_config("aws_access_key_id".parse().unwrap(), "my-access-key-id") +/// .with_config(AmazonS3ConfigKey::DefaultRegion, "my-default-region"); /// ``` #[derive(PartialEq, Eq, Hash, Clone, Debug, Copy, Serialize, Deserialize)] +#[non_exhaustive] pub enum AmazonS3ConfigKey { /// AWS Access Key /// @@ -662,7 +649,7 @@ impl AmazonS3Builder { if let Ok(config_key) = AmazonS3ConfigKey::from_str(&key.to_ascii_lowercase()) { - builder = builder.try_with_option(config_key, value).unwrap(); + builder = builder.with_config(config_key, value); } } } @@ -710,14 +697,12 @@ impl AmazonS3Builder { } /// Set an option on the builder via a key - value pair. - /// - /// This method will return an `UnknownConfigKey` error if key cannot be parsed into [`AmazonS3ConfigKey`]. - pub fn try_with_option( + pub fn with_config( mut self, - key: impl AsRef, + key: AmazonS3ConfigKey, value: impl Into, - ) -> Result { - match AmazonS3ConfigKey::from_str(key.as_ref())? { + ) -> Self { + match key { AmazonS3ConfigKey::AccessKeyId => self.access_key_id = Some(value.into()), AmazonS3ConfigKey::SecretAccessKey => { self.secret_access_key = Some(value.into()) @@ -742,18 +727,28 @@ impl AmazonS3Builder { AmazonS3ConfigKey::UnsignedPayload => { self.unsigned_payload = str_is_truthy(&value.into()) } - AmazonS3ConfigKey::Checksum => { - let algorithm = Checksum::try_from(&value.into()) - .map_err(|_| Error::InvalidChecksumAlgorithm)?; - self.checksum_algorithm = Some(algorithm) - } + AmazonS3ConfigKey::Checksum => self.checksum_algorithm = Some(value.into()), }; - Ok(self) + self + } + + /// Set an option on the builder via a key - value pair. + /// + /// This method will return an `UnknownConfigKey` error if key cannot be parsed into [`AmazonS3ConfigKey`]. + #[deprecated(note = "Use with_config")] + pub fn try_with_option( + self, + key: impl AsRef, + value: impl Into, + ) -> Result { + Ok(self.with_config(key.as_ref().parse()?, value)) } /// Hydrate builder from key value pairs /// /// This method will return an `UnknownConfigKey` error if any key cannot be parsed into [`AmazonS3ConfigKey`]. + #[deprecated(note = "Use with_config")] + #[allow(deprecated)] pub fn try_with_options< I: IntoIterator, impl Into)>, >( @@ -794,7 +789,7 @@ impl AmazonS3Builder { AmazonS3ConfigKey::MetadataEndpoint => self.metadata_endpoint.clone(), AmazonS3ConfigKey::Profile => self.profile.clone(), AmazonS3ConfigKey::UnsignedPayload => Some(self.unsigned_payload.to_string()), - AmazonS3ConfigKey::Checksum => self.checksum_algorithm.map(|v| v.to_string()), + AmazonS3ConfigKey::Checksum => self.checksum_algorithm.clone(), } } @@ -935,7 +930,8 @@ impl AmazonS3Builder { /// /// [checksum algorithm]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html pub fn with_checksum_algorithm(mut self, checksum_algorithm: Checksum) -> Self { - self.checksum_algorithm = Some(checksum_algorithm); + // Convert to String to enable deferred parsing of config + self.checksum_algorithm = Some(checksum_algorithm.to_string()); self } @@ -988,6 +984,11 @@ impl AmazonS3Builder { let bucket = self.bucket_name.context(MissingBucketNameSnafu)?; let region = self.region.context(MissingRegionSnafu)?; + let checksum = self + .checksum_algorithm + .map(|c| c.parse()) + .transpose() + .map_err(|_| Error::InvalidChecksumAlgorithm)?; let credentials = match (self.access_key_id, self.secret_access_key, self.token) { (Some(key_id), Some(secret_key), token) => { @@ -1085,7 +1086,7 @@ impl AmazonS3Builder { retry_config: self.retry_config, client_options: self.client_options, sign_payload: !self.unsigned_payload, - checksum: self.checksum_algorithm, + checksum, }; let client = Arc::new(S3Client::new(config)?); @@ -1259,7 +1260,10 @@ mod tests { assert_eq!(builder.token.unwrap(), aws_session_token); let metadata_uri = format!("{METADATA_ENDPOINT}{container_creds_relative_uri}"); assert_eq!(builder.metadata_endpoint.unwrap(), metadata_uri); - assert_eq!(builder.checksum_algorithm.unwrap(), Checksum::SHA256); + assert_eq!( + builder.checksum_algorithm.unwrap(), + Checksum::SHA256.to_string() + ); assert!(builder.unsigned_payload); } @@ -1280,46 +1284,22 @@ mod tests { ("aws_checksum_algorithm", "sha256".to_string()), ]); - let builder = AmazonS3Builder::new() - .try_with_options(&options) - .unwrap() - .try_with_option("aws_secret_access_key", "new-secret-key") - .unwrap(); - assert_eq!(builder.access_key_id.unwrap(), aws_access_key_id.as_str()); - assert_eq!(builder.secret_access_key.unwrap(), "new-secret-key"); - assert_eq!(builder.region.unwrap(), aws_default_region); - assert_eq!(builder.endpoint.unwrap(), aws_endpoint); - assert_eq!(builder.token.unwrap(), aws_session_token); - assert_eq!(builder.checksum_algorithm.unwrap(), Checksum::SHA256); - assert!(builder.unsigned_payload); - } - - #[test] - fn s3_test_config_from_typed_map() { - let aws_access_key_id = "object_store:fake_access_key_id".to_string(); - let aws_secret_access_key = "object_store:fake_secret_key".to_string(); - let aws_default_region = "object_store:fake_default_region".to_string(); - let aws_endpoint = "object_store:fake_endpoint".to_string(); - let aws_session_token = "object_store:fake_session_token".to_string(); - let options = HashMap::from([ - (AmazonS3ConfigKey::AccessKeyId, aws_access_key_id.clone()), - (AmazonS3ConfigKey::SecretAccessKey, aws_secret_access_key), - (AmazonS3ConfigKey::DefaultRegion, aws_default_region.clone()), - (AmazonS3ConfigKey::Endpoint, aws_endpoint.clone()), - (AmazonS3ConfigKey::Token, aws_session_token.clone()), - (AmazonS3ConfigKey::UnsignedPayload, "true".to_string()), - ]); + let builder = options + .into_iter() + .fold(AmazonS3Builder::new(), |builder, (key, value)| { + builder.with_config(key.parse().unwrap(), value) + }) + .with_config(AmazonS3ConfigKey::SecretAccessKey, "new-secret-key"); - let builder = AmazonS3Builder::new() - .try_with_options(&options) - .unwrap() - .try_with_option(AmazonS3ConfigKey::SecretAccessKey, "new-secret-key") - .unwrap(); assert_eq!(builder.access_key_id.unwrap(), aws_access_key_id.as_str()); assert_eq!(builder.secret_access_key.unwrap(), "new-secret-key"); assert_eq!(builder.region.unwrap(), aws_default_region); assert_eq!(builder.endpoint.unwrap(), aws_endpoint); assert_eq!(builder.token.unwrap(), aws_session_token); + assert_eq!( + builder.checksum_algorithm.unwrap(), + Checksum::SHA256.to_string() + ); assert!(builder.unsigned_payload); } @@ -1330,19 +1310,15 @@ mod tests { let aws_default_region = "object_store:fake_default_region".to_string(); let aws_endpoint = "object_store:fake_endpoint".to_string(); let aws_session_token = "object_store:fake_session_token".to_string(); - let options = HashMap::from([ - (AmazonS3ConfigKey::AccessKeyId, aws_access_key_id.clone()), - ( - AmazonS3ConfigKey::SecretAccessKey, - aws_secret_access_key.clone(), - ), - (AmazonS3ConfigKey::DefaultRegion, aws_default_region.clone()), - (AmazonS3ConfigKey::Endpoint, aws_endpoint.clone()), - (AmazonS3ConfigKey::Token, aws_session_token.clone()), - (AmazonS3ConfigKey::UnsignedPayload, "true".to_string()), - ]); - let builder = AmazonS3Builder::new().try_with_options(&options).unwrap(); + let builder = AmazonS3Builder::new() + .with_config(AmazonS3ConfigKey::AccessKeyId, &aws_access_key_id) + .with_config(AmazonS3ConfigKey::SecretAccessKey, &aws_secret_access_key) + .with_config(AmazonS3ConfigKey::DefaultRegion, &aws_default_region) + .with_config(AmazonS3ConfigKey::Endpoint, &aws_endpoint) + .with_config(AmazonS3ConfigKey::Token, &aws_session_token) + .with_config(AmazonS3ConfigKey::UnsignedPayload, "true"); + assert_eq!( builder .get_config_value(&AmazonS3ConfigKey::AccessKeyId) @@ -1379,19 +1355,6 @@ mod tests { ); } - #[test] - fn s3_test_config_fallible_options() { - let aws_access_key_id = "object_store:fake_access_key_id".to_string(); - let aws_secret_access_key = "object_store:fake_secret_key".to_string(); - let options = HashMap::from([ - ("aws_access_key_id", aws_access_key_id), - ("invalid-key", aws_secret_access_key), - ]); - - let builder = AmazonS3Builder::new().try_with_options(&options); - assert!(builder.is_err()); - } - #[tokio::test] async fn s3_test() { let config = maybe_skip_integration!(); diff --git a/object_store/src/azure/mod.rs b/object_store/src/azure/mod.rs index 11350a202c72..3cec0cd47fbb 100644 --- a/object_store/src/azure/mod.rs +++ b/object_store/src/azure/mod.rs @@ -436,30 +436,17 @@ pub struct MicrosoftAzureBuilder { /// Configuration keys for [`MicrosoftAzureBuilder`] /// -/// Configuration via keys can be dome via the [`try_with_option`](MicrosoftAzureBuilder::try_with_option) -/// or [`with_options`](MicrosoftAzureBuilder::try_with_options) methods on the builder. +/// Configuration via keys can be done via [`MicrosoftAzureBuilder::with_config`] /// /// # Example /// ``` -/// use std::collections::HashMap; -/// use object_store::azure::{MicrosoftAzureBuilder, AzureConfigKey}; -/// -/// let options = HashMap::from([ -/// ("azure_client_id", "my-client-id"), -/// ("azure_client_secret", "my-account-name"), -/// ]); -/// let typed_options = vec![ -/// (AzureConfigKey::AccountName, "my-account-name"), -/// ]; -/// let azure = MicrosoftAzureBuilder::new() -/// .try_with_options(options) -/// .unwrap() -/// .try_with_options(typed_options) -/// .unwrap() -/// .try_with_option(AzureConfigKey::AuthorityId, "my-tenant-id") -/// .unwrap(); +/// # use object_store::azure::{MicrosoftAzureBuilder, AzureConfigKey}; +/// let builder = MicrosoftAzureBuilder::new() +/// .with_config("azure_client_id".parse().unwrap(), "my-client-id") +/// .with_config(AzureConfigKey::AuthorityId, "my-tenant-id"); /// ``` #[derive(PartialEq, Eq, Hash, Clone, Debug, Copy, Deserialize, Serialize)] +#[non_exhaustive] pub enum AzureConfigKey { /// The name of the azure storage account /// @@ -678,7 +665,7 @@ impl MicrosoftAzureBuilder { if let Ok(config_key) = AzureConfigKey::from_str(&key.to_ascii_lowercase()) { - builder = builder.try_with_option(config_key, value).unwrap(); + builder = builder.with_config(config_key, value); } } } @@ -724,12 +711,8 @@ impl MicrosoftAzureBuilder { } /// Set an option on the builder via a key - value pair. - pub fn try_with_option( - mut self, - key: impl AsRef, - value: impl Into, - ) -> Result { - match AzureConfigKey::from_str(key.as_ref())? { + pub fn with_config(mut self, key: AzureConfigKey, value: impl Into) -> Self { + match key { AzureConfigKey::AccessKey => self.access_key = Some(value.into()), AzureConfigKey::AccountName => self.account_name = Some(value.into()), AzureConfigKey::ClientId => self.client_id = Some(value.into()), @@ -750,10 +733,22 @@ impl MicrosoftAzureBuilder { self.use_emulator = str_is_truthy(&value.into()) } }; - Ok(self) + self + } + + /// Set an option on the builder via a key - value pair. + #[deprecated(note = "Use with_config")] + pub fn try_with_option( + self, + key: impl AsRef, + value: impl Into, + ) -> Result { + Ok(self.with_config(key.as_ref().parse()?, value)) } /// Hydrate builder from key value pairs + #[deprecated(note = "Use with_config")] + #[allow(deprecated)] pub fn try_with_options< I: IntoIterator, impl Into)>, >( @@ -1270,31 +1265,11 @@ mod tests { ("azure_storage_token", azure_storage_token), ]); - let builder = MicrosoftAzureBuilder::new() - .try_with_options(options) - .unwrap(); - assert_eq!(builder.client_id.unwrap(), azure_client_id); - assert_eq!(builder.account_name.unwrap(), azure_storage_account_name); - assert_eq!(builder.bearer_token.unwrap(), azure_storage_token); - } - - #[test] - fn azure_test_config_from_typed_map() { - let azure_client_id = "object_store:fake_access_key_id".to_string(); - let azure_storage_account_name = "object_store:fake_secret_key".to_string(); - let azure_storage_token = "object_store:fake_default_region".to_string(); - let options = HashMap::from([ - (AzureConfigKey::ClientId, azure_client_id.clone()), - ( - AzureConfigKey::AccountName, - azure_storage_account_name.clone(), - ), - (AzureConfigKey::Token, azure_storage_token.clone()), - ]); - - let builder = MicrosoftAzureBuilder::new() - .try_with_options(&options) - .unwrap(); + let builder = options + .into_iter() + .fold(MicrosoftAzureBuilder::new(), |builder, (key, value)| { + builder.with_config(key.parse().unwrap(), value) + }); assert_eq!(builder.client_id.unwrap(), azure_client_id); assert_eq!(builder.account_name.unwrap(), azure_storage_account_name); assert_eq!(builder.bearer_token.unwrap(), azure_storage_token); @@ -1305,18 +1280,11 @@ mod tests { let azure_client_id = "object_store:fake_access_key_id".to_string(); let azure_storage_account_name = "object_store:fake_secret_key".to_string(); let azure_storage_token = "object_store:fake_default_region".to_string(); - let options = HashMap::from([ - (AzureConfigKey::ClientId, azure_client_id.clone()), - ( - AzureConfigKey::AccountName, - azure_storage_account_name.clone(), - ), - (AzureConfigKey::Token, azure_storage_token.clone()), - ]); - let builder = MicrosoftAzureBuilder::new() - .try_with_options(&options) - .unwrap(); + .with_config(AzureConfigKey::ClientId, &azure_client_id) + .with_config(AzureConfigKey::AccountName, &azure_storage_account_name) + .with_config(AzureConfigKey::Token, &azure_storage_token); + assert_eq!( builder.get_config_value(&AzureConfigKey::ClientId).unwrap(), azure_client_id @@ -1333,19 +1301,6 @@ mod tests { ); } - #[test] - fn azure_test_config_fallible_options() { - let azure_client_id = "object_store:fake_access_key_id".to_string(); - let azure_storage_token = "object_store:fake_default_region".to_string(); - let options = HashMap::from([ - ("azure_client_id", azure_client_id), - ("invalid-key", azure_storage_token), - ]); - - let builder = MicrosoftAzureBuilder::new().try_with_options(&options); - assert!(builder.is_err()); - } - #[test] fn azure_test_split_sas() { let raw_sas = "?sv=2021-10-04&st=2023-01-04T17%3A48%3A57Z&se=2023-01-04T18%3A15%3A00Z&sr=c&sp=rcwl&sig=C7%2BZeEOWbrxPA3R0Cw%2Fw1EZz0%2B4KBvQexeKZKe%2BB6h0%3D"; diff --git a/object_store/src/client/retry.rs b/object_store/src/client/retry.rs index e6e92f086b2b..f9c2dd30088d 100644 --- a/object_store/src/client/retry.rs +++ b/object_store/src/client/retry.rs @@ -22,9 +22,9 @@ use futures::future::BoxFuture; use futures::FutureExt; use reqwest::header::LOCATION; use reqwest::{Response, StatusCode}; +use snafu::Error as SnafuError; use std::time::{Duration, Instant}; use tracing::info; -use snafu::Error as SnafuError; /// Retry request error #[derive(Debug)] @@ -365,13 +365,13 @@ mod tests { assert_eq!(e.message, "502 Bad Gateway"); // Panic results in an incomplete message error in the client - mock.push_fn(|_| {panic!()}); + mock.push_fn(|_| panic!()); let r = do_request().await.unwrap(); assert_eq!(r.status(), StatusCode::OK); // Gives up after retrying mulitiple panics for _ in 0..=retry.max_retries { - mock.push_fn(|_| {panic!()}); + mock.push_fn(|_| panic!()); } let e = do_request().await.unwrap_err(); assert_eq!(e.retries, retry.max_retries); diff --git a/object_store/src/gcp/mod.rs b/object_store/src/gcp/mod.rs index a6cf660220bd..6f3d53d42f34 100644 --- a/object_store/src/gcp/mod.rs +++ b/object_store/src/gcp/mod.rs @@ -786,29 +786,17 @@ pub struct GoogleCloudStorageBuilder { /// Configuration keys for [`GoogleCloudStorageBuilder`] /// -/// Configuration via keys can be done via the [`try_with_option`](GoogleCloudStorageBuilder::try_with_option) -/// or [`try_with_options`](GoogleCloudStorageBuilder::try_with_options) methods on the builder. +/// Configuration via keys can be done via [`GoogleCloudStorageBuilder::with_config`] /// /// # Example /// ``` -/// use std::collections::HashMap; -/// use object_store::gcp::{GoogleCloudStorageBuilder, GoogleConfigKey}; -/// -/// let options = HashMap::from([ -/// ("google_service_account", "my-service-account"), -/// ]); -/// let typed_options = vec![ -/// (GoogleConfigKey::Bucket, "my-bucket"), -/// ]; -/// let azure = GoogleCloudStorageBuilder::new() -/// .try_with_options(options) -/// .unwrap() -/// .try_with_options(typed_options) -/// .unwrap() -/// .try_with_option(GoogleConfigKey::Bucket, "my-new-bucket") -/// .unwrap(); +/// # use object_store::gcp::{GoogleCloudStorageBuilder, GoogleConfigKey}; +/// let builder = GoogleCloudStorageBuilder::new() +/// .with_config("google_service_account".parse().unwrap(), "my-service-account") +/// .with_config(GoogleConfigKey::Bucket, "my-bucket"); /// ``` #[derive(PartialEq, Eq, Hash, Clone, Debug, Copy, Serialize, Deserialize)] +#[non_exhaustive] pub enum GoogleConfigKey { /// Path to the service account file /// @@ -926,7 +914,7 @@ impl GoogleCloudStorageBuilder { if let Ok(config_key) = GoogleConfigKey::from_str(&key.to_ascii_lowercase()) { - builder = builder.try_with_option(config_key, value).unwrap(); + builder = builder.with_config(config_key, value); } } } @@ -957,12 +945,8 @@ impl GoogleCloudStorageBuilder { } /// Set an option on the builder via a key - value pair. - pub fn try_with_option( - mut self, - key: impl AsRef, - value: impl Into, - ) -> Result { - match GoogleConfigKey::from_str(key.as_ref())? { + pub fn with_config(mut self, key: GoogleConfigKey, value: impl Into) -> Self { + match key { GoogleConfigKey::ServiceAccount => { self.service_account_path = Some(value.into()) } @@ -974,10 +958,22 @@ impl GoogleCloudStorageBuilder { self.application_credentials_path = Some(value.into()) } }; - Ok(self) + self + } + + /// Set an option on the builder via a key - value pair. + #[deprecated(note = "Use with_config")] + pub fn try_with_option( + self, + key: impl AsRef, + value: impl Into, + ) -> Result { + Ok(self.with_config(key.as_ref().parse()?, value)) } /// Hydrate builder from key value pairs + #[deprecated(note = "Use with_config")] + #[allow(deprecated)] pub fn try_with_options< I: IntoIterator, impl Into)>, >( @@ -1449,31 +1445,12 @@ mod test { ("google_bucket_name", google_bucket_name.clone()), ]); - let builder = GoogleCloudStorageBuilder::new() - .try_with_options(&options) - .unwrap(); - assert_eq!( - builder.service_account_path.unwrap(), - google_service_account.as_str() - ); - assert_eq!(builder.bucket_name.unwrap(), google_bucket_name.as_str()); - } + let builder = options + .iter() + .fold(GoogleCloudStorageBuilder::new(), |builder, (key, value)| { + builder.with_config(key.parse().unwrap(), value) + }); - #[test] - fn gcs_test_config_from_typed_map() { - let google_service_account = "object_store:fake_service_account".to_string(); - let google_bucket_name = "object_store:fake_bucket".to_string(); - let options = HashMap::from([ - ( - GoogleConfigKey::ServiceAccount, - google_service_account.clone(), - ), - (GoogleConfigKey::Bucket, google_bucket_name.clone()), - ]); - - let builder = GoogleCloudStorageBuilder::new() - .try_with_options(&options) - .unwrap(); assert_eq!( builder.service_account_path.unwrap(), google_service_account.as_str() @@ -1485,17 +1462,10 @@ mod test { fn gcs_test_config_get_value() { let google_service_account = "object_store:fake_service_account".to_string(); let google_bucket_name = "object_store:fake_bucket".to_string(); - let options = HashMap::from([ - ( - GoogleConfigKey::ServiceAccount, - google_service_account.clone(), - ), - (GoogleConfigKey::Bucket, google_bucket_name.clone()), - ]); - let builder = GoogleCloudStorageBuilder::new() - .try_with_options(&options) - .unwrap(); + .with_config(GoogleConfigKey::ServiceAccount, &google_service_account) + .with_config(GoogleConfigKey::Bucket, &google_bucket_name); + assert_eq!( builder .get_config_value(&GoogleConfigKey::ServiceAccount) @@ -1508,19 +1478,6 @@ mod test { ); } - #[test] - fn gcs_test_config_fallible_options() { - let google_service_account = "object_store:fake_service_account".to_string(); - let google_bucket_name = "object_store:fake_bucket".to_string(); - let options = HashMap::from([ - ("google_service_account", google_service_account), - ("invalid-key", google_bucket_name), - ]); - - let builder = GoogleCloudStorageBuilder::new().try_with_options(&options); - assert!(builder.is_err()); - } - #[test] fn gcs_test_config_aliases() { // Service account path @@ -1531,16 +1488,14 @@ mod test { "service_account_path", ] { let builder = GoogleCloudStorageBuilder::new() - .try_with_options([(alias, "/fake/path.json")]) - .unwrap(); + .with_config(alias.parse().unwrap(), "/fake/path.json"); assert_eq!("/fake/path.json", builder.service_account_path.unwrap()); } // Service account key for alias in ["google_service_account_key", "service_account_key"] { let builder = GoogleCloudStorageBuilder::new() - .try_with_options([(alias, FAKE_KEY)]) - .unwrap(); + .with_config(alias.parse().unwrap(), FAKE_KEY); assert_eq!(FAKE_KEY, builder.service_account_key.unwrap()); } @@ -1552,8 +1507,7 @@ mod test { "bucket_name", ] { let builder = GoogleCloudStorageBuilder::new() - .try_with_options([(alias, "fake_bucket")]) - .unwrap(); + .with_config(alias.parse().unwrap(), "fake_bucket"); assert_eq!("fake_bucket", builder.bucket_name.unwrap()); } }