66 lines
1.7 KiB
Rust
Raw Normal View History

2020-11-17 14:35:16 +01:00
use std::sync::Arc;
2020-11-17 14:38:11 +01:00
use capnp::capability::{Params, Results, Promise};
2020-11-17 14:35:16 +01:00
use crate::schema::connection_capnp;
use crate::connection::Session;
2020-11-20 13:06:55 +01:00
use crate::db::Databases;
2020-12-15 13:12:22 +01:00
use crate::network::Network;
2020-11-17 14:35:16 +01:00
pub mod auth;
2020-11-17 14:15:29 +01:00
mod machine;
mod machines;
2020-11-17 14:35:16 +01:00
use machines::Machines;
2020-12-09 18:44:52 +01:00
// TODO Session restoration by making the Bootstrap cap a SturdyRef
2020-11-17 14:35:16 +01:00
pub struct Bootstrap {
2020-11-20 13:06:55 +01:00
session: Arc<Session>,
db: Databases,
2020-12-15 13:12:22 +01:00
nw: Arc<Network>,
2020-11-17 14:35:16 +01:00
}
impl Bootstrap {
2020-12-15 13:12:22 +01:00
pub fn new(session: Arc<Session>, db: Databases, nw: Arc<Network>) -> Self {
info!(session.log, "Created Bootstrap");
2020-12-15 13:12:22 +01:00
Self { session, db, nw }
2020-11-17 14:35:16 +01:00
}
}
use connection_capnp::bootstrap::*;
impl connection_capnp::bootstrap::Server for Bootstrap {
fn auth(&mut self,
_: Params<auth_params::Owned>,
mut res: Results<auth_results::Owned>
) -> Promise<(), capnp::Error> {
2020-12-09 18:44:52 +01:00
// TODO: Forbid mutltiple authentication for now
2020-11-17 14:35:16 +01:00
// TODO: When should we allow multiple auth and how do me make sure that does not leak
// priviledges (e.g. due to previously issues caps)?
2020-11-24 15:57:23 +01:00
2021-02-09 17:15:31 +00:00
res.get().set_auth(capnp_rpc::new_client(auth::Auth::new(self.db.clone(), self.session.clone())));
2020-11-24 15:57:23 +01:00
Promise::ok(())
2020-11-17 14:35:16 +01:00
}
fn permissions(&mut self,
_: Params<permissions_params::Owned>,
2020-11-17 14:38:11 +01:00
_: Results<permissions_results::Owned>
2020-11-17 14:35:16 +01:00
) -> Promise<(), capnp::Error> {
Promise::ok(())
}
fn machines(&mut self,
_: Params<machines_params::Owned>,
mut res: Results<machines_results::Owned>
) -> Promise<(), capnp::Error> {
// TODO actual permission check and stuff
2020-12-15 13:12:22 +01:00
let c = capnp_rpc::new_client(Machines::new(self.session.clone(), self.db.clone(), self.nw.clone()));
2020-11-20 15:43:03 +01:00
res.get().set_machines(c);
2020-11-17 14:35:16 +01:00
Promise::ok(())
}
}