mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 17:09:40 +00:00
Support multiple enterprise configurations (#662)
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
48f8cb3285
commit
3671444d28
14 files changed
+479
-236
No files matched your search
+116
-10
@@ -1,7 +1,9 @@
|
||||
use std::env;
|
||||
use std::sync::OnceLock;
|
||||
use log::{debug, warn};
|
||||
use log::{debug, info, warn};
|
||||
use rocket::{delete, get};
|
||||
use rocket::serde::json::Json;
|
||||
use serde::Serialize;
|
||||
use sys_locale::get_locale;
|
||||
use crate::api_token::APIToken;
|
||||
|
||||
@@ -143,23 +145,127 @@ pub fn read_enterprise_env_config_encryption_secret(_token: APIToken) -> String
|
||||
)
|
||||
}
|
||||
|
||||
/// Represents a single enterprise configuration entry with an ID and server URL.
|
||||
#[derive(Serialize)]
|
||||
pub struct EnterpriseConfig {
|
||||
pub id: String,
|
||||
pub server_url: String,
|
||||
}
|
||||
|
||||
/// Returns all enterprise configurations. Collects configurations from both the
|
||||
/// new multi-config format (`id1@url1;id2@url2`) and the legacy single-config
|
||||
/// environment variables, merging them into one list. Duplicates (by ID) are
|
||||
/// skipped — the first occurrence wins.
|
||||
#[get("/system/enterprise/configs")]
|
||||
pub fn read_enterprise_configs(_token: APIToken) -> Json<Vec<EnterpriseConfig>> {
|
||||
info!("Trying to read the enterprise environment for all configurations.");
|
||||
|
||||
let mut configs: Vec<EnterpriseConfig> = Vec::new();
|
||||
let mut seen_ids: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
|
||||
// Read the new combined format:
|
||||
let combined = get_enterprise_configuration(
|
||||
"configs",
|
||||
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIGS",
|
||||
);
|
||||
|
||||
if !combined.is_empty() {
|
||||
// Parse the new format: id1@url1;id2@url2;...
|
||||
for entry in combined.split(';') {
|
||||
let entry = entry.trim();
|
||||
if entry.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split at the first '@' (GUIDs never contain '@'):
|
||||
if let Some((id, url)) = entry.split_once('@') {
|
||||
let id = id.trim().to_lowercase();
|
||||
let url = url.trim().to_string();
|
||||
if !id.is_empty() && !url.is_empty() && seen_ids.insert(id.clone()) {
|
||||
configs.push(EnterpriseConfig { id, server_url: url });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also read the legacy single-config variables:
|
||||
let config_id = get_enterprise_configuration(
|
||||
"config_id",
|
||||
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_ID",
|
||||
);
|
||||
|
||||
let config_server_url = get_enterprise_configuration(
|
||||
"config_server_url",
|
||||
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_SERVER_URL",
|
||||
);
|
||||
|
||||
if !config_id.is_empty() && !config_server_url.is_empty() {
|
||||
let id = config_id.trim().to_lowercase();
|
||||
if seen_ids.insert(id.clone()) {
|
||||
configs.push(EnterpriseConfig { id, server_url: config_server_url });
|
||||
}
|
||||
}
|
||||
|
||||
Json(configs)
|
||||
}
|
||||
|
||||
/// Returns all enterprise configuration IDs that should be deleted. Supports the new
|
||||
/// multi-delete format (`id1;id2;id3`) as well as the legacy single-delete variable.
|
||||
#[get("/system/enterprise/delete-configs")]
|
||||
pub fn read_enterprise_delete_config_ids(_token: APIToken) -> Json<Vec<String>> {
|
||||
info!("Trying to read the enterprise environment for configuration IDs to delete.");
|
||||
|
||||
let mut ids: Vec<String> = Vec::new();
|
||||
let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
|
||||
// Read the new combined format:
|
||||
let combined = get_enterprise_configuration(
|
||||
"delete_config_ids",
|
||||
"MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_IDS",
|
||||
);
|
||||
|
||||
if !combined.is_empty() {
|
||||
for id in combined.split(';') {
|
||||
let id = id.trim().to_lowercase();
|
||||
if !id.is_empty() && seen.insert(id.clone()) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also read the legacy single-delete variable:
|
||||
let delete_id = get_enterprise_configuration(
|
||||
"delete_config_id",
|
||||
"MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_ID",
|
||||
);
|
||||
|
||||
if !delete_id.is_empty() {
|
||||
let id = delete_id.trim().to_lowercase();
|
||||
if seen.insert(id.clone()) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
Json(ids)
|
||||
}
|
||||
|
||||
fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "windows")] {
|
||||
debug!(r"Detected a Windows machine, trying to read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT' or environment variables.");
|
||||
info!(r"Detected a Windows machine, trying to read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT\{}' or the environment variable '{}'.", _reg_value, env_name);
|
||||
use windows_registry::*;
|
||||
let key_path = r"Software\github\MindWork AI Studio\Enterprise IT";
|
||||
let key = match CURRENT_USER.open(key_path) {
|
||||
Ok(key) => key,
|
||||
Err(_) => {
|
||||
debug!(r"Could not read the registry key HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT. Falling back to environment variables.");
|
||||
info!(r"Could not read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT\{}'. Falling back to the environment variable '{}'.", _reg_value, env_name);
|
||||
return match env::var(env_name) {
|
||||
Ok(val) => {
|
||||
debug!("Falling back to the environment variable '{}' was successful.", env_name);
|
||||
info!("Falling back to the environment variable '{}' was successful.", env_name);
|
||||
val
|
||||
},
|
||||
Err(_) => {
|
||||
debug!("Falling back to the environment variable '{}' was not successful.", env_name);
|
||||
info!("Falling back to the environment variable '{}' was not successful. It seems that there is no enterprise environment available.", env_name);
|
||||
"".to_string()
|
||||
},
|
||||
}
|
||||
@@ -169,14 +275,14 @@ fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
||||
match key.get_string(_reg_value) {
|
||||
Ok(val) => val,
|
||||
Err(_) => {
|
||||
debug!(r"We could read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT', but the value '{}' could not be read. Falling back to environment variables.", _reg_value);
|
||||
info!(r"We could read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT', but the value '{}' could not be read. Falling back to the environment variable '{}'.", _reg_value, env_name);
|
||||
match env::var(env_name) {
|
||||
Ok(val) => {
|
||||
debug!("Falling back to the environment variable '{}' was successful.", env_name);
|
||||
info!("Falling back to the environment variable '{}' was successful.", env_name);
|
||||
val
|
||||
},
|
||||
Err(_) => {
|
||||
debug!("Falling back to the environment variable '{}' was not successful.", env_name);
|
||||
info!("Falling back to the environment variable '{}' was not successful. It seems that there is no enterprise environment available.", env_name);
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
@@ -184,11 +290,11 @@ fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
||||
}
|
||||
} else {
|
||||
// In the case of macOS or Linux, we just read the environment variable:
|
||||
debug!(r"Detected a Unix machine, trying to read the environment variable '{}'.", env_name);
|
||||
info!(r"Detected a Unix machine, trying to read the environment variable '{}'.", env_name);
|
||||
match env::var(env_name) {
|
||||
Ok(val) => val,
|
||||
Err(_) => {
|
||||
debug!("The environment variable '{}' was not found.", env_name);
|
||||
info!("The environment variable '{}' was not found. It seems that there is no enterprise environment available.", env_name);
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ pub fn start_runtime_api() {
|
||||
crate::environment::delete_enterprise_env_config_id,
|
||||
crate::environment::read_enterprise_env_config_server_url,
|
||||
crate::environment::read_enterprise_env_config_encryption_secret,
|
||||
crate::environment::read_enterprise_configs,
|
||||
crate::environment::read_enterprise_delete_config_ids,
|
||||
crate::file_data::extract_data,
|
||||
crate::log::get_log_paths,
|
||||
crate::log::log_event,
|
||||
|
||||
Reference in new issue
Block a user