Skip to content

Commit

Permalink
CP-41474: Authenticate for downloading updates.
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
  • Loading branch information
kc284 committed Jun 5, 2023
1 parent f8a2395 commit f565e2f
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 376 deletions.
6 changes: 2 additions & 4 deletions CFUValidator/Validators/ZipContentsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ private void DownloadPatchFile(XenServerPatchAlert patch, Action<string> statusR
return;
}

string tempFileName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

var action = new DownloadAndUnzipXenServerPatchAction(patch.Patch.Name, new Uri(patch.Patch.PatchUrl),
tempFileName, false, BrandManager.ExtensionUpdate, "iso");
var action = new DownloadAndUnzipUpdateAction(patch.Patch.Name, new Uri(patch.Patch.PatchUrl),
BrandManager.ExtensionUpdate, "iso");

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class DownloadPatchPlanAction : PlanActionWithSession
private readonly XenServerPatch patch;
private Dictionary<XenServerPatch, string> AllDownloadedPatches = new Dictionary<XenServerPatch, string>();
private KeyValuePair<XenServerPatch, string> patchFromDisk;
private string tempFileName = null;

public DownloadPatchPlanAction(IXenConnection connection, XenServerPatch patch, Dictionary<XenServerPatch, string> allDownloadedPatches, KeyValuePair<XenServerPatch, string> patchFromDisk)
: base(connection)
Expand Down Expand Up @@ -96,18 +95,17 @@ private void DownloadFile(ref Session session)
return;

Uri address = new Uri(patchUri);
tempFileName = Path.GetTempFileName();

var exts = Helpers.ElyOrGreater(Connection) ? "iso" : BrandManager.ExtensionUpdate;
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, true, exts);
var downloadAction = new DownloadAndUnzipUpdateAction(patch.Name, address, exts);

downloadAction.Changed += downloadAndUnzipXenServerPatchAction_Changed;
downloadAction.Completed += downloadAndUnzipXenServerPatchAction_Completed;
downloadAction.Changed += DownloadAction_Changed;
downloadAction.Completed += DownloadAction_Completed;

downloadAction.RunSync(session);
}

private void downloadAndUnzipXenServerPatchAction_Changed(ActionBase action)
private void DownloadAction_Changed(ActionBase action)
{
if (action == null)
return;
Expand All @@ -124,17 +122,16 @@ private void downloadAndUnzipXenServerPatchAction_Changed(ActionBase action)
}


private void downloadAndUnzipXenServerPatchAction_Completed(ActionBase sender)
private void DownloadAction_Completed(ActionBase sender)
{
var action = sender as DownloadAndUnzipXenServerPatchAction;
if (action == null)
if (!(sender is DownloadAndUnzipUpdateAction action))
return;

action.Changed -= downloadAndUnzipXenServerPatchAction_Changed;
action.Completed -= downloadAndUnzipXenServerPatchAction_Completed;
action.Changed -= DownloadAction_Changed;
action.Completed -= DownloadAction_Completed;

if (action.Succeeded)
AllDownloadedPatches[patch] = action.PatchPath;
AllDownloadedPatches[patch] = action.UpdatePath;
}
}
}
5 changes: 2 additions & 3 deletions XenAdmin/Wizards/WizardHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ public static string ExtractUpdate(string zippedUpdatePath, Control control)
if (string.IsNullOrEmpty(zippedUpdatePath))
return null;

var unzipAction = new DownloadAndUnzipXenServerPatchAction(Path.GetFileNameWithoutExtension(zippedUpdatePath),
null, zippedUpdatePath, true, BrandManager.ExtensionUpdate, "iso");
var unzipAction = new UnzipUpdateAction(zippedUpdatePath, BrandManager.ExtensionUpdate, "iso");

using (var dlg = new ActionProgressDialog(unzipAction, ProgressBarStyle.Marquee))
{
dlg.ShowDialog(control);
}

return !string.IsNullOrEmpty(unzipAction.PatchPath) ? unzipAction.PatchPath : null;
return !string.IsNullOrEmpty(unzipAction.UpdatePath) ? unzipAction.UpdatePath : null;
}

public static bool IsValidFile(string fileName, out string failureReason)
Expand Down
Loading

0 comments on commit f565e2f

Please sign in to comment.