From 09ee9e838e221c0562ed1a634fde53dd62c9afbb Mon Sep 17 00:00:00 2001 From: asafmahlev Date: Wed, 17 Jan 2024 14:44:57 +0200 Subject: [PATCH 1/5] Update versions --- azure-kusto-data/Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azure-kusto-data/Cargo.toml b/azure-kusto-data/Cargo.toml index 7bd53f7..4366ad6 100644 --- a/azure-kusto-data/Cargo.toml +++ b/azure-kusto-data/Cargo.toml @@ -13,13 +13,13 @@ keywords = ["sdk", "azure", "kusto", "azure-data-explorer"] categories = ["api-bindings"] [dependencies] -arrow-array = { version = "42", optional = true } -arrow-schema = { version = "42", optional = true } -azure_core = { version = "0.13", features = [ +arrow-array = { version = "50.0.0", optional = true } +arrow-schema = { version = "50.0.0", optional = true } +azure_core = { version = "0.19.0", features = [ "enable_reqwest", "enable_reqwest_gzip", ] } -azure_identity = "0.13.0" +azure_identity = "0.19.0" async-trait = "0.1.64" async-convert = "1.0.0" bytes = "1.4" @@ -41,7 +41,7 @@ derive_builder = "0.12" once_cell = "1" [dev-dependencies] -arrow = { version = "42", features = ["prettyprint"] } +arrow = { version = "50.0.0", features = ["prettyprint"] } dotenv = "0.15.0" env_logger = "0.10.0" tokio = { version = "1.25.0", features = ["macros"] } From b244624773ccb211dd3a26d37f35527e199db7bd Mon Sep 17 00:00:00 2001 From: asafmahlev Date: Wed, 17 Jan 2024 14:49:17 +0200 Subject: [PATCH 2/5] Fix connection string --- Cargo.toml | 1 + azure-kusto-data/src/authorization_policy.rs | 4 ++- azure-kusto-data/src/connection_string.rs | 2 +- azure-kusto-data/src/credentials.rs | 32 +++++++++++++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 739a289..303c71e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] members = ["azure-kusto-data"] +resolver = "2" diff --git a/azure-kusto-data/src/authorization_policy.rs b/azure-kusto-data/src/authorization_policy.rs index d5132fd..472c8fe 100644 --- a/azure-kusto-data/src/authorization_policy.rs +++ b/azure-kusto-data/src/authorization_policy.rs @@ -73,7 +73,9 @@ impl Policy for AuthorizationPolicy { } }; - let token = cred.get_token(&resource).await?; + let scope = format!("{}/.default", resource); + + let token = cred.get_token(&[&scope]).await?; request.insert_header(AUTHORIZATION, &format!("Bearer {}", token.token.secret())); diff --git a/azure-kusto-data/src/connection_string.rs b/azure-kusto-data/src/connection_string.rs index 2495eb9..61511cc 100644 --- a/azure-kusto-data/src/connection_string.rs +++ b/azure-kusto-data/src/connection_string.rs @@ -22,7 +22,7 @@ use crate::error::ConnectionStringError; /// Function that handles the device code flow. pub type DeviceCodeFunction = Arc String + Send + Sync>; /// Function that returns a token. -pub type TokenCallbackFunction = Arc String + Send + Sync>; +pub type TokenCallbackFunction = Arc String + Send + Sync>; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] enum ConnectionStringKey { diff --git a/azure-kusto-data/src/credentials.rs b/azure-kusto-data/src/credentials.rs index c4b3642..b4b4771 100644 --- a/azure-kusto-data/src/credentials.rs +++ b/azure-kusto-data/src/credentials.rs @@ -1,7 +1,8 @@ //! Custom credentials for Azure Data Explorer. use crate::connection_string::TokenCallbackFunction; -use azure_core::auth::{AccessToken, TokenCredential, TokenResponse}; +use azure_core::auth::{AccessToken, TokenCredential}; +use std::fmt::{Debug, Formatter}; use std::time::Duration; use time::OffsetDateTime; @@ -14,12 +15,16 @@ pub struct ConstTokenCredential { } #[async_trait::async_trait] impl TokenCredential for ConstTokenCredential { - async fn get_token(&self, _resource: &str) -> azure_core::Result { - Ok(TokenResponse { - token: AccessToken::new(self.token.clone()), + async fn get_token(&self, _: &[&str]) -> azure_core::Result { + Ok(AccessToken { + token: self.token.clone().into(), expires_on: OffsetDateTime::now_utc() + Duration::from_secs(SECONDS_IN_50_YEARS), }) } + + async fn clear_cache(&self) -> azure_core::Result<()> { + Ok(()) + } } /// Uses a user provided callback that accepts the resource and returns a token in order to authenticate. @@ -28,16 +33,29 @@ pub struct CallbackTokenCredential { pub(crate) time_to_live: Option, } +impl Debug for CallbackTokenCredential { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("CallbackTokenCredential") + .field("token_callback", &"") + .field("time_to_live", &self.time_to_live) + .finish() + } +} + #[async_trait::async_trait] impl TokenCredential for CallbackTokenCredential { - async fn get_token(&self, resource: &str) -> azure_core::Result { + async fn get_token(&self, scopes: &[&str]) -> azure_core::Result { let callback = &self.token_callback; - Ok(TokenResponse { - token: AccessToken::new(callback(resource)), + Ok(AccessToken { + token: callback(scopes).into(), expires_on: OffsetDateTime::now_utc() + self .time_to_live .unwrap_or(Duration::from_secs(SECONDS_IN_50_YEARS)), }) } + + async fn clear_cache(&self) -> azure_core::Result<()> { + Ok(()) + } } From bc9ac6ca11d040fb8dbe438fe2ea51eeec7e5214 Mon Sep 17 00:00:00 2001 From: asafmahlev Date: Wed, 17 Jan 2024 14:52:59 +0200 Subject: [PATCH 3/5] Fix connection string --- azure-kusto-data/src/prelude.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-kusto-data/src/prelude.rs b/azure-kusto-data/src/prelude.rs index 726caab..36502ce 100644 --- a/azure-kusto-data/src/prelude.rs +++ b/azure-kusto-data/src/prelude.rs @@ -24,7 +24,7 @@ pub use crate::request_options::{ // Token credentials are re-exported for user convenience pub use azure_identity::{ - AutoRefreshingTokenCredential, AzureCliCredential, ClientSecretCredential, + AzureCliCredential, ClientSecretCredential, DefaultAzureCredential, DefaultAzureCredentialBuilder, EnvironmentCredential, TokenCredentialOptions, }; From ce35f8ac1935333c76b429bdfd8e4c661b581017 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:54:02 +0000 Subject: [PATCH 4/5] Format Rust code using rustfmt --- azure-kusto-data/src/prelude.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/azure-kusto-data/src/prelude.rs b/azure-kusto-data/src/prelude.rs index 36502ce..319bc6f 100644 --- a/azure-kusto-data/src/prelude.rs +++ b/azure-kusto-data/src/prelude.rs @@ -24,7 +24,6 @@ pub use crate::request_options::{ // Token credentials are re-exported for user convenience pub use azure_identity::{ - AzureCliCredential, ClientSecretCredential, - DefaultAzureCredential, DefaultAzureCredentialBuilder, EnvironmentCredential, - TokenCredentialOptions, + AzureCliCredential, ClientSecretCredential, DefaultAzureCredential, + DefaultAzureCredentialBuilder, EnvironmentCredential, TokenCredentialOptions, }; From 89052f48e455494f65ab4dccd5e27a534baba937 Mon Sep 17 00:00:00 2001 From: asafmahlev Date: Wed, 17 Jan 2024 15:03:17 +0200 Subject: [PATCH 5/5] Fix connection string --- azure-kusto-data/src/connection_string.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-kusto-data/src/connection_string.rs b/azure-kusto-data/src/connection_string.rs index 61511cc..5c6b033 100644 --- a/azure-kusto-data/src/connection_string.rs +++ b/azure-kusto-data/src/connection_string.rs @@ -775,7 +775,7 @@ impl ConnectionString { /// use std::sync::Arc; /// use azure_kusto_data::prelude::{ConnectionString, ConnectionStringAuth}; /// - /// let conn = ConnectionString::with_token_callback_auth("https://mycluster.kusto.windows.net", Arc::new(|resource_uri| resource_uri.to_string()), None); + /// let conn = ConnectionString::with_token_callback_auth("https://mycluster.kusto.windows.net", Arc::new(|scopes| scopes[0].to_string()), None); /// /// assert_eq!(conn.data_source, "https://mycluster.kusto.windows.net".to_string()); /// assert!(matches!(conn.auth, ConnectionStringAuth::TokenCallback { .. }));