Skip to content

Commit

Permalink
feat: use session_token by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Aug 28, 2024
1 parent 3c04378 commit 324ee56
Show file tree
Hide file tree
Showing 11 changed files with 536 additions and 213 deletions.
10 changes: 3 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,9 @@ pub async fn main() -> Result<()> {
// Exit client if user login failed.
if let Some(error) = err.downcast_ref::<databend_driver::Error>() {
match error {
databend_driver::Error::Api(
databend_client::error::Error::InvalidResponse(resp_err),
) => {
if resp_err.code == 401 {
println!("Authenticate failed wrong password user {}", user);
return Ok(());
}
databend_driver::Error::Api(databend_client::error::Error::AuthFailure(_)) => {
println!("Authenticate failed wrong password user {}", user);
return Ok(());
}
databend_driver::Error::Arrow(arrow::error::ArrowError::IpcError(ipc_err)) => {
if ipc_err.contains("Unauthenticated") {
Expand Down
6 changes: 2 additions & 4 deletions cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ impl Session {
Err(err) => {
match err {
databend_driver::Error::Api(
databend_client::error::Error::InvalidResponse(ref resp_err),
databend_client::error::Error::AuthFailure(_),
) => {
if resp_err.code == 401 {
return Err(err.into());
}
return Err(err.into());
}
databend_driver::Error::Arrow(arrow::error::ArrowError::IpcError(
ref ipc_err,
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async-trait = "0.1"
log = "0.4"
once_cell = "1.18"
percent-encoding = "2.3"
parking_lot = "0.12.3"
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "stream"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["std"] }
Expand Down
7 changes: 7 additions & 0 deletions core/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use crate::error::{Error, Result};
#[async_trait::async_trait]
pub trait Auth: Sync + Send {
async fn wrap(&self, builder: RequestBuilder) -> Result<RequestBuilder>;
fn can_reload(&self) -> bool {
false
}
fn username(&self) -> String;
}

Expand Down Expand Up @@ -98,6 +101,10 @@ impl Auth for AccessTokenFileAuth {
Ok(builder.bearer_auth(token.trim()))
}

fn can_reload(&self) -> bool {
true
}

fn username(&self) -> String {
"token".to_string()
}
Expand Down
Loading

0 comments on commit 324ee56

Please sign in to comment.