From 7a667eab6939d648e0f1ed7ebd62ae002409fc4f Mon Sep 17 00:00:00 2001 From: Krishan Mistry Date: Tue, 16 Jan 2024 16:20:10 +0000 Subject: [PATCH] Ingest: Azure SDK changes for 0.19 --- azure-kusto-ingest/Cargo.toml | 8 +++--- .../src/resource_manager/resource_uri.rs | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/azure-kusto-ingest/Cargo.toml b/azure-kusto-ingest/Cargo.toml index b389b9d..6f6833b 100644 --- a/azure-kusto-ingest/Cargo.toml +++ b/azure-kusto-ingest/Cargo.toml @@ -8,10 +8,10 @@ edition = "2021" [dependencies] azure-kusto-data = {path = "../azure-kusto-data"} # Azure SDK for Rust crates versions must be kept in sync -azure_core = "0.17" -azure_storage = "0.17" -azure_storage_blobs = "0.17" -azure_storage_queues = "0.17" +azure_core = "0.19" +azure_storage = "0.19" +azure_storage_blobs = "0.19" +azure_storage_queues = "0.19" chrono = { version = "0.4", default-features = false, features = ["serde"] } rand = "0.8" diff --git a/azure-kusto-ingest/src/resource_manager/resource_uri.rs b/azure-kusto-ingest/src/resource_manager/resource_uri.rs index f41d1ff..f31f2b4 100644 --- a/azure-kusto-ingest/src/resource_manager/resource_uri.rs +++ b/azure-kusto-ingest/src/resource_manager/resource_uri.rs @@ -15,6 +15,9 @@ pub enum ResourceUriError { #[error("SAS token is missing in the URI as a query parameter")] MissingSasToken, + #[error("Account name is missing in the URI")] + MissingAccountName, + #[error(transparent)] ParseError(#[from] url::ParseError), @@ -27,6 +30,7 @@ pub enum ResourceUriError { pub(crate) struct ResourceUri { pub(crate) service_uri: String, pub(crate) object_name: String, + pub(crate) account_name: String, pub(crate) sas_token: StorageCredentials, } @@ -41,11 +45,22 @@ impl TryFrom<&str> for ResourceUri { other_scheme => return Err(ResourceUriError::InvalidScheme(other_scheme.to_string())), }; + let host_string = parsed_uri + .host_str() + .expect("Url::parse should always return a host for a URI"); + let service_uri = scheme + "://" - + parsed_uri - .host_str() - .expect("Url::parse should always return a host for a URI"); + + host_string; + + + let host_string_components = host_string + .split_terminator('.').collect::>(); + if host_string_components.len() < 2 { + return Err(ResourceUriError::MissingAccountName); + } + + let account_name = host_string_components[0].to_string(); let object_name = match parsed_uri.path().trim_start().trim_start_matches('/') { "" => return Err(ResourceUriError::MissingObjectName), @@ -61,6 +76,7 @@ impl TryFrom<&str> for ResourceUri { Ok(Self { service_uri, object_name, + account_name, sas_token, }) } @@ -76,6 +92,7 @@ impl ClientFromResourceUri for QueueClient { QueueServiceClientBuilder::with_location( azure_storage::CloudLocation::Custom { uri: resource_uri.service_uri, + account: resource_uri.account_name, }, resource_uri.sas_token, ) @@ -90,6 +107,7 @@ impl ClientFromResourceUri for ContainerClient { ClientBuilder::with_location( azure_storage::CloudLocation::Custom { uri: resource_uri.service_uri, + account: resource_uri.account_name, }, resource_uri.sas_token, ) @@ -183,6 +201,7 @@ mod tests { let resource_uri = ResourceUri { service_uri: "https://mystorageaccount.queue.core.windows.net".to_string(), object_name: "queuename".to_string(), + account_name: "mystorageaccount".to_string(), sas_token: StorageCredentials::sas_token("sas=token").unwrap(), }; @@ -197,6 +216,7 @@ mod tests { let resource_uri = ResourceUri { service_uri: "https://mystorageaccount.blob.core.windows.net".to_string(), object_name: "containername".to_string(), + account_name: "mystorageaccount".to_string(), sas_token: StorageCredentials::sas_token("sas=token").unwrap(), };