Skip to content

Commit

Permalink
adjustment against the new changes in server side.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Nov 7, 2024
1 parent 5ddb17b commit ed7803d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
22 changes: 5 additions & 17 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::auth::{AccessTokenAuth, AccessTokenFileAuth, Auth, BasicAuth};
use crate::error_code::{need_refresh_token, ResponseWithErrorCode};
use crate::global_cookie_store::GlobalCookieStore;
use crate::login::{
LoginRequest, LoginResponseResult, LogoutRequest, RefreshResponse, RefreshSessionTokenRequest,
LoginRequest, LoginResponseResult, RefreshResponse, RefreshSessionTokenRequest,
SessionTokenInfo,
};
use crate::presign::{presign_upload_to_stage, PresignMode, PresignedResponse, Reader};
Expand Down Expand Up @@ -648,11 +648,9 @@ impl APIClient {
LoginResponseResult::Err { error } => return Err(Error::AuthFailure(error)),
LoginResponseResult::Ok(info) => {
self.server_version = Some(info.version.clone());
if !info.token_info.session_token.is_empty() {
self.session_token_info = Some(Arc::new(parking_lot::Mutex::new((
info.token_info,
Instant::now(),
))))
if let Some(tokens) = info.tokens {
self.session_token_info =
Some(Arc::new(parking_lot::Mutex::new((tokens, Instant::now()))))
}
}
}
Expand All @@ -663,24 +661,14 @@ impl APIClient {
let endpoint = self.endpoint.join("/v1/session/logout")?;

let session_state = self.session_state();
let refresh_token = self
.session_token_info
.as_ref()
.map(|info| info.lock().0.refresh_token.clone());
let body = LogoutRequest { refresh_token };

let need_sticky = session_state.need_sticky.unwrap_or(false);
let mut headers = self.make_headers(None)?;
if need_sticky {
if let Some(node_id) = self.last_node_id() {
headers.insert(HEADER_STICKY_NODE, node_id.parse()?);
}
}
let builder = self
.cli
.post(endpoint.clone())
.json(&body)
.headers(headers.clone());
let builder = self.cli.post(endpoint.clone()).headers(headers.clone());

let builder = self.wrap_auth_or_session_token(builder)?;
let req = builder.build()?;
Expand Down
8 changes: 1 addition & 7 deletions core/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ pub struct SessionTokenInfo {
#[derive(Deserialize, Debug, Clone)]
pub struct LoginResponse {
pub version: String,
#[serde(flatten)]
pub token_info: SessionTokenInfo,
pub tokens: Option<SessionTokenInfo>,
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
Expand All @@ -74,8 +73,3 @@ pub enum RefreshResponse {
Ok(SessionTokenInfo),
Err { error: ErrorCode },
}

#[derive(Serialize, Debug)]
pub struct LogoutRequest {
pub refresh_token: Option<String>,
}

0 comments on commit ed7803d

Please sign in to comment.