refactor(auth): move into central auth-engine setup
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,2 +1,149 @@
|
||||
pub use introspection::IntrospectionConfigClap;
|
||||
|
||||
mod introspection;
|
||||
mod oauth;
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum AuthEngine {
|
||||
Noop,
|
||||
Zitadel,
|
||||
}
|
||||
|
||||
#[derive(clap::Args, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct AuthClap {
|
||||
#[arg(
|
||||
env = "AUTH_ENGINE",
|
||||
long = "auth-engine",
|
||||
requires_ifs = [
|
||||
( "zitadel", "ZitadelClap" )
|
||||
],
|
||||
default_value = "noop" )
|
||||
]
|
||||
pub engine: AuthEngine,
|
||||
|
||||
#[clap(flatten)]
|
||||
pub zitadel: ZitadelClap,
|
||||
}
|
||||
|
||||
#[derive(clap::Args, Clone, Debug, PartialEq, Eq)]
|
||||
#[group(requires_all = ["auth_url", "client_id", "client_secret", "redirect_url", "token_url", "authority_url"])]
|
||||
pub struct ZitadelClap {
|
||||
#[arg(env = "ZITADEL_AUTH_URL", long = "zitadel-auth-url")]
|
||||
pub auth_url: Option<String>,
|
||||
|
||||
#[arg(env = "ZITADEL_CLIENT_ID", long = "zitadel-client-id")]
|
||||
pub client_id: Option<String>,
|
||||
|
||||
#[arg(env = "ZITADEL_CLIENT_SECRET", long = "zitadel-client-secret")]
|
||||
pub client_secret: Option<String>,
|
||||
|
||||
#[arg(env = "ZITADEL_REDIRECT_URL", long = "zitadel-redirect-url")]
|
||||
pub redirect_url: Option<String>,
|
||||
|
||||
#[arg(env = "ZITADEL_AUTHORITY_URL", long = "zitadel-authority-url")]
|
||||
pub authority_url: Option<String>,
|
||||
|
||||
#[arg(env = "ZITADEL_TOKEN_URL", long = "zitadel-token-url")]
|
||||
pub token_url: Option<String>,
|
||||
}
|
||||
|
||||
impl AuthClap {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{AuthClap, AuthEngine, ZitadelClap};
|
||||
use clap::Parser;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum Commands {
|
||||
One {
|
||||
#[clap(flatten)]
|
||||
options: AuthClap,
|
||||
},
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_command_parse_as_default_noop() {
|
||||
let cli: Cli = Cli::parse_from(&["base", "one"]);
|
||||
|
||||
assert_eq!(
|
||||
cli.command,
|
||||
Commands::One {
|
||||
options: AuthClap {
|
||||
engine: AuthEngine::Noop,
|
||||
zitadel: ZitadelClap {
|
||||
auth_url: None,
|
||||
client_id: None,
|
||||
client_secret: None,
|
||||
redirect_url: None,
|
||||
token_url: None,
|
||||
authority_url: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_command_parse_as_noop() {
|
||||
let cli: Cli = Cli::parse_from(&["base", "one", "--auth-engine", "noop"]);
|
||||
|
||||
assert_eq!(
|
||||
cli.command,
|
||||
Commands::One {
|
||||
options: AuthClap {
|
||||
engine: AuthEngine::Noop,
|
||||
zitadel: ZitadelClap {
|
||||
auth_url: None,
|
||||
client_id: None,
|
||||
client_secret: None,
|
||||
redirect_url: None,
|
||||
token_url: None,
|
||||
authority_url: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_command_parse_as_zitadel() {
|
||||
let cli: Cli = Cli::parse_from(&[
|
||||
"base",
|
||||
"one",
|
||||
"--auth-engine",
|
||||
"zitadel",
|
||||
"--zitadel-client-id=something",
|
||||
"--zitadel-client-secret=something",
|
||||
"--zitadel-auth-url=https://something",
|
||||
"--zitadel-redirect-url=https://something",
|
||||
"--zitadel-token-url=https://something",
|
||||
"--zitadel-authority-url=https://something",
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
cli.command,
|
||||
Commands::One {
|
||||
options: AuthClap {
|
||||
engine: AuthEngine::Zitadel,
|
||||
zitadel: ZitadelClap {
|
||||
auth_url: Some("https://something".into()),
|
||||
client_id: Some("something".into()),
|
||||
client_secret: Some("something".into()),
|
||||
redirect_url: Some("https://something".into()),
|
||||
token_url: Some("https://something".into()),
|
||||
authority_url: Some("https://something".into()),
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user