Skip to content

Commit

Permalink
Allow using test locations for downloading LCM hotfixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Chremmou <[email protected]>
  • Loading branch information
kc284 committed Jul 26, 2023
1 parent 049b85f commit 8582174
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
39 changes: 33 additions & 6 deletions XenModel/Actions/Updates/DownloadUnzipUpdateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using System.Net.NetworkInformation;
using XenCenterLib.Archive;
using XenAdmin.Actions.Updates;
using XenAdmin.Core;

namespace XenAdmin.Actions
{
Expand Down Expand Up @@ -214,22 +215,48 @@ protected override void Run()
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;
Expand Down
9 changes: 9 additions & 0 deletions XenModel/InvisibleMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions XenModel/InvisibleMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 8582174

Please sign in to comment.