chitralverma commented on code in PR #4077: URL: https://github.com/apache/arrow-rs/pull/4077#discussion_r1175151986
########## object_store/src/options.rs: ########## @@ -0,0 +1,166 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::collections::HashMap; +pub use std::str::FromStr; + +#[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))] +use crate::client::ClientOptions; + +#[cfg(any(feature = "aws"))] +use crate::aws::AmazonS3ConfigKey; +#[cfg(feature = "azure")] +use crate::azure::AzureConfigKey; +#[cfg(feature = "gcp")] +use crate::gcp::GoogleConfigKey; + +/// Options used for configuring backend store +#[derive(Clone, Debug, Default)] +pub struct StoreOptions { + /// Store specific options like key, secret, region etc. + _store_options: HashMap<String, String>, + + /// Options specific for the internal client + #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))] + client_options: ClientOptions, +} + +impl StoreOptions { + /// Create a new instance of [`StorageOptions`] + #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))] + pub fn new( + store_options: HashMap<String, String>, + client_options: ClientOptions, + ) -> Self { + Self { + _store_options: store_options, + client_options, + } + } + + #[cfg(not(any( + feature = "gcp", + feature = "aws", + feature = "azure", + feature = "http" + )))] + pub fn new(store_options: HashMap<String, String>) -> Self { + Self { + _store_options: store_options, + } + } + + #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))] + pub fn from_iterable<I: IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>>( + iter: I, + client_options: ClientOptions, + ) -> Self { + let store_options: HashMap<String, String> = iter + .into_iter() + .map(|(key, value)| (key.as_ref().to_ascii_lowercase(), value.into())) + .collect(); + + Self { + _store_options: store_options, + client_options, + } + } + + #[cfg(not(any( + feature = "gcp", + feature = "aws", + feature = "azure", + feature = "http" + )))] + pub fn from_iterable<I: IntoIterator<Item = (impl AsRef<str>, impl Into<String>)>>( + iter: I, + ) -> Self { + let store_options: HashMap<String, String> = iter + .into_iter() + .map(|(key, value)| (key.as_ref().to_ascii_lowercase(), value.into())) + .collect(); + + Self { + _store_options: store_options, + } + } + + /// Gets an instance of ClientOptions + #[cfg(any(feature = "gcp", feature = "aws", feature = "azure", feature = "http"))] + pub fn get_client_options(&self) -> ClientOptions { + self.client_options.clone() + } + + /// Ensures that provided options are compatible with Azure + #[cfg(feature = "azure")] + pub fn get_azure_options(&self) -> HashMap<AzureConfigKey, String> { + self._store_options + .iter() + .map(|(key, value)| { + let conf_key = + AzureConfigKey::from_str(&key.to_ascii_lowercase()).unwrap(); Review Comment: @roeap this is how it was done before, but based on @tustvold's [comments](https://github.com/apache/arrow-rs/pull/4077#discussion_r1165408572) I changed it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
