Skip to content

Commit

Permalink
Ingest: Azure SDK changes for 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
krishanjmistry committed Jan 18, 2024
1 parent 67ec88e commit 7a667ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions azure-kusto-ingest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 23 additions & 3 deletions azure-kusto-ingest/src/resource_manager/resource_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand All @@ -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,
}

Expand All @@ -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::<Vec<_>>();
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),
Expand All @@ -61,6 +76,7 @@ impl TryFrom<&str> for ResourceUri {
Ok(Self {
service_uri,
object_name,
account_name,
sas_token,
})
}
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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(),
};

Expand All @@ -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(),
};

Expand Down

0 comments on commit 7a667ea

Please sign in to comment.