mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-22 03:33:48 +01:00
Implement remaining card management
This commit is contained in:
parent
24c02fccff
commit
e42a32934a
@ -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(())
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +96,12 @@ pub struct Config {
|
||||
|
||||
#[serde(default, skip)]
|
||||
pub logging: LogConfig,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub spacename: Option<String>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub instanceurl: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@ -164,6 +170,8 @@ impl Default for Config {
|
||||
tlskeylog: None,
|
||||
verbosity: 0,
|
||||
logging: LogConfig::default(),
|
||||
instanceurl: None,
|
||||
spacename: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ pub struct Diflouroborane {
|
||||
|
||||
pub static RESOURCES: OnceCell<ResourcesHandle> = OnceCell::new();
|
||||
|
||||
pub static CONFIG: OnceCell<Config> = 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,
|
||||
|
@ -2,6 +2,7 @@ use crate::resources::Resource;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Inner {
|
||||
id: HashMap<String, Resource>,
|
||||
}
|
||||
@ -19,7 +20,7 @@ impl Inner {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ResourcesHandle {
|
||||
inner: Arc<Inner>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user