diff --git a/Cargo.lock b/Cargo.lock index 675a0ed0b4..04dc6d89c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5000,6 +5000,7 @@ dependencies = [ "futures", "http 1.3.1", "http-body-util", + "httparse", "humantime", "hyper 1.5.1", "itertools 0.14.0", @@ -5010,6 +5011,7 @@ dependencies = [ "rand 0.9.0", "reqwest", "ring", + "rustls-pemfile 2.2.0", "serde", "serde_json", "serde_urlencoded", diff --git a/crates/nu_plugin_polars/Cargo.toml b/crates/nu_plugin_polars/Cargo.toml index 906f1a99ac..1babee59f6 100644 --- a/crates/nu_plugin_polars/Cargo.toml +++ b/crates/nu_plugin_polars/Cargo.toml @@ -33,7 +33,7 @@ indexmap = { version = "2.11" } num = { version = "0.4" } serde = { version = "1.0", features = ["derive"] } sqlparser = { version = "=0.53.0" } -polars-io = { version = "=0.52.0", features = ["avro", "cloud", "aws"] } +polars-io = { version = "=0.52.0", features = ["avro", "cloud", "aws", "azure", "gcp"] } polars-arrow = { version = "=0.52.0" } polars-ops = { version = "=0.52.0", features = ["pivot", "cutqcut"] } polars-plan = { version = "=0.52.0", features = ["regex"] } @@ -53,7 +53,7 @@ hashbrown = { version = "0.16", features = ["rayon", "serde"] } aws-config = { version = "1.5", features = ["sso"] } aws-credential-types = "1.2" tokio = { version = "1.45", features = ["full"] } -object_store = { version = "0.12", features = ["aws"], default-features = false } +object_store = { version = "0.12", features = ["aws", "azure", "gcp"], default-features = false } url.workspace = true [dependencies.polars] diff --git a/crates/nu_plugin_polars/src/cloud/azure.rs b/crates/nu_plugin_polars/src/cloud/azure.rs new file mode 100644 index 0000000000..36721bd557 --- /dev/null +++ b/crates/nu_plugin_polars/src/cloud/azure.rs @@ -0,0 +1,42 @@ +use object_store::azure::MicrosoftAzureBuilder; +use polars_io::cloud::{AzureConfigKey, CloudOptions}; + +struct AzureOptionsBuilder { + builder: MicrosoftAzureBuilder, +} + +impl AzureOptionsBuilder { + fn new() -> Self { + Self { + builder: MicrosoftAzureBuilder::new(), + } + } + + fn get_config_value(&self, key: AzureConfigKey) -> Option<(AzureConfigKey, String)> { + self.builder.get_config_value(&key).map(|v| (key, v)) + } +} + +pub(crate) fn build_cloud_options() -> Result { + let builder = AzureOptionsBuilder::new(); + // Variables extracted from environment: + // * AZURE_STORAGE_ACCOUNT_NAME: storage account name + // * AZURE_STORAGE_ACCOUNT_KEY: storage account master key + // * AZURE_STORAGE_ACCESS_KEY: alias for AZURE_STORAGE_ACCOUNT_KEY + // * AZURE_STORAGE_CLIENT_ID -> client id for service principal authorization + // * AZURE_STORAGE_CLIENT_SECRET -> client secret for service principal authorization + // * AZURE_STORAGE_TENANT_ID -> tenant id used in oauth flows + let configs = vec![ + AzureConfigKey::AccountName, + AzureConfigKey::AccessKey, + AzureConfigKey::AccessKey, + AzureConfigKey::ClientId, + AzureConfigKey::ClientSecret, + AzureConfigKey::AuthorityId, + ] + .into_iter() + .filter_map(|key| builder.get_config_value(key)) + .collect::>(); + + Ok(CloudOptions::default().with_azure(configs)) +} diff --git a/crates/nu_plugin_polars/src/cloud/mod.rs b/crates/nu_plugin_polars/src/cloud/mod.rs index 9f8cf3cc6a..87ec5d9445 100644 --- a/crates/nu_plugin_polars/src/cloud/mod.rs +++ b/crates/nu_plugin_polars/src/cloud/mod.rs @@ -1,29 +1,23 @@ use nu_protocol::ShellError; use polars::prelude::PlPath; -use polars_io::cloud::CloudOptions; -use polars_utils::plpath::CloudScheme; +use polars_io::cloud::{CloudOptions, CloudType}; use crate::PolarsPlugin; mod aws; - -enum CloudType { - Aws, -} - -fn determine_cloud_type(plpath: &PlPath) -> Option { - match plpath.cloud_scheme() { - Some(CloudScheme::S3) | Some(CloudScheme::S3a) => Some(CloudType::Aws), - _ => None, - } -} +mod azure; pub(crate) fn build_cloud_options( plugin: &PolarsPlugin, path: &PlPath, ) -> Result, ShellError> { - match determine_cloud_type(path) { + match path + .cloud_scheme() + .map(|ref scheme| CloudType::from_cloud_scheme(scheme)) + { Some(CloudType::Aws) => aws::build_cloud_options(plugin).map(Some), + Some(CloudType::Azure) => azure::build_cloud_options().map(Some), + _ => Ok(None), } }