mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-21 04:12:56 +00:00
Add ETag handling in enterprise environment logic
This commit is contained in:
parent
4ced06473b
commit
d10f2af9f7
@ -1,6 +1,8 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace AIStudio.Tools;
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId)
|
public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId, EntityTagHeaderValue? ETag)
|
||||||
{
|
{
|
||||||
public bool IsActive => !string.IsNullOrEmpty(this.ConfigurationServerUrl) && this.ConfigurationId != Guid.Empty;
|
public bool IsActive => !string.IsNullOrEmpty(this.ConfigurationServerUrl) && this.ConfigurationId != Guid.Empty;
|
||||||
}
|
}
|
@ -1,9 +1,29 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace AIStudio.Tools.PluginSystem;
|
namespace AIStudio.Tools.PluginSystem;
|
||||||
|
|
||||||
public static partial class PluginFactory
|
public static partial class PluginFactory
|
||||||
{
|
{
|
||||||
|
public static async Task<EntityTagHeaderValue?> DetermineConfigPluginETagAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl;
|
||||||
|
var downloadUrl = $"{serverUrl}/{configPlugId}.zip";
|
||||||
|
|
||||||
|
using var http = new HttpClient();
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, downloadUrl);
|
||||||
|
var response = await http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
|
return response.Headers.ETag;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOG.LogError(e, "An error occurred while determining the ETag for the configuration plugin.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if(!IS_INITIALIZED)
|
if(!IS_INITIALIZED)
|
||||||
|
@ -40,7 +40,8 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
|
|||||||
|
|
||||||
var enterpriseConfigServerUrl = await rustService.EnterpriseEnvConfigServerUrl();
|
var enterpriseConfigServerUrl = await rustService.EnterpriseEnvConfigServerUrl();
|
||||||
var enterpriseConfigId = await rustService.EnterpriseEnvConfigId();
|
var enterpriseConfigId = await rustService.EnterpriseEnvConfigId();
|
||||||
var nextEnterpriseEnvironment = new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId);
|
var etag = await PluginFactory.DetermineConfigPluginETagAsync(enterpriseConfigId, enterpriseConfigServerUrl);
|
||||||
|
var nextEnterpriseEnvironment = new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId, etag);
|
||||||
if (CURRENT_ENVIRONMENT != nextEnterpriseEnvironment)
|
if (CURRENT_ENVIRONMENT != nextEnterpriseEnvironment)
|
||||||
{
|
{
|
||||||
logger.LogInformation("The enterprise environment has changed. Updating the current environment.");
|
logger.LogInformation("The enterprise environment has changed. Updating the current environment.");
|
||||||
|
Loading…
Reference in New Issue
Block a user