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 af29160..b99ee32 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 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(