From 06b8e19805fff6d3c3fad0cf1f3329d606242fd4 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Fri, 4 Nov 2022 17:25:17 +0100 Subject: [PATCH] Fix all compile errors except 'user' --- bffhd/capnp/authenticationsystem.rs | 14 +- bffhd/capnp/machine.rs | 362 ---------------------------- bffhd/capnp/machinesystem.rs | 99 +------- bffhd/capnp/permissionsystem.rs | 24 +- bffhd/capnp/session.rs | 20 +- bffhd/capnp/user.rs | 71 ++---- bffhd/capnp/user_system.rs | 80 ++---- bffhd/utils/uuid.rs | 10 +- 8 files changed, 58 insertions(+), 622 deletions(-) diff --git a/bffhd/capnp/authenticationsystem.rs b/bffhd/capnp/authenticationsystem.rs index 96b2b08..9ff1737 100644 --- a/bffhd/capnp/authenticationsystem.rs +++ b/bffhd/capnp/authenticationsystem.rs @@ -15,7 +15,7 @@ use crate::session::SessionManager; use api::auth_capnp::authentication::{ AbortParams, AbortResults, Server as AuthenticationSystem, StepParams, StepResults, }; -use api::auth_capnp::{response, response::Error as ErrorCode}; +use api::auth_capnp::response::{self, Reason, Action}; use crate::authentication::V; const TARGET: &str = "bffh::api::authenticationsystem"; @@ -67,11 +67,11 @@ impl Authentication { return; } - let mut builder = response.init_failed(); + let mut builder = response.init_error(); match self.state { - State::InvalidMechanism => builder.set_code(ErrorCode::BadMechanism), - State::Finished => builder.set_code(ErrorCode::Aborted), - State::Aborted => builder.set_code(ErrorCode::Aborted), + State::InvalidMechanism => builder.set_reason(Reason::BadMechanism), + State::Finished => builder.set_reason(Reason::Aborted), + State::Aborted => builder.set_reason(Reason::Aborted), _ => unreachable!(), } } @@ -141,8 +141,8 @@ impl AuthenticationSystem for Authentication { APISession::build(session, builder) } else { - let mut builder = builder.init_failed(); - builder.set_code(ErrorCode::InvalidCredentials); + let mut builder = builder.init_error(); + builder.set_reason(Reason::InvalidCredentials); response = Response { union_field: "error", diff --git a/bffhd/capnp/machine.rs b/bffhd/capnp/machine.rs index a4fc534..0b74d63 100644 --- a/bffhd/capnp/machine.rs +++ b/bffhd/capnp/machine.rs @@ -2,11 +2,6 @@ use crate::capnp::user::User; use crate::resources::modules::fabaccess::{ArchivedStatus, Status}; use crate::resources::Resource; use crate::session::SessionHandle; -use api::resource_capnp::resource::{ - self, admin, admin::Server as AdminServer, check, check::Server as CheckServer, - in_use as inuse, in_use::Server as InUseServer, info, info::Server as InfoServer, manage, - manage::Server as ManageServer, use_, use_::Server as UseServer, MachineState, -}; use capnp::capability::Promise; use capnp_rpc::pry; @@ -15,360 +10,3 @@ pub struct Machine { session: SessionHandle, resource: Resource, } - -impl Machine { - pub fn new(session: SessionHandle, resource: Resource) -> Self { - Self { session, resource } - } - - pub fn build_into(self, mut builder: resource::Builder) { - builder.set_id(self.resource.get_id()); - builder.set_name(self.resource.get_name()); - if let Some(ref desc) = self.resource.get_description().description { - builder.set_description(desc); - } - if let Some(ref wiki) = self.resource.get_description().wiki { - builder.set_wiki(wiki); - } - if let Some(ref category) = self.resource.get_description().category { - builder.set_category(category); - } - builder.set_urn(&format!( - "urn:fabaccess:resource:{}", - self.resource.get_id() - )); - - { - let user = self.session.get_user_ref(); - let state = self.resource.get_state_ref(); - let state = state.as_ref(); - - if self.session.has_write(&self.resource) - && match &state.inner.state { - ArchivedStatus::Free => true, - ArchivedStatus::Reserved(reserver) if reserver == &user => true, - _ => false, - } - { - builder.set_use(capnp_rpc::new_client(self.clone())); - } - - if self.session.has_manage(&self.resource) { - builder.set_manage(capnp_rpc::new_client(self.clone())); - } - - // TODO: admin perm - - let s = match &state.inner.state { - ArchivedStatus::Free => MachineState::Free, - ArchivedStatus::Disabled => MachineState::Disabled, - ArchivedStatus::Blocked(_) => MachineState::Blocked, - ArchivedStatus::InUse(owner) => { - if owner == &user { - builder.set_inuse(capnp_rpc::new_client(self.clone())); - } - MachineState::InUse - } - ArchivedStatus::Reserved(_) => MachineState::Reserved, - ArchivedStatus::ToCheck(_) => MachineState::ToCheck, - }; - if self.session.has_read(&self.resource) { - builder.set_state(s); - } - } - - builder.set_info(capnp_rpc::new_client(self)); - } - - /// Builds a machine into the given builder. Re - pub fn build(session: SessionHandle, resource: Resource, builder: machine::Builder) { - let this = Self::new(session.clone(), resource.clone()); - this.build_into(builder) - } - - pub fn optional_build( - session: SessionHandle, - resource: Resource, - builder: optional::Builder, - ) { - let this = Self::new(session.clone(), resource.clone()); - if this.resource.visible(&session) || session.has_read(&resource) { - let builder = builder.init_just(); - this.build_into(builder); - } - } -} - -impl InfoServer for Machine { - fn get_property_list( - &mut self, - _: info::GetPropertyListParams, - _: info::GetPropertyListResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - fn get_reservation_list( - &mut self, - _: info::GetReservationListParams, - _: info::GetReservationListResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } -} - -impl UseServer for Machine { - fn use_(&mut self, _: use_::UseParams, _: use_::UseResults) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let session = self.session.clone(); - Promise::from_future(async move { - let user = session.get_user_ref(); - resource.try_update(session, Status::InUse(user)).await; - Ok(()) - }) - } - - fn reserve( - &mut self, - _: use_::ReserveParams, - _: use_::ReserveResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let session = self.session.clone(); - Promise::from_future(async move { - let user = session.get_user_ref(); - resource.try_update(session, Status::Reserved(user)).await; - Ok(()) - }) - } - - fn reserveto( - &mut self, - _: use_::ReservetoParams, - _: use_::ReservetoResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } -} - -impl InUseServer for Machine { - fn give_back( - &mut self, - _: inuse::GiveBackParams, - _: inuse::GiveBackResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let session = self.session.clone(); - Promise::from_future(async move { - resource.give_back(session.clone()).await; - Ok(()) - }) - } - - fn send_raw_data( - &mut self, - _: inuse::SendRawDataParams, - _: inuse::SendRawDataResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } -} - -impl CheckServer for Machine { - fn check( - &mut self, - _: check::CheckParams, - _: check::CheckResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - - fn reject( - &mut self, - _: check::RejectParams, - _: check::RejectResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } -} - -impl ManageServer for Machine { - fn get_machine_info_extended( - &mut self, - _: manage::GetMachineInfoExtendedParams, - mut result: manage::GetMachineInfoExtendedResults, - ) -> Promise<(), ::capnp::Error> { - let mut builder = result.get(); - let user = User::new_self(self.session.clone()); - User::build_optional( - &self.session, - self.resource.get_current_user(), - builder.reborrow().init_current_user(), - ); - User::build_optional( - &self.session, - self.resource.get_previous_user(), - builder.init_last_user(), - ); - Promise::ok(()) - } - fn set_property( - &mut self, - _: manage::SetPropertyParams, - _: manage::SetPropertyResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - fn remove_property( - &mut self, - _: manage::RemovePropertyParams, - _: manage::RemovePropertyResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - - fn force_use( - &mut self, - _: manage::ForceUseParams, - _: manage::ForceUseResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let session = self.session.clone(); - Promise::from_future(async move { - resource - .force_set(Status::InUse(session.get_user_ref())) - .await; - Ok(()) - }) - } - - fn force_free( - &mut self, - _: manage::ForceFreeParams, - _: manage::ForceFreeResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let _session = self.session.clone(); - Promise::from_future(async move { - resource.force_set(Status::Free).await; - Ok(()) - }) - } - fn force_transfer( - &mut self, - _: manage::ForceTransferParams, - _: manage::ForceTransferResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - - fn block( - &mut self, - _: manage::BlockParams, - _: manage::BlockResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - let session = self.session.clone(); - Promise::from_future(async move { - resource - .force_set(Status::Blocked(session.get_user_ref())) - .await; - Ok(()) - }) - } - fn disabled( - &mut self, - _: manage::DisabledParams, - _: manage::DisabledResults, - ) -> Promise<(), ::capnp::Error> { - let resource = self.resource.clone(); - Promise::from_future(async move { - resource.force_set(Status::Disabled).await; - Ok(()) - }) - } -} - -impl AdminServer for Machine { - fn force_set_state( - &mut self, - params: admin::ForceSetStateParams, - _: admin::ForceSetStateResults, - ) -> Promise<(), ::capnp::Error> { - use api::schema::resource_capnp::resource::MachineState as APIMState; - let user = self.session.get_user_ref(); - let state = match pry!(pry!(params.get()).get_state()) { - APIMState::Free => Status::Free, - APIMState::Blocked => Status::Blocked(user), - APIMState::Disabled => Status::Disabled, - APIMState::InUse => Status::InUse(user), - APIMState::Reserved => Status::Reserved(user), - APIMState::ToCheck => Status::ToCheck(user), - APIMState::Totakeover => { - return Promise::err(::capnp::Error::unimplemented( - "totakeover not implemented".to_string(), - )) - } - }; - let resource = self.resource.clone(); - Promise::from_future(async move { - resource.force_set(state).await; - Ok(()) - }) - } - - fn force_set_user( - &mut self, - _: admin::ForceSetUserParams, - _: admin::ForceSetUserResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - - fn get_admin_property_list( - &mut self, - _: admin::GetAdminPropertyListParams, - _: admin::GetAdminPropertyListResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - fn set_admin_property( - &mut self, - _: admin::SetAdminPropertyParams, - _: admin::SetAdminPropertyResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } - fn remove_admin_property( - &mut self, - _: admin::RemoveAdminPropertyParams, - _: admin::RemoveAdminPropertyResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } -} diff --git a/bffhd/capnp/machinesystem.rs b/bffhd/capnp/machinesystem.rs index fad4240..43cea99 100644 --- a/bffhd/capnp/machinesystem.rs +++ b/bffhd/capnp/machinesystem.rs @@ -3,7 +3,7 @@ use crate::resources::search::ResourcesHandle; use crate::resources::Resource; use crate::session::SessionHandle; use crate::RESOURCES; -use api::machinesystem_capnp::machine_system::info; +use api::resources_capnp::resources; use capnp::capability::Promise; use capnp_rpc::pry; use tracing::Span; @@ -33,101 +33,6 @@ impl Machines { } } -impl info::Server for Machines { - fn get_machine_list( - &mut self, - _: info::GetMachineListParams, - mut result: info::GetMachineListResults, - ) -> Promise<(), ::capnp::Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!( - target: TARGET, - parent: &self.span, - "getMachineList", - ) - .entered(); +impl resources::Server for Machines { - tracing::trace!("method call"); - - let machine_list: Vec<(usize, &Resource)> = self - .resources - .list_all() - .into_iter() - .filter(|resource| resource.visible(&self.session)) - .enumerate() - .collect(); - let mut builder = result.get().init_machine_list(machine_list.len() as u32); - for (i, m) in machine_list { - let resource = m.clone(); - let mbuilder = builder.reborrow().get(i as u32); - Machine::build(self.session.clone(), resource, mbuilder); - } - - // TODO: indicate result? - tracing::trace!("method return"); - - Promise::ok(()) - } - - fn get_machine( - &mut self, - params: info::GetMachineParams, - mut result: info::GetMachineResults, - ) -> Promise<(), ::capnp::Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!( - target: TARGET, - parent: &self.span, - "getMachine", - ) - .entered(); - - let params = pry!(params.get()); - let id = pry!(params.get_id()); - - tracing::trace!(params.id = id, "method call"); - - if let Some(resource) = self.resources.get_by_id(id) { - tracing::trace!(results = "Just", results.inner = id, "method return"); - let builder = result.get(); - Machine::optional_build(self.session.clone(), resource.clone(), builder); - } else { - tracing::trace!(results = "Nothing", "method return"); - } - - Promise::ok(()) - } - - fn get_machine_u_r_n( - &mut self, - params: info::GetMachineURNParams, - mut result: info::GetMachineURNResults, - ) -> Promise<(), ::capnp::Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!( - target: TARGET, - parent: &self.span, - "getMachineURN", - ) - .entered(); - - let params = pry!(params.get()); - let urn = pry!(params.get_urn()); - - tracing::trace!(params.urn = urn, "method call"); - - if let Some(resource) = self.resources.get_by_urn(urn) { - tracing::trace!( - results = "Just", - results.inner = resource.get_id(), - "method return" - ); - let builder = result.get(); - Machine::optional_build(self.session.clone(), resource.clone(), builder); - } else { - tracing::trace!(results = "Nothing", "method return"); - } - - Promise::ok(()) - } } diff --git a/bffhd/capnp/permissionsystem.rs b/bffhd/capnp/permissionsystem.rs index 6e8eac3..13c47aa 100644 --- a/bffhd/capnp/permissionsystem.rs +++ b/bffhd/capnp/permissionsystem.rs @@ -1,7 +1,7 @@ use crate::authorization::roles::Role; use crate::Roles; -use api::permissionsystem_capnp::permission_system::info::{ - GetRoleListParams, GetRoleListResults, Server as PermissionSystem, +use api::permissions_capnp::permissions::{ + self, ListRolesParams, ListRolesResults, }; use capnp::capability::Promise; use capnp::Error; @@ -26,24 +26,6 @@ impl Permissions { } } -impl PermissionSystem for Permissions { - fn get_role_list( - &mut self, - _: GetRoleListParams, - mut results: GetRoleListResults, - ) -> Promise<(), Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "getRoleList",).entered(); +impl permissions::Server for Permissions { - tracing::trace!("method call"); - let roles = self.roles.list().collect::>(); - let mut builder = results.get(); - let mut b = builder.init_role_list(roles.len() as u32); - for (i, role) in roles.into_iter().enumerate() { - let mut role_builder = b.reborrow().get(i as u32); - role_builder.set_name(role); - } - tracing::trace!("method return"); - Promise::ok(()) - } } diff --git a/bffhd/capnp/session.rs b/bffhd/capnp/session.rs index 11a34da..3e3cf37 100644 --- a/bffhd/capnp/session.rs +++ b/bffhd/capnp/session.rs @@ -1,5 +1,5 @@ use crate::authorization::permissions::Permission; -use api::authenticationsystem_capnp::response::successful::Builder; +use api::auth_capnp::response::successful::Builder; use crate::capnp::machinesystem::Machines; use crate::capnp::permissionsystem::Permissions; @@ -17,24 +17,14 @@ impl APISession { pub fn build(session: SessionHandle, builder: Builder) { let mut builder = builder.init_session(); - { - let mut b = builder.reborrow().init_machine_system(); - b.set_info(capnp_rpc::new_client(Machines::new(session.clone()))); - } + builder.reborrow().set_resources(capnp_rpc::new_client(Machines::new(session.clone()))); + if session.has_perm(Permission::new("bffh.users.manage")) { - let mut b = builder.reborrow().init_user_system(); let u = Users::new(session.clone()); - if session.has_perm(Permission::new("bffh.users.manage")) { - b.set_manage(capnp_rpc::new_client(u.clone())); - b.set_search(capnp_rpc::new_client(u.clone())); - } - b.set_info(capnp_rpc::new_client(u)); + builder.reborrow().set_users(capnp_rpc::new_client(u.clone())); } - { - let mut b = builder.init_permission_system(); - b.set_info(capnp_rpc::new_client(Permissions::new(session))); - } + builder.set_permissions(capnp_rpc::new_client(Permissions::new(session))); } } diff --git a/bffhd/capnp/user.rs b/bffhd/capnp/user.rs index 4333a86..7863629 100644 --- a/bffhd/capnp/user.rs +++ b/bffhd/capnp/user.rs @@ -1,8 +1,7 @@ use crate::authorization::permissions::Permission; use crate::session::SessionHandle; use crate::users::{db, UserRef}; -use api::general_capnp::optional; -use api::user_capnp::user::{self, admin, info, manage}; +use api::user_capnp::user::{self, self_service, manage, admin}; use capnp::capability::Promise; use capnp_rpc::pry; @@ -22,24 +21,13 @@ impl User { Self::new(session, user) } - pub fn build_optional( - session: &SessionHandle, - user: Option, - builder: optional::Builder, - ) { - if let Some(user) = user.and_then(|u| session.users.get_user(u.get_username())) { - let builder = builder.init_just(); - Self::fill(&session, user, builder); - } - } - pub fn build(session: SessionHandle, builder: user::Builder) { let this = Self::new_self(session); let user = this.session.get_user(); Self::fill(&this.session, user, builder); } - pub fn fill(session: &SessionHandle, user: db::User, mut builder: user::Builder) { + pub fn fill(session: &SessionHandle, user: db::User) -> Self { builder.set_username(user.id.as_str()); // We have permissions on ourself @@ -59,11 +47,11 @@ impl User { } } -impl info::Server for User { - fn list_roles( +impl user::Server for User { + fn roles( &mut self, - _: info::ListRolesParams, - mut result: info::ListRolesResults, + _: user::RolesParams, + mut result: user::RolesResults, ) -> Promise<(), ::capnp::Error> { if let Some(user) = self.session.users.get_user(self.user.get_username()) { let mut builder = result.get().init_roles(user.userdata.roles.len() as u32); @@ -77,40 +65,10 @@ impl info::Server for User { } impl manage::Server for User { - fn pwd( - &mut self, - params: manage::PwdParams, - _results: manage::PwdResults, - ) -> Promise<(), ::capnp::Error> { - let params = pry!(params.get()); - let old_pw = pry!(params.get_old_pwd()); - let new_pw = pry!(params.get_new_pwd()); - - let uid = self.user.get_username(); - if let Some(mut user) = self.session.users.get_user(uid) { - if let Ok(true) = user.check_password(old_pw.as_bytes()) { - user.set_pw(new_pw.as_bytes()); - self.session.users.put_user(uid, &user); - } - } - Promise::ok(()) - } -} - -impl admin::Server for User { - fn get_user_info_extended( - &mut self, - _: admin::GetUserInfoExtendedParams, - _: admin::GetUserInfoExtendedResults, - ) -> Promise<(), ::capnp::Error> { - Promise::err(::capnp::Error::unimplemented( - "method not implemented".to_string(), - )) - } fn add_role( &mut self, - param: admin::AddRoleParams, - _: admin::AddRoleResults, + param: manage::AddRoleParams, + _: manage::AddRoleResults, ) -> Promise<(), ::capnp::Error> { let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name()); @@ -134,8 +92,8 @@ impl admin::Server for User { } fn remove_role( &mut self, - param: admin::RemoveRoleParams, - _: admin::RemoveRoleResults, + param: manage::RemoveRoleParams, + _: manage::RemoveRoleResults, ) -> Promise<(), ::capnp::Error> { let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name()); @@ -157,10 +115,13 @@ impl admin::Server for User { Promise::ok(()) } - fn pwd( +} + +impl admin::Server for User { + fn setpw( &mut self, - param: admin::PwdParams, - _: admin::PwdResults, + param: admin::SetpwParams, + _: admin::SetpwResults, ) -> Promise<(), ::capnp::Error> { let new_pw = pry!(pry!(param.get()).get_new_pwd()); let uid = self.user.get_username(); diff --git a/bffhd/capnp/user_system.rs b/bffhd/capnp/user_system.rs index 2d40a44..ec856ef 100644 --- a/bffhd/capnp/user_system.rs +++ b/bffhd/capnp/user_system.rs @@ -1,4 +1,4 @@ -use api::usersystem_capnp::user_system::{info, manage, search}; +use api::users_capnp::users; use capnp::capability::Promise; use capnp_rpc::pry; use tracing::Span; @@ -23,29 +23,11 @@ impl Users { } } -impl info::Server for Users { - fn get_user_self( +impl users::Server for Users { + fn list( &mut self, - _: info::GetUserSelfParams, - mut result: info::GetUserSelfResults, - ) -> Promise<(), ::capnp::Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "getUserSelf").entered(); - tracing::trace!("method call"); - - let builder = result.get(); - User::build(self.session.clone(), builder); - - tracing::trace!("method return"); - Promise::ok(()) - } -} - -impl manage::Server for Users { - fn get_user_list( - &mut self, - _: manage::GetUserListParams, - mut result: manage::GetUserListResults, + _: users::ListParams, + mut result: users::ListResults, ) -> Promise<(), ::capnp::Error> { let _guard = self.span.enter(); let _span = tracing::trace_span!(target: TARGET, "getUserList",).entered(); @@ -55,20 +37,20 @@ impl manage::Server for Users { let users = pry!(userdb .get_all() .map_err(|e| capnp::Error::failed(format!("UserDB error: {:?}", e)))); - let mut builder = result.get().init_user_list(users.len() as u32); + let mut builder = result.get().init_users(users.len() as u32); for (i, (id, userdata)) in users.into_iter().enumerate() { let user = db::User { id, userdata }; - User::fill(&self.session, user, builder.reborrow().get(i as u32)); + builder.reborrow().set(i as u32, User::fill(&self.session, user)); } tracing::trace!("method return"); Promise::ok(()) } - fn add_user_fallible( + fn add_user( &mut self, - params: manage::AddUserFallibleParams, - mut result: manage::AddUserFallibleResults, + params: users::AddUserParams, + mut result: users::AddUserResults, ) -> Promise<(), ::capnp::Error> { let _guard = self.span.enter(); let _span = tracing::trace_span!(target: TARGET, "addUserFallible").entered(); @@ -90,21 +72,20 @@ impl manage::Server for Users { if self.session.users.get_user(username).is_none() { let user = db::User::new_with_plain_pw(username, password); self.session.users.put_user(username, &user); - let mut builder = builder.init_successful(); - User::fill(&self.session, user, builder); + builder.set_user(capnp_rpc::new_client(User::fill(&self.session, user))); } else { - let mut builder = builder.init_failed(); - builder.set_error(manage::add_user_error::AddUserError::AlreadyExists); + let mut builder = builder.init_error(); + builder.set_exists(); tracing::warn!("Failed to add user: Username taken"); } } else { if username.is_empty() { - let mut builder = builder.init_failed(); - builder.set_error(manage::add_user_error::AddUserError::UsernameInvalid); + let mut builder = builder.init_error(); + builder.set_username_invalid(); tracing::warn!("Failed to add user: Username empty"); } else if password.is_empty() { - let mut builder = builder.init_failed(); - builder.set_error(manage::add_user_error::AddUserError::PasswordInvalid); + let mut builder = builder.init_error(); + builder.set_password_invalid(); tracing::warn!("Failed to add user: Password empty"); } } @@ -115,8 +96,8 @@ impl manage::Server for Users { fn remove_user( &mut self, - params: manage::RemoveUserParams, - _: manage::RemoveUserResults, + params: users::RemoveUserParams, + _: users::RemoveUserResults, ) -> Promise<(), ::capnp::Error> { let _guard = self.span.enter(); let _span = tracing::trace_span!(target: TARGET, "removeUser",).entered(); @@ -134,25 +115,4 @@ impl manage::Server for Users { tracing::trace!("method return"); Promise::ok(()) } -} - -impl search::Server for Users { - fn get_user_by_name( - &mut self, - params: search::GetUserByNameParams, - mut result: search::GetUserByNameResults, - ) -> Promise<(), ::capnp::Error> { - let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "getUserByName",).entered(); - - let username: &str = pry!(pry!(params.get()).get_username()); - - tracing::trace!(params.username = username, "method call"); - - let userref = UserRef::new(username.to_string()); - User::build_optional(&self.session, Some(userref), result.get()); - - tracing::trace!("method return"); - Promise::ok(()) - } -} +} \ No newline at end of file diff --git a/bffhd/utils/uuid.rs b/bffhd/utils/uuid.rs index e88a6d2..f209821 100644 --- a/bffhd/utils/uuid.rs +++ b/bffhd/utils/uuid.rs @@ -1,17 +1,17 @@ -use api::general_capnp::u_u_i_d::{Builder, Reader}; +use api::utils_capnp::u_u_i_d::{Builder, Reader}; use uuid::Uuid; pub fn uuid_to_api(uuid: Uuid, mut builder: Builder) { let [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = uuid.as_u128().to_ne_bytes(); let lower = u64::from_ne_bytes([a, b, c, d, e, f, g, h]); let upper = u64::from_ne_bytes([i, j, k, l, m, n, o, p]); - builder.set_uuid0(lower); - builder.set_uuid1(upper); + builder.set_lower(lower); + builder.set_upper(upper); } pub fn api_to_uuid(reader: Reader) -> Uuid { - let lower: u64 = reader.reborrow().get_uuid0(); - let upper: u64 = reader.get_uuid1(); + let lower: u64 = reader.reborrow().get_lower(); + let upper: u64 = reader.get_upper(); let [a, b, c, d, e, f, g, h] = lower.to_ne_bytes(); let [i, j, k, l, m, n, o, p] = upper.to_ne_bytes(); let num = u128::from_ne_bytes([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]);