refactor: Refactor oauth2_ee module, add placeholders

This commit is contained in:
github-actions[bot] (aider)
2025-05-20 10:03:57 +00:00
parent 0bd30a7d59
commit 3da1db22fa
+32 -94
View File
@@ -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<HashMap<String, OAuthClient>>,
db: &DB,
_base_url: &str,
_oauths_from_config: Option<HashMap<String, OAuthClient>>,
_db: &DB,
) -> anyhow::Result<AllClients> {
#[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<String>,
}
async fn list_logins() -> error::JsonResult<Logins> {
#[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<Vec<String>> {
#[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<Vec<String>> {
// 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<Vec<String>> {
#[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<Vec<String>> {
// 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<String> {
#[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)]