cross server client

This commit is contained in:
Priec
2026-09-03 10:42:36 +02:00
parent 0d20546787
commit 0db358c075
6 changed files with 109 additions and 5 deletions

View File

@@ -2,9 +2,10 @@
syntax = "proto3";
package komp_ac.auth;
import "common.proto";
service AuthService {
// Identifies the logical database before the client selects a saved token.
// This endpoint is deliberately unauthenticated.
rpc GetServerIdentity(GetServerIdentityRequest) returns (ServerIdentity);
rpc Register(RegisterRequest) returns (AuthResponse);
rpc Login(LoginRequest) returns (LoginResponse);
// Changes the authenticated user's password after verifying the current one.
@@ -45,6 +46,12 @@ service AuthService {
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
}
message ServerIdentity {
string instance_id = 1; // Stable UUID stored inside this database
}
message GetServerIdentityRequest {}
message RegisterRequest {
string username = 1;
string email = 2;

Binary file not shown.

View File

@@ -1,6 +1,16 @@
// This file is @generated by prost-build.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ServerIdentity {
/// Stable UUID stored inside this database
#[prost(string, tag = "1")]
pub instance_id: ::prost::alloc::string::String,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetServerIdentityRequest {}
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RegisterRequest {
#[prost(string, tag = "1")]
pub username: ::prost::alloc::string::String,
@@ -473,6 +483,31 @@ pub mod auth_service_client {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// Identifies the logical database before the client selects a saved token.
/// This endpoint is deliberately unauthenticated.
pub async fn get_server_identity(
&mut self,
request: impl tonic::IntoRequest<super::GetServerIdentityRequest>,
) -> std::result::Result<tonic::Response<super::ServerIdentity>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/GetServerIdentity",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new("komp_ac.auth.AuthService", "GetServerIdentity"),
);
self.inner.unary(req, path, codec).await
}
pub async fn register(
&mut self,
request: impl tonic::IntoRequest<super::RegisterRequest>,
@@ -947,6 +982,12 @@ pub mod auth_service_server {
/// Generated trait containing gRPC methods that should be implemented for use with AuthServiceServer.
#[async_trait]
pub trait AuthService: std::marker::Send + std::marker::Sync + 'static {
/// Identifies the logical database before the client selects a saved token.
/// This endpoint is deliberately unauthenticated.
async fn get_server_identity(
&self,
request: tonic::Request<super::GetServerIdentityRequest>,
) -> std::result::Result<tonic::Response<super::ServerIdentity>, tonic::Status>;
async fn register(
&self,
request: tonic::Request<super::RegisterRequest>,
@@ -1138,6 +1179,52 @@ pub mod auth_service_server {
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
match req.uri().path() {
"/komp_ac.auth.AuthService/GetServerIdentity" => {
#[allow(non_camel_case_types)]
struct GetServerIdentitySvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::GetServerIdentityRequest>
for GetServerIdentitySvc<T> {
type Response = super::ServerIdentity;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetServerIdentityRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::get_server_identity(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = GetServerIdentitySvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/Register" => {
#[allow(non_camel_case_types)]
struct RegisterSvc<T: AuthService>(pub Arc<T>);