cross server client
This commit is contained in:
Submodule client-gui2 updated: 842b941b3e...657bb323db
@@ -2,9 +2,10 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package komp_ac.auth;
|
package komp_ac.auth;
|
||||||
|
|
||||||
import "common.proto";
|
|
||||||
|
|
||||||
service AuthService {
|
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 Register(RegisterRequest) returns (AuthResponse);
|
||||||
rpc Login(LoginRequest) returns (LoginResponse);
|
rpc Login(LoginRequest) returns (LoginResponse);
|
||||||
// Changes the authenticated user's password after verifying the current one.
|
// Changes the authenticated user's password after verifying the current one.
|
||||||
@@ -45,6 +46,12 @@ service AuthService {
|
|||||||
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
|
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ServerIdentity {
|
||||||
|
string instance_id = 1; // Stable UUID stored inside this database
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetServerIdentityRequest {}
|
||||||
|
|
||||||
message RegisterRequest {
|
message RegisterRequest {
|
||||||
string username = 1;
|
string username = 1;
|
||||||
string email = 2;
|
string email = 2;
|
||||||
|
|||||||
Binary file not shown.
@@ -1,6 +1,16 @@
|
|||||||
// This file is @generated by prost-build.
|
// This file is @generated by prost-build.
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
#[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 {
|
pub struct RegisterRequest {
|
||||||
#[prost(string, tag = "1")]
|
#[prost(string, tag = "1")]
|
||||||
pub username: ::prost::alloc::string::String,
|
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.inner = self.inner.max_encoding_message_size(limit);
|
||||||
self
|
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(
|
pub async fn register(
|
||||||
&mut self,
|
&mut self,
|
||||||
request: impl tonic::IntoRequest<super::RegisterRequest>,
|
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.
|
/// Generated trait containing gRPC methods that should be implemented for use with AuthServiceServer.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait AuthService: std::marker::Send + std::marker::Sync + 'static {
|
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(
|
async fn register(
|
||||||
&self,
|
&self,
|
||||||
request: tonic::Request<super::RegisterRequest>,
|
request: tonic::Request<super::RegisterRequest>,
|
||||||
@@ -1138,6 +1179,52 @@ pub mod auth_service_server {
|
|||||||
}
|
}
|
||||||
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
match req.uri().path() {
|
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" => {
|
"/komp_ac.auth.AuthService/Register" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct RegisterSvc<T: AuthService>(pub Arc<T>);
|
struct RegisterSvc<T: AuthService>(pub Arc<T>);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use common::proto::komp_ac::auth::{
|
use common::proto::komp_ac::auth::{
|
||||||
AddRoleRequest, AssignUserRoleRequest, AuthResponse, AuthorizationSnapshot,
|
AddRoleRequest, AssignUserRoleRequest, AuthResponse, AuthorizationSnapshot,
|
||||||
ChangePasswordRequest, GetAuthorizationRequest, GetInternalErrorRequest, GrantPermissionRequest,
|
ChangePasswordRequest, GetAuthorizationRequest, GetInternalErrorRequest,
|
||||||
|
GetServerIdentityRequest, GrantPermissionRequest,
|
||||||
GrantableObject, InternalError, ListGrantableObjectsRequest, ListInternalErrorsRequest,
|
GrantableObject, InternalError, ListGrantableObjectsRequest, ListInternalErrorsRequest,
|
||||||
ListInternalErrorsResponse, ListRolePermissionsRequest, ListRolesRequest,
|
ListInternalErrorsResponse, ListRolePermissionsRequest, ListRolesRequest,
|
||||||
ListUsersRequest, LoginRequest, LoginResponse, LogoutRequest, PasswordOperationResponse,
|
ListUsersRequest, LoginRequest, LoginResponse, LogoutRequest, PasswordOperationResponse,
|
||||||
@@ -58,6 +59,15 @@ impl AuthClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_server_identity(&mut self) -> Result<String> {
|
||||||
|
Ok(self
|
||||||
|
.client
|
||||||
|
.get_server_identity(Request::new(GetServerIdentityRequest {}))
|
||||||
|
.await?
|
||||||
|
.into_inner()
|
||||||
|
.instance_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse> {
|
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.client
|
.client
|
||||||
|
|||||||
2
server
2
server
Submodule server updated: 15d938893a...d3c676d64a
Reference in New Issue
Block a user