diff --git a/bffhd/capnp/user.rs b/bffhd/capnp/user.rs index f1ff084..4f6a6a4 100644 --- a/bffhd/capnp/user.rs +++ b/bffhd/capnp/user.rs @@ -12,6 +12,9 @@ use capnp::capability::Promise; use capnp::Error; use capnp_rpc::pry; use std::borrow::Cow; +use std::io::Write; +use uuid::Uuid; +use crate::CONFIG; const TARGET: &str = "bffh::api::user"; @@ -333,35 +336,54 @@ impl card_d_e_s_fire_e_v2::Server for User { fn gen_card_token( &mut self, _: GenCardTokenParams, - _: GenCardTokenResults, + mut results: GenCardTokenResults, ) -> Promise<(), Error> { let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "get_token_list").entered(); + let _span = tracing::trace_span!(target: TARGET, "get_card_token").entered(); tracing::trace!("method call"); - Promise::err(Error::unimplemented(format!( - "Method get_token_list is not implemented yet" - ))) + + results.get().set_token(Uuid::new_v4().as_bytes()); + + Promise::ok(()) } - fn get_meta_info(&mut self, _: GetMetaInfoParams, _: GetMetaInfoResults) -> Promise<(), Error> { + fn get_meta_info(&mut self, _: GetMetaInfoParams, mut results: GetMetaInfoResults) + -> Promise<(), Error> + { let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "get_token_list").entered(); + let _span = tracing::trace_span!(target: TARGET, "get_meta_info").entered(); tracing::trace!("method call"); - Promise::err(Error::unimplemented(format!( - "Method get_token_list is not implemented yet" - ))) + + results.get().set_bytes(b"FABACCESS\x00DESFIRE\x001.0\x00"); + + Promise::ok(()) } fn get_space_info( &mut self, _: GetSpaceInfoParams, - _: GetSpaceInfoResults, + mut results: GetSpaceInfoResults, ) -> Promise<(), Error> { let _guard = self.span.enter(); - let _span = tracing::trace_span!(target: TARGET, "get_token_list").entered(); + let _span = tracing::trace_span!(target: TARGET, "get_space_info").entered(); tracing::trace!("method call"); - Promise::err(Error::unimplemented(format!( - "Method get_token_list is not implemented yet" - ))) + + let space = if let Some(space) = CONFIG.get().and_then(|c| c.spacename.as_ref()) { + space + } else { + return Promise::err(Error::failed("No space name configured".to_string())); + }; + + let url = if let Some(url) = CONFIG.get().and_then(|c| c.instanceurl.as_ref()) { + url + } else { + return Promise::err(Error::failed("No instance url configured".to_string())); + }; + + let mut data = Vec::new(); + write!(&mut data, "urn:fabaccess:lab:{space}\x00{url}").unwrap(); + results.get().set_bytes(&data); + + Promise::ok(()) } } diff --git a/bffhd/config/dhall.rs b/bffhd/config/dhall.rs index b933a0b..efb1ecd 100644 --- a/bffhd/config/dhall.rs +++ b/bffhd/config/dhall.rs @@ -96,6 +96,12 @@ pub struct Config { #[serde(default, skip)] pub logging: LogConfig, + + #[serde(default, skip_serializing_if = "Option::is_none")] + pub spacename: Option, + + #[serde(default, skip_serializing_if = "Option::is_none")] + pub instanceurl: Option, } impl Config { @@ -164,6 +170,8 @@ impl Default for Config { tlskeylog: None, verbosity: 0, logging: LogConfig::default(), + instanceurl: None, + spacename: None, } } } diff --git a/bffhd/lib.rs b/bffhd/lib.rs index 77451c1..8e24c15 100644 --- a/bffhd/lib.rs +++ b/bffhd/lib.rs @@ -81,6 +81,8 @@ pub struct Diflouroborane { pub static RESOURCES: OnceCell = OnceCell::new(); +pub static CONFIG: OnceCell = OnceCell::new(); + struct SignalHandlerErr; impl error::Description for SignalHandlerErr { const CODE: &'static str = "signals::new"; @@ -182,7 +184,8 @@ impl Diflouroborane { desc.clone(), ))) })); - RESOURCES.set(resources.clone()); + RESOURCES.set(resources.clone()).unwrap(); + CONFIG.set(config.clone()).unwrap(); Ok(Self { config, diff --git a/bffhd/resources/search.rs b/bffhd/resources/search.rs index 97371d7..a82f9e6 100644 --- a/bffhd/resources/search.rs +++ b/bffhd/resources/search.rs @@ -2,6 +2,7 @@ use crate::resources::Resource; use std::collections::HashMap; use std::sync::Arc; +#[derive(Debug)] struct Inner { id: HashMap, } @@ -19,7 +20,7 @@ impl Inner { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ResourcesHandle { inner: Arc, }