auth: Enable backends based on the configuration or --backends

This commit is contained in:
George Kaklamanos 2023-11-25 18:08:56 +02:00
parent eebb4ca762
commit 7a294ee146
No known key found for this signature in database
GPG key ID: C0CAB8A6BDC9399D
4 changed files with 39 additions and 18 deletions

View file

@ -3,16 +3,34 @@ pub mod to_config;
use labadoor_acl::ACL;
use to_config::ToConfig;
pub fn auth(i: &cli::Cli, config: config::Config) {
let acl = match &i.backend {
#[cfg(feature = "csv")]
cli::Backend::CSV => config.get::<cli::CSV>("csv").unwrap().to_config().new(),
};
match &i.command {
cli::Command::Open(open) => acl.auth_user(
open.method.clone(),
open.identifier.clone(),
open.resource.clone(),
),
macro_rules! add_cliargs {
($d:ident,$section:expr,$i:ident) => {
$d.add_source(config::File::from_str(
&format!("[{}]\n{}", $section, toml::to_string($i).unwrap()),
config::FileFormat::Toml,
))
.build()
.unwrap()
};
}
use std::collections::{HashMap, HashSet};
pub fn auth(cli: &cli::Cli, config: config::ConfigBuilder<config::builder::DefaultState>) {
let config = add_cliargs!(config, "auth", cli);
let backends = config.get::<Vec<cli::Backend>>("auth.backends").unwrap();
for backend in backends {
let acl = match backend {
#[cfg(feature = "csv")]
cli::Backend::CSV => config.get::<cli::CSV>("csv").unwrap().to_config().new(),
};
match &cli.command {
cli::Command::Open(cliargs) => {
let found = acl.auth_user(
cliargs.method.clone(),
cliargs.identifier.clone(),
cliargs.resource.clone(),
);
}
};
}
}