Files
osirose-new/packet-service/src/auth_client.rs
raven a8755bd3de Add comprehensive documentation and unit tests
Documentation:
- Add detailed README files for all services (auth, character, database, launcher, packet, utils, world)
- Create API documentation for the database service with detailed endpoint specifications
- Document database schema and relationships
- Add service architecture overviews and configuration instructions

Unit Tests:
- Implement comprehensive test suite for database repositories (user, character, session)
- Add gRPC service tests for database interactions
- Create tests for packet service components (bufferpool, connection, packets)
- Add utility service tests (health check, logging, load balancer, redis cache, service discovery)
- Implement auth service user tests
- Add character service tests

Code Structure:
- Reorganize test files into a more consistent structure
- Create a dedicated tests crate for integration testing
- Add test helpers and mock implementations for easier testing
2025-04-09 13:29:53 -04:00

81 lines
2.5 KiB
Rust

use crate::auth::auth_service_client::AuthServiceClient;
use crate::auth::{
LoginRequest, LoginResponse, LogoutRequest, RefreshSessionResponse, ValidateSessionRequest,
ValidateSessionResponse, ValidateTokenRequest, ValidateTokenResponse,
};
use crate::common::Empty;
use tonic::transport::Channel;
#[derive(Clone, Debug)]
pub struct AuthClient {
client: AuthServiceClient<Channel>,
}
impl AuthClient {
pub async fn connect(endpoint: &str) -> Result<Self, Box<dyn std::error::Error>> {
let client = AuthServiceClient::connect(endpoint.to_string()).await?;
Ok(AuthClient { client })
}
pub async fn login(
&mut self,
username: &str,
password: &str,
ip_address: &str,
) -> Result<LoginResponse, Box<dyn std::error::Error + Send + Sync>> {
let request = LoginRequest {
username: username.to_string(),
password: password.to_string(),
ip_address: ip_address.to_string(),
};
let response = self.client.login(request).await?;
Ok(response.into_inner())
}
pub async fn login_token(
&mut self,
token: &str,
) -> Result<ValidateTokenResponse, Box<dyn std::error::Error + Send + Sync>> {
let request = ValidateTokenRequest {
token: token.to_string(),
};
let response = self.client.validate_token(request).await?;
Ok(response.into_inner())
}
pub async fn validate_session(
&mut self,
session_id: &str,
) -> Result<ValidateSessionResponse, Box<dyn std::error::Error + Send + Sync>> {
let request = ValidateSessionRequest {
session_id: session_id.to_string(),
};
let response = self.client.validate_session(request).await?;
Ok(response.into_inner())
}
pub async fn refresh_session(
&mut self,
session_id: &str,
) -> Result<RefreshSessionResponse, Box<dyn std::error::Error + Send + Sync>> {
let request = ValidateSessionRequest {
session_id: session_id.to_string(),
};
let response = self.client.refresh_session(request).await?;
Ok(response.into_inner())
}
pub async fn logout(&mut self, session_id: &str) -> Result<Empty, Box<dyn std::error::Error + Send + Sync>> {
let request = LogoutRequest {
session_id: session_id.to_string(),
};
let response = self.client.logout(request).await?;
Ok(response.into_inner())
}
}