feat: refactor new

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-10-22 22:40:04 +02:00
parent 89acf8c343
commit ec3ed89d68
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 4 additions and 10 deletions

View File

@ -24,10 +24,11 @@ pub trait Auth {
pub struct AuthService(Arc<dyn Auth + Send + Sync + 'static>); pub struct AuthService(Arc<dyn Auth + Send + Sync + 'static>);
impl AuthService { impl AuthService {
pub async fn new(config: &AuthClap, session: SessionService) -> anyhow::Result<Self> { pub async fn new(config: &AuthClap) -> anyhow::Result<Self> {
match config.engine { match config.engine {
AuthEngine::Noop => Ok(Self::new_noop()), AuthEngine::Noop => Ok(Self::new_noop()),
AuthEngine::Zitadel => { AuthEngine::Zitadel => {
let session = SessionService::new(config).await?;
let oauth: OAuth = ZitadelConfig::try_from(config.zitadel.clone())?.into(); let oauth: OAuth = ZitadelConfig::try_from(config.zitadel.clone())?.into();
let introspection: IntrospectionService = let introspection: IntrospectionService =
IntrospectionService::new_zitadel(config).await?; IntrospectionService::new_zitadel(config).await?;

View File

@ -48,11 +48,7 @@ async fn main() -> anyhow::Result<()> {
}, },
}; };
let auth_service = AuthService::new_zitadel( let auth_service = AuthService::new(&auth);
OAuth::try_from(auth.clone())?,
IntrospectionService::new_zitadel(&auth).await?,
SessionService::new(&auth).await?,
);
let state = AppState { let state = AppState {
auth: auth_service.clone(), auth: auth_service.clone(),

View File

@ -43,10 +43,7 @@ async fn main() -> anyhow::Result<()> {
"--session-postgres-conn=postgres://como:somenotverysecurepassword@localhost:5432/como", "--session-postgres-conn=postgres://como:somenotverysecurepassword@localhost:5432/como",
]); ]);
let auth = cmd.auth; let auth_service = AuthService::new(&cmd.auth).await?;
let session_service = SessionService::new(&auth).await?;
let auth_service = AuthService::new(&auth, session_service).await?;
let state = AppState { let state = AppState {
auth: auth_service.clone(), auth: auth_service.clone(),