From 025e03ee161e07ca17be9fa199c07f63396ea474 Mon Sep 17 00:00:00 2001 From: Priec Date: Thu, 9 Jul 2026 22:34:40 +0200 Subject: [PATCH] rbac from the server used in the client from now on --- common/proto/auth.proto | 14 +++++ common/src/proto/descriptor.bin | Bin 87671 -> 88455 bytes common/src/proto/komp_ac.auth.rs | 96 ++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/common/proto/auth.proto b/common/proto/auth.proto index 759bb29..e7b5e7a 100644 --- a/common/proto/auth.proto +++ b/common/proto/auth.proto @@ -7,6 +7,7 @@ import "common.proto"; service AuthService { rpc Register(RegisterRequest) returns (AuthResponse); rpc Login(LoginRequest) returns (LoginResponse); + rpc GetAuthorization(GetAuthorizationRequest) returns (AuthorizationSnapshot); } message RegisterRequest { @@ -36,4 +37,17 @@ message LoginResponse { string user_id = 4; // User's UUID in string format string role = 5; // User's role string username = 6; + AuthorizationSnapshot authorization = 7; +} + +message GetAuthorizationRequest {} + +message Permission { + string resource = 1; + string action = 2; +} + +message AuthorizationSnapshot { + string role = 1; + repeated Permission permissions = 2; } diff --git a/common/src/proto/descriptor.bin b/common/src/proto/descriptor.bin index af291603a40170c0f18409e008aa933a51c6e504..b99ee321fadc3c3f99c53fe1332e80cb9735e30c 100644 GIT binary patch delta 1852 zcma)6O>Y}j6rK0p*qM2bzg|4{#I+lH{E@`1oyKk=6(mI2pjHS~DH0MwAS<$HRGJC4 zvtcu;K=1=*(LccgsY1YpEeke?Ex&?I*>diiH>0{Mc5~*QbMC$8y_tW1$bJ7Z_v4>q z{(Ix)U*qo>|CYy}9Q_)p2eLT7UOx$!7hliU7vZJ9)nNyPX>am0e0KHu{Cq;y$^F+U zk1yv}t0&?5Y*QKR%EtSP^#=89@zwQWwGQ5u^3h`X>|(V-3)Pg)a&KXXxji zr7sq$F7xwqJqgzpgMu%lw_%-5p_H_j;g_kAepYYE!d2F9<@1ifPX6XjG?14}boM%X z`YQJByol6ivhwCSYOrbXX5Fm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%y8>bqj;1MJ4( z%18~pY1y4;9M%)Pi|&%UXVl9Z*_l}%$MejYp#WOuCpK3gm}R?rdT2!`jm-7&Xg;dw z+Bd?clMA}^QB-MwOj#gvy?qsnUSMEIX*bkkU za~*eL-LrJOwt}L(nZ3R^U(YVG^{0>L+A;a@6_pD=zQWy(tN<46 amtPAIx{1pb2)ap}e7-!ry*w3vhW`O#OHJee diff --git a/common/src/proto/komp_ac.auth.rs b/common/src/proto/komp_ac.auth.rs index dbe9376..22bd686 100644 --- a/common/src/proto/komp_ac.auth.rs +++ b/common/src/proto/komp_ac.auth.rs @@ -35,7 +35,7 @@ pub struct LoginRequest { #[prost(string, tag = "2")] pub password: ::prost::alloc::string::String, } -#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct LoginResponse { /// JWT token #[prost(string, tag = "1")] @@ -54,6 +54,24 @@ pub struct LoginResponse { pub role: ::prost::alloc::string::String, #[prost(string, tag = "6")] pub username: ::prost::alloc::string::String, + #[prost(message, optional, tag = "7")] + pub authorization: ::core::option::Option, +} +#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)] +pub struct GetAuthorizationRequest {} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct Permission { + #[prost(string, tag = "1")] + pub resource: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub action: ::prost::alloc::string::String, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct AuthorizationSnapshot { + #[prost(string, tag = "1")] + pub role: ::prost::alloc::string::String, + #[prost(message, repeated, tag = "2")] + pub permissions: ::prost::alloc::vec::Vec, } /// Generated client implementations. pub mod auth_service_client { @@ -188,6 +206,30 @@ pub mod auth_service_client { .insert(GrpcMethod::new("komp_ac.auth.AuthService", "Login")); self.inner.unary(req, path, codec).await } + pub async fn get_authorization( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + 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/GetAuthorization", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("komp_ac.auth.AuthService", "GetAuthorization")); + self.inner.unary(req, path, codec).await + } } } /// Generated server implementations. @@ -211,6 +253,13 @@ pub mod auth_service_server { &self, request: tonic::Request, ) -> std::result::Result, tonic::Status>; + async fn get_authorization( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; } #[derive(Debug)] pub struct AuthServiceServer { @@ -376,6 +425,51 @@ pub mod auth_service_server { }; Box::pin(fut) } + "/komp_ac.auth.AuthService/GetAuthorization" => { + #[allow(non_camel_case_types)] + struct GetAuthorizationSvc(pub Arc); + impl< + T: AuthService, + > tonic::server::UnaryService + for GetAuthorizationSvc { + type Response = super::AuthorizationSnapshot; + 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_authorization(&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 = GetAuthorizationSvc(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) + } _ => { Box::pin(async move { let mut response = http::Response::new(