Merge remote-tracking branch 'origin/main' into simplified-ingest-client

This commit is contained in:
Krishan Mistry 2024-01-18 20:05:52 +00:00
Родитель f0dddceca7 5deb758526
Коммит 67ec88e079
6 изменённых файлов: 38 добавлений и 18 удалений

Просмотреть файл

@ -1,2 +1,3 @@
[workspace]
members = ["azure-kusto-data", "azure-kusto-ingest"]
resolver = "2"

Просмотреть файл

@ -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.17", 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.17"
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"] }

Просмотреть файл

@ -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()));

Просмотреть файл

@ -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 {
@ -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 { .. }));

Просмотреть файл

@ -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<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.
@ -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(())
}
}

Просмотреть файл

@ -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,
};