main: Use labadoor-auth
instead of the CSV module directly
This commit is contained in:
parent
2caad2a5ef
commit
e7c34865c5
6 changed files with 41 additions and 30 deletions
|
@ -5,7 +5,10 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.4.8", features = ["derive"] }
|
clap = { version = "4.4.8", features = ["derive"] }
|
||||||
|
config = "0.13.4"
|
||||||
|
labadoor-acl = { path = "../labadoor-acl" }
|
||||||
labadoor-csv = { path = "../labadoor-csv", optional = true }
|
labadoor-csv = { path = "../labadoor-csv", optional = true }
|
||||||
|
serde = { version = "1.0.193", features = ["derive"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
csv = ["dep:labadoor-csv"]
|
csv = ["dep:labadoor-csv"]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
|
@ -29,3 +30,11 @@ pub struct Open {
|
||||||
pub fn parse() -> Cli {
|
pub fn parse() -> Cli {
|
||||||
Cli::parse()
|
Cli::parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "csv")]
|
||||||
|
#[derive(Deserialize, Parser, Debug)]
|
||||||
|
pub struct CSV {
|
||||||
|
#[clap(short, long)]
|
||||||
|
#[arg(default_value = "Some(String::from(\"/etc/labadoor\"))")]
|
||||||
|
pub path: String,
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
pub mod to_config;
|
||||||
|
use labadoor_acl::ACL;
|
||||||
|
use to_config::ToConfig;
|
||||||
|
|
||||||
pub fn auth(i: &cli::Cli) {
|
pub fn auth(i: &cli::Cli, config: config::Config) {
|
||||||
match i.command {
|
let acl = match &i.backend {
|
||||||
cli::Command::Open(_) => todo!(),
|
#[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(),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
14
labadoor-auth/src/to_config.rs
Normal file
14
labadoor-auth/src/to_config.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
use crate::cli::*;
|
||||||
|
|
||||||
|
pub trait ToConfig<T> {
|
||||||
|
fn to_config(&self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "csv")]
|
||||||
|
impl ToConfig<labadoor_csv::CSVArgs> for CSV {
|
||||||
|
fn to_config(&self) -> labadoor_csv::CSVArgs {
|
||||||
|
labadoor_csv::CSVArgs {
|
||||||
|
path: self.path.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,8 +13,6 @@ pub enum Command {
|
||||||
Telegram(Telegram),
|
Telegram(Telegram),
|
||||||
#[cfg(feature = "matrix")]
|
#[cfg(feature = "matrix")]
|
||||||
Matrix(Matrix),
|
Matrix(Matrix),
|
||||||
#[cfg(feature = "csv")]
|
|
||||||
CSV(CSV),
|
|
||||||
#[cfg(feature = "gpio")]
|
#[cfg(feature = "gpio")]
|
||||||
GPIO(GPIO),
|
GPIO(GPIO),
|
||||||
#[cfg(feature = "auth")]
|
#[cfg(feature = "auth")]
|
||||||
|
@ -39,21 +37,6 @@ pub struct Matrix {
|
||||||
pub device_id: Option<String>,
|
pub device_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "csv")]
|
|
||||||
#[derive(Deserialize, Parser, Debug)]
|
|
||||||
pub struct CSV {
|
|
||||||
#[clap(short, long)]
|
|
||||||
#[arg(default_value = "Some(String::from(\"/etc/labadoor\"))")]
|
|
||||||
pub path: Option<String>,
|
|
||||||
#[clap(short, long)]
|
|
||||||
pub method: String,
|
|
||||||
#[clap(short, long)]
|
|
||||||
pub identifier: String,
|
|
||||||
// #[cfg(feature = "multiple_resources")]
|
|
||||||
#[clap(short, long)]
|
|
||||||
pub resource_shortcut: i8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gpio")]
|
#[cfg(feature = "gpio")]
|
||||||
#[derive(Deserialize, Parser, Debug)]
|
#[derive(Deserialize, Parser, Debug)]
|
||||||
pub struct GPIO {
|
pub struct GPIO {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use labadoor_acl::ACL;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod to_config;
|
mod to_config;
|
||||||
use to_config::ToConfig;
|
use to_config::ToConfig;
|
||||||
|
@ -21,14 +20,6 @@ fn main() {
|
||||||
let matrix = config.get::<cli::Matrix>("matrix").unwrap().to_config();
|
let matrix = config.get::<cli::Matrix>("matrix").unwrap().to_config();
|
||||||
labadoor_matrix::matrix(matrix);
|
labadoor_matrix::matrix(matrix);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "csv")]
|
|
||||||
cli::Command::CSV(_) => {
|
|
||||||
let csv = config.get::<cli::CSV>("csv").unwrap();
|
|
||||||
let c = labadoor_csv::CSV {
|
|
||||||
path: csv.path.unwrap(),
|
|
||||||
};
|
|
||||||
c.auth_user(csv.method, csv.identifier, csv.resource_shortcut);
|
|
||||||
}
|
|
||||||
#[cfg(feature = "gpio")]
|
#[cfg(feature = "gpio")]
|
||||||
cli::Command::GPIO(_) => {
|
cli::Command::GPIO(_) => {
|
||||||
let gpio = config.get::<cli::GPIO>("gpio").unwrap().to_config();
|
let gpio = config.get::<cli::GPIO>("gpio").unwrap().to_config();
|
||||||
|
@ -36,7 +27,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
#[cfg(feature = "auth")]
|
#[cfg(feature = "auth")]
|
||||||
cli::Command::Auth(cli) => {
|
cli::Command::Auth(cli) => {
|
||||||
labadoor_auth::auth(cli);
|
labadoor_auth::auth(cli, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue