- removed: api-service
- removed: session-service - updated: moved health check out of consul registration - updated: get service info to pull the service from the default namespace for the service account - updated: the rest of the services to be able to handle the new database tables
This commit is contained in:
@@ -6,9 +6,8 @@ use crate::auth::{
|
||||
};
|
||||
use crate::common::Empty;
|
||||
use crate::database_client::{DatabaseClient, DatabaseClientTrait};
|
||||
use crate::jwt::{generate_token, validate_token};
|
||||
use crate::session::session_service_client::SessionServiceClient;
|
||||
use crate::session::{CreateSessionRequest, DeleteSessionRequest, GetSessionRequest};
|
||||
use crate::session::{GetSessionRequest};
|
||||
use crate::users::{hash_password, verify_user};
|
||||
use chrono::{Duration, Utc};
|
||||
use rand::Rng;
|
||||
@@ -32,13 +31,6 @@ impl AuthService for MyAuthService {
|
||||
|
||||
async fn logout(&self, request: Request<LogoutRequest>) -> Result<Response<Empty>, Status> {
|
||||
let req = request.into_inner();
|
||||
self.session_client
|
||||
.as_ref()
|
||||
.clone()
|
||||
.delete_session(DeleteSessionRequest {
|
||||
session_id: req.session_id.clone(),
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(Response::new(Empty {}))
|
||||
}
|
||||
@@ -47,43 +39,11 @@ impl AuthService for MyAuthService {
|
||||
&self,
|
||||
request: Request<ValidateTokenRequest>,
|
||||
) -> Result<Response<ValidateTokenResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
|
||||
match validate_token(&req.token) {
|
||||
Ok(user_data) => {
|
||||
let response = self
|
||||
.session_client
|
||||
.as_ref()
|
||||
.clone()
|
||||
.get_session(GetSessionRequest {
|
||||
session_id: user_data.1.clone(),
|
||||
})
|
||||
.await;
|
||||
match response {
|
||||
Ok(res) => {
|
||||
debug!("Session valid: {:?}", res.into_inner());
|
||||
Ok(Response::new(ValidateTokenResponse {
|
||||
valid: true,
|
||||
user_id: user_data.0,
|
||||
session_id: user_data.1,
|
||||
}))
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("Session invalid or not found");
|
||||
Ok(Response::new(ValidateTokenResponse {
|
||||
valid: false,
|
||||
user_id: "".to_string(),
|
||||
session_id: "".to_string(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(Response::new(ValidateTokenResponse {
|
||||
valid: false,
|
||||
user_id: "".to_string(),
|
||||
session_id: "".to_string(),
|
||||
})),
|
||||
}
|
||||
Ok(Response::new(ValidateTokenResponse {
|
||||
valid: false,
|
||||
user_id: "".to_string(),
|
||||
session_id: "".to_string(),
|
||||
}))
|
||||
}
|
||||
|
||||
async fn validate_session(
|
||||
@@ -91,14 +51,10 @@ impl AuthService for MyAuthService {
|
||||
request: Request<ValidateSessionRequest>,
|
||||
) -> Result<Response<ValidateSessionResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
let response = self
|
||||
.session_client
|
||||
.as_ref()
|
||||
.clone()
|
||||
let response = self.session_client.as_ref().clone()
|
||||
.get_session(GetSessionRequest {
|
||||
session_id: req.session_id,
|
||||
})
|
||||
.await;
|
||||
}).await;
|
||||
|
||||
match response {
|
||||
Ok(res) => {
|
||||
@@ -106,8 +62,8 @@ impl AuthService for MyAuthService {
|
||||
debug!("Session valid: {:?}", res);
|
||||
Ok(Response::new(ValidateSessionResponse { valid: true, session_id: res.session_id.to_string(), user_id: res.user_id.to_string() }))
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("Session invalid or not found");
|
||||
Err(error) => {
|
||||
debug!("Session invalid or not found: {error}");
|
||||
Ok(Response::new(ValidateSessionResponse { valid: false, session_id: "".to_string(), user_id: "".to_string() }))
|
||||
}
|
||||
}
|
||||
@@ -122,7 +78,7 @@ impl AuthService for MyAuthService {
|
||||
.session_client
|
||||
.as_ref()
|
||||
.clone()
|
||||
.refresh_session(GetSessionRequest {
|
||||
.get_session(GetSessionRequest {
|
||||
session_id: req.session_id,
|
||||
})
|
||||
.await;
|
||||
@@ -131,10 +87,10 @@ impl AuthService for MyAuthService {
|
||||
Ok(res) => {
|
||||
let res = res.into_inner();
|
||||
debug!("Session valid: {:?}", res);
|
||||
Ok(Response::new(RefreshSessionResponse { valid: res.valid }))
|
||||
Ok(Response::new(RefreshSessionResponse { valid: true }))
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("Session invalid or not found");
|
||||
debug!("Unable to refresh session");
|
||||
Ok(Response::new(RefreshSessionResponse { valid: false }))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user