2026-02-15 17:11:57 +00:00
|
|
|
|
using AIStudio.Tools.Rust;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Tools.Services;
|
2025-06-01 19:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
public sealed partial class RustService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Tries to read the enterprise environment for the configuration encryption secret.
|
2025-06-01 19:14:21 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Returns an empty string when the environment is not set or the request fails.
|
|
|
|
|
|
/// Otherwise, the base64-encoded encryption secret.
|
2025-06-01 19:14:21 +00:00
|
|
|
|
/// </returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
public async Task<string> EnterpriseEnvConfigEncryptionSecret()
|
2025-06-01 19:14:21 +00:00
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var result = await this.http.GetAsync("/system/enterprise/config/encryption_secret");
|
2025-06-01 19:14:21 +00:00
|
|
|
|
if (!result.IsSuccessStatusCode)
|
|
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
this.logger!.LogError($"Failed to query the enterprise configuration encryption secret: '{result.StatusCode}'");
|
|
|
|
|
|
return string.Empty;
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var encryptionSecret = await result.Content.ReadAsStringAsync();
|
|
|
|
|
|
return string.IsNullOrWhiteSpace(encryptionSecret) ? string.Empty : encryptionSecret;
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|
2026-02-15 17:11:57 +00:00
|
|
|
|
|
2025-06-01 19:14:21 +00:00
|
|
|
|
/// <summary>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Reads all enterprise configurations (multi-config support).
|
2025-06-01 19:14:21 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Returns a list of enterprise environments parsed from the Rust runtime.
|
|
|
|
|
|
/// The ETag is not yet determined; callers must resolve it separately.
|
2025-06-01 19:14:21 +00:00
|
|
|
|
/// </returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
public async Task<List<EnterpriseEnvironment>> EnterpriseEnvConfigs()
|
2025-06-01 19:14:21 +00:00
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var result = await this.http.GetAsync("/system/enterprise/configs");
|
2025-06-01 19:14:21 +00:00
|
|
|
|
if (!result.IsSuccessStatusCode)
|
|
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
this.logger!.LogError($"Failed to query the enterprise configurations: '{result.StatusCode}'");
|
|
|
|
|
|
return [];
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var configs = await result.Content.ReadFromJsonAsync<List<EnterpriseConfig>>(this.jsonRustSerializerOptions);
|
|
|
|
|
|
if (configs is null)
|
|
|
|
|
|
return [];
|
2025-06-01 19:14:21 +00:00
|
|
|
|
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var environments = new List<EnterpriseEnvironment>();
|
|
|
|
|
|
foreach (var config in configs)
|
2025-06-01 19:14:21 +00:00
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
if (Guid.TryParse(config.Id, out var id))
|
|
|
|
|
|
environments.Add(new EnterpriseEnvironment(config.ServerUrl, id, null));
|
|
|
|
|
|
else
|
|
|
|
|
|
this.logger!.LogWarning($"Skipping enterprise config with invalid ID: '{config.Id}'.");
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|
2026-02-15 17:11:57 +00:00
|
|
|
|
|
|
|
|
|
|
return environments;
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|
2026-02-07 21:59:41 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Reads all enterprise configuration IDs that should be deleted.
|
2026-02-07 21:59:41 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
/// Returns a list of GUIDs representing configuration IDs to remove.
|
2026-02-07 21:59:41 +00:00
|
|
|
|
/// </returns>
|
2026-02-15 17:11:57 +00:00
|
|
|
|
public async Task<List<Guid>> EnterpriseEnvDeleteConfigIds()
|
2026-02-07 21:59:41 +00:00
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var result = await this.http.GetAsync("/system/enterprise/delete-configs");
|
2026-02-07 21:59:41 +00:00
|
|
|
|
if (!result.IsSuccessStatusCode)
|
|
|
|
|
|
{
|
2026-02-15 17:11:57 +00:00
|
|
|
|
this.logger!.LogError($"Failed to query the enterprise delete configuration IDs: '{result.StatusCode}'");
|
|
|
|
|
|
return [];
|
2026-02-07 21:59:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-15 17:11:57 +00:00
|
|
|
|
var ids = await result.Content.ReadFromJsonAsync<List<string>>(this.jsonRustSerializerOptions);
|
|
|
|
|
|
if (ids is null)
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
|
|
var guids = new List<Guid>();
|
|
|
|
|
|
foreach (var idStr in ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Guid.TryParse(idStr, out var id))
|
|
|
|
|
|
guids.Add(id);
|
|
|
|
|
|
else
|
|
|
|
|
|
this.logger!.LogWarning($"Skipping invalid GUID in enterprise delete config IDs: '{idStr}'.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return guids;
|
2026-02-07 21:59:41 +00:00
|
|
|
|
}
|
2025-06-01 19:14:21 +00:00
|
|
|
|
}
|