Skip to content

Commit

Permalink
Merge pull request #31 from Azure/17-01-2024-update
Browse files Browse the repository at this point in the history
Update versions
  • Loading branch information
AsafMah authored Jan 18, 2024
2 parents 02ce97f + 4de6078 commit 5deb758
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["azure-kusto-data"]
resolver = "2"
10 changes: 5 additions & 5 deletions azure-kusto-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
Expand Down
4 changes: 3 additions & 1 deletion azure-kusto-data/src/authorization_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
4 changes: 2 additions & 2 deletions azure-kusto-data/src/connection_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::error::ConnectionStringError;
/// Function that handles the device code flow.
pub type DeviceCodeFunction = Arc<dyn Fn(&str) -> String + Send + Sync>;
/// Function that returns a token.
pub type TokenCallbackFunction = Arc<dyn Fn(&str) -> String + Send + Sync>;
pub type TokenCallbackFunction = Arc<dyn Fn(&[&str]) -> String + Send + Sync>;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
enum ConnectionStringKey {
Expand Down Expand Up @@ -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 { .. }));
Expand Down
32 changes: 25 additions & 7 deletions azure-kusto-data/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<TokenResponse> {
Ok(TokenResponse {
token: AccessToken::new(self.token.clone()),
async fn get_token(&self, _: &[&str]) -> azure_core::Result<AccessToken> {
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.
Expand All @@ -28,16 +33,29 @@ pub struct CallbackTokenCredential {
pub(crate) time_to_live: Option<Duration>,
}

impl Debug for CallbackTokenCredential {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CallbackTokenCredential")
.field("token_callback", &"<REDACTED>")
.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<TokenResponse> {
async fn get_token(&self, scopes: &[&str]) -> azure_core::Result<AccessToken> {
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(())
}
}
5 changes: 2 additions & 3 deletions azure-kusto-data/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub use crate::request_options::{

// Token credentials are re-exported for user convenience
pub use azure_identity::{
AutoRefreshingTokenCredential, AzureCliCredential, ClientSecretCredential,
DefaultAzureCredential, DefaultAzureCredentialBuilder, EnvironmentCredential,
TokenCredentialOptions,
AzureCliCredential, ClientSecretCredential, DefaultAzureCredential,
DefaultAzureCredentialBuilder, EnvironmentCredential, TokenCredentialOptions,
};

0 comments on commit 5deb758

Please sign in to comment.