Allow using test locations for downloading LCM hotfixes.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2023-07-26 22:27:39 +01:00
parent 049b85fb11
commit 36c5b940cc
3 changed files with 45 additions and 6 deletions

View File

@ -37,6 +37,7 @@ using System.Linq;
using System.Net.NetworkInformation;
using XenCenterLib.Archive;
using XenAdmin.Actions.Updates;
using XenAdmin.Core;
namespace XenAdmin.Actions
{
@ -214,22 +215,48 @@ namespace XenAdmin.Actions
Description = Messages.COMPLETED;
}
private static bool IsFileServiceUri(Uri uri)
{
var updateUriPrefix = new Uri(InvisibleMessages.UPDATE_URL_PREFIX);
if (uri.Host == updateUriPrefix.Host)
return true;
var customUpdateUriPrefix = XenAdminConfigManager.Provider.GetCustomFileServicePrefix();
if (!string.IsNullOrEmpty(customUpdateUriPrefix))
{
var customUpdateUri = new Uri(customUpdateUriPrefix);
if (uri.Host == customUpdateUri.Host)
return true;
}
return false;
}
private void DownloadFile(out string outputFileName)
{
outputFileName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
log.InfoFormat("Downloading update '{0}' (from '{1}') to '{2}'", UpdateName, _updateUri, outputFileName);
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_DOWNLOADING_DESC, UpdateName);
LogDescriptionChanges = false;
_client = new WebClient();
_client.DownloadProgressChanged += client_DownloadProgressChanged;
_client.DownloadFileCompleted += client_DownloadFileCompleted;
NetworkChange.NetworkAvailabilityChanged += NetworkAvailabilityChanged;
var credential = TokenManager.GetDownloadCredential(XenAdminConfigManager.Provider);
_client.Headers.Add("Authorization", $"Basic {credential}");
//useful when the updates use test locations
if (IsFileServiceUri(_updateUri))
{
log.InfoFormat("Authenticating account...");
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_AUTHENTICATING_DESC,
BrandManager.CompanyNameLegacy);
var credential = TokenManager.GetDownloadCredential(XenAdminConfigManager.Provider);
_client.Headers.Add("Authorization", $"Basic {credential}");
}
log.InfoFormat("Downloading update '{0}' (from '{1}') to '{2}'", UpdateName, _updateUri, outputFileName);
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_DOWNLOADING_DESC, UpdateName);
LogDescriptionChanges = false;
int errorCount = 0;
bool needToRetry = false;

View File

@ -204,6 +204,15 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to https://fileservice.citrix.com/direct/v2/download/.
/// </summary>
public static string UPDATE_URL_PREFIX {
get {
return ResourceManager.GetString("UPDATE_URL_PREFIX", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to https://www.citrix.com/products/citrix-hypervisor/get-started.html.
/// </summary>

View File

@ -165,6 +165,9 @@
<data name="TOKEN_API_URL" xml:space="preserve">
<value>https://fileservice.citrix.com/api/session/token</value>
</data>
<data name="UPDATE_URL_PREFIX" xml:space="preserve">
<value>https://fileservice.citrix.com/direct/v2/download/</value>
</data>
<data name="UPSELL_LEARNMOREURL_TRIAL" xml:space="preserve">
<value>https://www.citrix.com/products/citrix-hypervisor/get-started.html</value>
</data>