open: Call logging binary found from configuration
This commit is contained in:
parent
3938e5c0c8
commit
30525d4408
4 changed files with 22 additions and 0 deletions
|
@ -37,6 +37,7 @@ pub fn log(cli: &cli::Cli, config: ConfigBuilder<DefaultState>) -> Result<(), ()
|
||||||
cliargs.resource.clone(),
|
cliargs.resource.clone(),
|
||||||
cliargs.method.clone(),
|
cliargs.method.clone(),
|
||||||
);
|
);
|
||||||
|
ret = Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub type Binary = Vec<String>;
|
||||||
pub struct OpenArgs {
|
pub struct OpenArgs {
|
||||||
pub auth: BTreeMap<String, Binary>,
|
pub auth: BTreeMap<String, Binary>,
|
||||||
pub hardware: BTreeMap<String, Binary>,
|
pub hardware: BTreeMap<String, Binary>,
|
||||||
|
pub log: Binary,
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
pub resource_shortcut: i8,
|
pub resource_shortcut: i8,
|
||||||
|
@ -36,13 +37,27 @@ fn run_auth(args: &OpenArgs, bin: Binary) -> Result<AuthResult, String> {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_log(args: &OpenArgs, identifier: String, resource: String) -> Result<String, String> {
|
||||||
|
let a = labadoor_common::LogBinaryArgs {
|
||||||
|
time: "time.now()".to_string(),
|
||||||
|
method: args.method.clone(),
|
||||||
|
identifier: identifier,
|
||||||
|
resource: resource,
|
||||||
|
};
|
||||||
|
labadoor_common::run_log(a, args.log.clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open(args: OpenArgs) -> Result<(), ()> {
|
pub fn open(args: OpenArgs) -> Result<(), ()> {
|
||||||
let mut msg = "Not authorized!";
|
let mut msg = "Not authorized!";
|
||||||
let mut ret = Err(());
|
let mut ret = Err(());
|
||||||
|
let mut identifier = args.identifier.clone();
|
||||||
|
let mut resource = "Null".to_string();
|
||||||
|
|
||||||
for (method, binary) in args.auth.iter() {
|
for (method, binary) in args.auth.iter() {
|
||||||
let output = run_auth(&args, binary.to_vec());
|
let output = run_auth(&args, binary.to_vec());
|
||||||
if let Ok(user) = output {
|
if let Ok(user) = output {
|
||||||
|
identifier = user.username;
|
||||||
|
resource = user.resource.clone();
|
||||||
let resource_bin = args.hardware.get(&user.resource).unwrap();
|
let resource_bin = args.hardware.get(&user.resource).unwrap();
|
||||||
if let Ok(_) = labadoor_common::run_bin(resource_bin.to_vec()) {
|
if let Ok(_) = labadoor_common::run_bin(resource_bin.to_vec()) {
|
||||||
msg = "Open sesame!";
|
msg = "Open sesame!";
|
||||||
|
@ -53,5 +68,6 @@ pub fn open(args: OpenArgs) -> Result<(), ()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}", msg);
|
println!("{}", msg);
|
||||||
|
run_log(&args, identifier, resource).expect("Could not log event");
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ backends = ["csv"]
|
||||||
[auth.csv]
|
[auth.csv]
|
||||||
path = "./labadoor-csv"
|
path = "./labadoor-csv"
|
||||||
|
|
||||||
|
[open]
|
||||||
|
log = [ "/usr/bin/labadoor", "log" ]
|
||||||
|
|
||||||
[open.auth]
|
[open.auth]
|
||||||
labadoor = [ "/usr/bin/labadoor", "auth" ]
|
labadoor = [ "/usr/bin/labadoor", "auth" ]
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ pub struct Open {
|
||||||
pub auth: BTreeMap<String, Vec<String>>,
|
pub auth: BTreeMap<String, Vec<String>>,
|
||||||
#[clap(skip)]
|
#[clap(skip)]
|
||||||
pub hardware: BTreeMap<String, Vec<String>>,
|
pub hardware: BTreeMap<String, Vec<String>>,
|
||||||
|
#[clap(skip)]
|
||||||
|
pub log: Option<Vec<String>>,
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
pub resource_shortcut: i8,
|
pub resource_shortcut: i8,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue