mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-23 23:27:57 +01:00
Fix all compile errors except 'user'
This commit is contained in:
parent
47ed3b1e4c
commit
06b8e19805
@ -15,7 +15,7 @@ use crate::session::SessionManager;
|
|||||||
use api::auth_capnp::authentication::{
|
use api::auth_capnp::authentication::{
|
||||||
AbortParams, AbortResults, Server as AuthenticationSystem, StepParams, StepResults,
|
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;
|
use crate::authentication::V;
|
||||||
|
|
||||||
const TARGET: &str = "bffh::api::authenticationsystem";
|
const TARGET: &str = "bffh::api::authenticationsystem";
|
||||||
@ -67,11 +67,11 @@ impl Authentication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut builder = response.init_failed();
|
let mut builder = response.init_error();
|
||||||
match self.state {
|
match self.state {
|
||||||
State::InvalidMechanism => builder.set_code(ErrorCode::BadMechanism),
|
State::InvalidMechanism => builder.set_reason(Reason::BadMechanism),
|
||||||
State::Finished => builder.set_code(ErrorCode::Aborted),
|
State::Finished => builder.set_reason(Reason::Aborted),
|
||||||
State::Aborted => builder.set_code(ErrorCode::Aborted),
|
State::Aborted => builder.set_reason(Reason::Aborted),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,8 +141,8 @@ impl AuthenticationSystem for Authentication {
|
|||||||
|
|
||||||
APISession::build(session, builder)
|
APISession::build(session, builder)
|
||||||
} else {
|
} else {
|
||||||
let mut builder = builder.init_failed();
|
let mut builder = builder.init_error();
|
||||||
builder.set_code(ErrorCode::InvalidCredentials);
|
builder.set_reason(Reason::InvalidCredentials);
|
||||||
|
|
||||||
response = Response {
|
response = Response {
|
||||||
union_field: "error",
|
union_field: "error",
|
||||||
|
@ -2,11 +2,6 @@ use crate::capnp::user::User;
|
|||||||
use crate::resources::modules::fabaccess::{ArchivedStatus, Status};
|
use crate::resources::modules::fabaccess::{ArchivedStatus, Status};
|
||||||
use crate::resources::Resource;
|
use crate::resources::Resource;
|
||||||
use crate::session::SessionHandle;
|
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::capability::Promise;
|
||||||
use capnp_rpc::pry;
|
use capnp_rpc::pry;
|
||||||
|
|
||||||
@ -15,360 +10,3 @@ pub struct Machine {
|
|||||||
session: SessionHandle,
|
session: SessionHandle,
|
||||||
resource: Resource,
|
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<machine::Owned>,
|
|
||||||
) {
|
|
||||||
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(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@ use crate::resources::search::ResourcesHandle;
|
|||||||
use crate::resources::Resource;
|
use crate::resources::Resource;
|
||||||
use crate::session::SessionHandle;
|
use crate::session::SessionHandle;
|
||||||
use crate::RESOURCES;
|
use crate::RESOURCES;
|
||||||
use api::machinesystem_capnp::machine_system::info;
|
use api::resources_capnp::resources;
|
||||||
use capnp::capability::Promise;
|
use capnp::capability::Promise;
|
||||||
use capnp_rpc::pry;
|
use capnp_rpc::pry;
|
||||||
use tracing::Span;
|
use tracing::Span;
|
||||||
@ -33,101 +33,6 @@ impl Machines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl info::Server for Machines {
|
impl resources::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();
|
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::authorization::roles::Role;
|
use crate::authorization::roles::Role;
|
||||||
use crate::Roles;
|
use crate::Roles;
|
||||||
use api::permissionsystem_capnp::permission_system::info::{
|
use api::permissions_capnp::permissions::{
|
||||||
GetRoleListParams, GetRoleListResults, Server as PermissionSystem,
|
self, ListRolesParams, ListRolesResults,
|
||||||
};
|
};
|
||||||
use capnp::capability::Promise;
|
use capnp::capability::Promise;
|
||||||
use capnp::Error;
|
use capnp::Error;
|
||||||
@ -26,24 +26,6 @@ impl Permissions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PermissionSystem for Permissions {
|
impl permissions::Server 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();
|
|
||||||
|
|
||||||
tracing::trace!("method call");
|
|
||||||
let roles = self.roles.list().collect::<Vec<&String>>();
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::authorization::permissions::Permission;
|
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::machinesystem::Machines;
|
||||||
use crate::capnp::permissionsystem::Permissions;
|
use crate::capnp::permissionsystem::Permissions;
|
||||||
@ -17,24 +17,14 @@ impl APISession {
|
|||||||
pub fn build(session: SessionHandle, builder: Builder) {
|
pub fn build(session: SessionHandle, builder: Builder) {
|
||||||
let mut builder = builder.init_session();
|
let mut builder = builder.init_session();
|
||||||
|
|
||||||
{
|
builder.reborrow().set_resources(capnp_rpc::new_client(Machines::new(session.clone())));
|
||||||
let mut b = builder.reborrow().init_machine_system();
|
|
||||||
b.set_info(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());
|
let u = Users::new(session.clone());
|
||||||
if session.has_perm(Permission::new("bffh.users.manage")) {
|
builder.reborrow().set_users(capnp_rpc::new_client(u.clone()));
|
||||||
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.set_permissions(capnp_rpc::new_client(Permissions::new(session)));
|
||||||
let mut b = builder.init_permission_system();
|
|
||||||
b.set_info(capnp_rpc::new_client(Permissions::new(session)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use crate::authorization::permissions::Permission;
|
use crate::authorization::permissions::Permission;
|
||||||
use crate::session::SessionHandle;
|
use crate::session::SessionHandle;
|
||||||
use crate::users::{db, UserRef};
|
use crate::users::{db, UserRef};
|
||||||
use api::general_capnp::optional;
|
use api::user_capnp::user::{self, self_service, manage, admin};
|
||||||
use api::user_capnp::user::{self, admin, info, manage};
|
|
||||||
use capnp::capability::Promise;
|
use capnp::capability::Promise;
|
||||||
use capnp_rpc::pry;
|
use capnp_rpc::pry;
|
||||||
|
|
||||||
@ -22,24 +21,13 @@ impl User {
|
|||||||
Self::new(session, user)
|
Self::new(session, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_optional(
|
|
||||||
session: &SessionHandle,
|
|
||||||
user: Option<UserRef>,
|
|
||||||
builder: optional::Builder<user::Owned>,
|
|
||||||
) {
|
|
||||||
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) {
|
pub fn build(session: SessionHandle, builder: user::Builder) {
|
||||||
let this = Self::new_self(session);
|
let this = Self::new_self(session);
|
||||||
let user = this.session.get_user();
|
let user = this.session.get_user();
|
||||||
Self::fill(&this.session, user, builder);
|
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());
|
builder.set_username(user.id.as_str());
|
||||||
|
|
||||||
// We have permissions on ourself
|
// We have permissions on ourself
|
||||||
@ -59,11 +47,11 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl info::Server for User {
|
impl user::Server for User {
|
||||||
fn list_roles(
|
fn roles(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: info::ListRolesParams,
|
_: user::RolesParams,
|
||||||
mut result: info::ListRolesResults,
|
mut result: user::RolesResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
if let Some(user) = self.session.users.get_user(self.user.get_username()) {
|
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);
|
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 {
|
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(
|
fn add_role(
|
||||||
&mut self,
|
&mut self,
|
||||||
param: admin::AddRoleParams,
|
param: manage::AddRoleParams,
|
||||||
_: admin::AddRoleResults,
|
_: manage::AddRoleResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name());
|
let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name());
|
||||||
|
|
||||||
@ -134,8 +92,8 @@ impl admin::Server for User {
|
|||||||
}
|
}
|
||||||
fn remove_role(
|
fn remove_role(
|
||||||
&mut self,
|
&mut self,
|
||||||
param: admin::RemoveRoleParams,
|
param: manage::RemoveRoleParams,
|
||||||
_: admin::RemoveRoleResults,
|
_: manage::RemoveRoleResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name());
|
let rolename = pry!(pry!(pry!(param.get()).get_role()).get_name());
|
||||||
|
|
||||||
@ -157,10 +115,13 @@ impl admin::Server for User {
|
|||||||
|
|
||||||
Promise::ok(())
|
Promise::ok(())
|
||||||
}
|
}
|
||||||
fn pwd(
|
}
|
||||||
|
|
||||||
|
impl admin::Server for User {
|
||||||
|
fn setpw(
|
||||||
&mut self,
|
&mut self,
|
||||||
param: admin::PwdParams,
|
param: admin::SetpwParams,
|
||||||
_: admin::PwdResults,
|
_: admin::SetpwResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let new_pw = pry!(pry!(param.get()).get_new_pwd());
|
let new_pw = pry!(pry!(param.get()).get_new_pwd());
|
||||||
let uid = self.user.get_username();
|
let uid = self.user.get_username();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use api::usersystem_capnp::user_system::{info, manage, search};
|
use api::users_capnp::users;
|
||||||
use capnp::capability::Promise;
|
use capnp::capability::Promise;
|
||||||
use capnp_rpc::pry;
|
use capnp_rpc::pry;
|
||||||
use tracing::Span;
|
use tracing::Span;
|
||||||
@ -23,29 +23,11 @@ impl Users {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl info::Server for Users {
|
impl users::Server for Users {
|
||||||
fn get_user_self(
|
fn list(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: info::GetUserSelfParams,
|
_: users::ListParams,
|
||||||
mut result: info::GetUserSelfResults,
|
mut result: users::ListResults,
|
||||||
) -> 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,
|
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let _guard = self.span.enter();
|
let _guard = self.span.enter();
|
||||||
let _span = tracing::trace_span!(target: TARGET, "getUserList",).entered();
|
let _span = tracing::trace_span!(target: TARGET, "getUserList",).entered();
|
||||||
@ -55,20 +37,20 @@ impl manage::Server for Users {
|
|||||||
let users = pry!(userdb
|
let users = pry!(userdb
|
||||||
.get_all()
|
.get_all()
|
||||||
.map_err(|e| capnp::Error::failed(format!("UserDB error: {:?}", e))));
|
.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() {
|
for (i, (id, userdata)) in users.into_iter().enumerate() {
|
||||||
let user = db::User { id, userdata };
|
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");
|
tracing::trace!("method return");
|
||||||
Promise::ok(())
|
Promise::ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_user_fallible(
|
fn add_user(
|
||||||
&mut self,
|
&mut self,
|
||||||
params: manage::AddUserFallibleParams,
|
params: users::AddUserParams,
|
||||||
mut result: manage::AddUserFallibleResults,
|
mut result: users::AddUserResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let _guard = self.span.enter();
|
let _guard = self.span.enter();
|
||||||
let _span = tracing::trace_span!(target: TARGET, "addUserFallible").entered();
|
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() {
|
if self.session.users.get_user(username).is_none() {
|
||||||
let user = db::User::new_with_plain_pw(username, password);
|
let user = db::User::new_with_plain_pw(username, password);
|
||||||
self.session.users.put_user(username, &user);
|
self.session.users.put_user(username, &user);
|
||||||
let mut builder = builder.init_successful();
|
builder.set_user(capnp_rpc::new_client(User::fill(&self.session, user)));
|
||||||
User::fill(&self.session, user, builder);
|
|
||||||
} else {
|
} else {
|
||||||
let mut builder = builder.init_failed();
|
let mut builder = builder.init_error();
|
||||||
builder.set_error(manage::add_user_error::AddUserError::AlreadyExists);
|
builder.set_exists();
|
||||||
tracing::warn!("Failed to add user: Username taken");
|
tracing::warn!("Failed to add user: Username taken");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
let mut builder = builder.init_failed();
|
let mut builder = builder.init_error();
|
||||||
builder.set_error(manage::add_user_error::AddUserError::UsernameInvalid);
|
builder.set_username_invalid();
|
||||||
tracing::warn!("Failed to add user: Username empty");
|
tracing::warn!("Failed to add user: Username empty");
|
||||||
} else if password.is_empty() {
|
} else if password.is_empty() {
|
||||||
let mut builder = builder.init_failed();
|
let mut builder = builder.init_error();
|
||||||
builder.set_error(manage::add_user_error::AddUserError::PasswordInvalid);
|
builder.set_password_invalid();
|
||||||
tracing::warn!("Failed to add user: Password empty");
|
tracing::warn!("Failed to add user: Password empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,8 +96,8 @@ impl manage::Server for Users {
|
|||||||
|
|
||||||
fn remove_user(
|
fn remove_user(
|
||||||
&mut self,
|
&mut self,
|
||||||
params: manage::RemoveUserParams,
|
params: users::RemoveUserParams,
|
||||||
_: manage::RemoveUserResults,
|
_: users::RemoveUserResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let _guard = self.span.enter();
|
let _guard = self.span.enter();
|
||||||
let _span = tracing::trace_span!(target: TARGET, "removeUser",).entered();
|
let _span = tracing::trace_span!(target: TARGET, "removeUser",).entered();
|
||||||
@ -135,24 +116,3 @@ impl manage::Server for Users {
|
|||||||
Promise::ok(())
|
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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn uuid_to_api(uuid: Uuid, mut builder: Builder) {
|
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 [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 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]);
|
let upper = u64::from_ne_bytes([i, j, k, l, m, n, o, p]);
|
||||||
builder.set_uuid0(lower);
|
builder.set_lower(lower);
|
||||||
builder.set_uuid1(upper);
|
builder.set_upper(upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn api_to_uuid(reader: Reader) -> Uuid {
|
pub fn api_to_uuid(reader: Reader) -> Uuid {
|
||||||
let lower: u64 = reader.reborrow().get_uuid0();
|
let lower: u64 = reader.reborrow().get_lower();
|
||||||
let upper: u64 = reader.get_uuid1();
|
let upper: u64 = reader.get_upper();
|
||||||
let [a, b, c, d, e, f, g, h] = lower.to_ne_bytes();
|
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 [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]);
|
let num = u128::from_ne_bytes([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]);
|
||||||
|
Loading…
Reference in New Issue
Block a user