diff --git a/client-gui2 b/client-gui2 index 842b941b..657bb323 160000 --- a/client-gui2 +++ b/client-gui2 @@ -1 +1 @@ -Subproject commit 842b941b3e44f780f202d8f6df93f2441f9073e9 +Subproject commit 657bb323db17f79e91319719c8f37a1ccaadbe7a diff --git a/common/proto/auth.proto b/common/proto/auth.proto index c3eda68b..54f3009d 100644 --- a/common/proto/auth.proto +++ b/common/proto/auth.proto @@ -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; diff --git a/common/src/proto/descriptor.bin b/common/src/proto/descriptor.bin index ed84cc3d..d1f18856 100644 Binary files a/common/src/proto/descriptor.bin and b/common/src/proto/descriptor.bin differ diff --git a/common/src/proto/komp_ac.auth.rs b/common/src/proto/komp_ac.auth.rs index 7b4d94b0..054a6d27 100644 --- a/common/src/proto/komp_ac.auth.rs +++ b/common/src/proto/komp_ac.auth.rs @@ -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, + ) -> std::result::Result, 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, @@ -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, + ) -> std::result::Result, tonic::Status>; async fn register( &self, request: tonic::Request, @@ -1138,6 +1179,52 @@ pub mod auth_service_server { } fn call(&mut self, req: http::Request) -> Self::Future { match req.uri().path() { + "/komp_ac.auth.AuthService/GetServerIdentity" => { + #[allow(non_camel_case_types)] + struct GetServerIdentitySvc(pub Arc); + impl< + T: AuthService, + > tonic::server::UnaryService + for GetServerIdentitySvc { + type Response = super::ServerIdentity; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::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(pub Arc); diff --git a/komp-app/src/auth.rs b/komp-app/src/auth.rs index 6f533dab..2b808e26 100644 --- a/komp-app/src/auth.rs +++ b/komp-app/src/auth.rs @@ -1,7 +1,8 @@ use anyhow::{Context, Result}; use common::proto::komp_ac::auth::{ AddRoleRequest, AssignUserRoleRequest, AuthResponse, AuthorizationSnapshot, - ChangePasswordRequest, GetAuthorizationRequest, GetInternalErrorRequest, GrantPermissionRequest, + ChangePasswordRequest, GetAuthorizationRequest, GetInternalErrorRequest, + GetServerIdentityRequest, GrantPermissionRequest, GrantableObject, InternalError, ListGrantableObjectsRequest, ListInternalErrorsRequest, ListInternalErrorsResponse, ListRolePermissionsRequest, ListRolesRequest, ListUsersRequest, LoginRequest, LoginResponse, LogoutRequest, PasswordOperationResponse, @@ -58,6 +59,15 @@ impl AuthClient { }) } + pub async fn get_server_identity(&mut self) -> Result { + 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 { Ok(self .client diff --git a/server b/server index 15d93889..d3c676d6 160000 --- a/server +++ b/server @@ -1 +1 @@ -Subproject commit 15d938893ad1fc47a94645e52356fb4b66e5c5fd +Subproject commit d3c676d64a760acbc1e35bc05af800c014deb81d