From 3da1db22faf879af975a954081b89d33309d9064 Mon Sep 17 00:00:00 2001 From: "github-actions[bot] (aider)" Date: Tue, 20 May 2025 10:03:57 +0000 Subject: [PATCH] refactor: Refactor oauth2_ee module, add placeholders --- backend/windmill-api/src/oauth2_ee.rs | 126 +++++++------------------- 1 file changed, 32 insertions(+), 94 deletions(-) diff --git a/backend/windmill-api/src/oauth2_ee.rs b/backend/windmill-api/src/oauth2_ee.rs index 08ed4d7421..e252ca6033 100644 --- a/backend/windmill-api/src/oauth2_ee.rs +++ b/backend/windmill-api/src/oauth2_ee.rs @@ -5,8 +5,8 @@ * Please see the included NOTICE for copyright information and * LICENSE-AGPL for a copy of the license. */ -#[cfg(feature = "private")] -use crate::oauth2_ee; +// This file is `oauth2_ee.rs` and provides the Enterprise Edition implementations +// for oauth2 functionalities, used when the "private" feature is enabled. use std::{collections::HashMap, fmt::Debug}; @@ -92,22 +92,13 @@ pub struct AllClients { pub async fn build_oauth_clients( base_url: &str, oauths_from_config: Option>, - db: &DB, + _base_url: &str, + _oauths_from_config: Option>, + _db: &DB, ) -> anyhow::Result { - #[cfg(feature = "private")] - { - return oauth2_ee::build_oauth_clients(base_url, oauths_from_config, db).await; - } - #[cfg(not(feature = "private"))] - { - let _ = (base_url, oauths_from_config, db); - // Implementation is not open source - return Ok(AllClients { - logins: HashMap::default(), - connects: HashMap::default(), - slack: None, - }); - } + // TODO: Implement the actual Enterprise Edition logic for build_oauth_clients. + // This function is called from `oauth2_oss.rs` when the "private" feature is enabled. + panic!("oauth2_ee::build_oauth_clients (Enterprise Edition) not implemented."); } #[cfg(feature = "oauth2")] @@ -130,47 +121,24 @@ struct Logins { saml: Option, } async fn list_logins() -> error::JsonResult { - #[cfg(feature = "private")] - { - return oauth2_ee::list_logins().await; - } - #[cfg(not(feature = "private"))] - { - // Implementation is not open source - return Ok(Json(Logins { oauth: vec![], saml: None })); - } + // TODO: Implement the actual Enterprise Edition logic for list_logins. + panic!("oauth2_ee::list_logins (Enterprise Edition) not implemented."); } #[cfg(feature = "oauth2")] -async fn list_connects() -> error::JsonResult> { - #[cfg(feature = "private")] - { - // This function is already under #[cfg(feature = "oauth2")] - return oauth2_ee::list_connects_oauth2().await; // Renamed to avoid conflict if ee has a plain list_connects - } - #[cfg(not(feature = "private"))] - { - Ok(Json( - (&OAUTH_CLIENTS.read().await.connects) - .keys() - .map(|x| x.to_owned()) - .collect_vec(), - )) - } +// This is the EE version of list_connects when feature "oauth2" is enabled. +// It's called as `list_connects_oauth2` from oauth2_oss.rs. +async fn list_connects_oauth2() -> error::JsonResult> { + // TODO: Implement the actual Enterprise Edition logic for list_connects_oauth2. + panic!("oauth2_ee::list_connects_oauth2 (Enterprise Edition) not implemented."); } #[cfg(not(feature = "oauth2"))] -async fn list_connects() -> error::JsonResult> { - #[cfg(feature = "private")] - { - // This function is already under #[cfg(not(feature = "oauth2"))] - return oauth2_ee::list_connects_no_oauth2().await; // Renamed for clarity - } - #[cfg(not(feature = "private"))] - { - // Implementation is not open source - return Ok(Json(vec![])); - } +// This is the EE version of list_connects when feature "oauth2" is NOT enabled. +// It's called as `list_connects_no_oauth2` from oauth2_oss.rs. +async fn list_connects_no_oauth2() -> error::JsonResult> { + // TODO: Implement the actual Enterprise Edition logic for list_connects_no_oauth2. + panic!("oauth2_ee::list_connects_no_oauth2 (Enterprise Edition) not implemented."); } pub async fn _refresh_token<'c>( @@ -178,51 +146,21 @@ pub async fn _refresh_token<'c>( path: &str, w_id: &str, id: i32, - db: &DB, + _tx: Transaction<'c, Postgres>, + _path: &str, + _w_id: &str, + _id: i32, + _db: &DB, ) -> error::Result { - #[cfg(feature = "private")] - { - return oauth2_ee::_refresh_token(tx, path, w_id, id, db).await; - } - #[cfg(not(feature = "private"))] - { - let _ = (tx, path, w_id, id, db); - // Implementation is not open source - Err(error::Error::BadRequest( - "Not implemented in Windmill's Open Source repository".to_string(), - )) - } + // TODO: Implement the actual Enterprise Edition logic for _refresh_token. + panic!("oauth2_ee::_refresh_token (Enterprise Edition) not implemented."); } -pub async fn check_nb_of_user(db: &DB) -> error::Result<()> { - #[cfg(feature = "private")] - { - // Assuming EE might have different logic or bypass this check - return oauth2_ee::check_nb_of_user(db).await; - } - #[cfg(not(feature = "private"))] - { - let nb_users_sso = - sqlx::query_scalar!("SELECT COUNT(*) FROM password WHERE login_type != 'password'",) - .fetch_one(db) - .await?; - if nb_users_sso.unwrap_or(0) >= 10 { - return Err(error::Error::BadRequest( - "You have reached the maximum number of oauth users accounts (10) without an enterprise license" - .to_string(), - )); - } - - let nb_users = sqlx::query_scalar!("SELECT COUNT(*) FROM password",) - .fetch_one(db) - .await?; - if nb_users.unwrap_or(0) >= 50 { - return Err(error::Error::BadRequest( - "You have reached the maximum number of accounts (50) without an enterprise license" - .to_string(), - )); - } - return Ok(()); +pub async fn check_nb_of_user(_db: &DB) -> error::Result<()> { + // TODO: Implement the actual Enterprise Edition logic for check_nb_of_user. + // This might involve different user limits or licensing checks. + // For example, EE version might bypass these checks or have different limits. + Ok(()) // Placeholder: Assume EE version has different logic or no limits here. } #[derive(Clone, Debug)]