diff --git a/XenModel/Actions/Updates/DownloadUpdatesXmlAction.cs b/XenModel/Actions/Updates/DownloadUpdatesXmlAction.cs index 5419692a9..15d5d374e 100644 --- a/XenModel/Actions/Updates/DownloadUpdatesXmlAction.cs +++ b/XenModel/Actions/Updates/DownloadUpdatesXmlAction.cs @@ -29,9 +29,7 @@ */ using System; -using System.Web; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; using System.IO; using System.Xml; @@ -44,7 +42,6 @@ namespace XenAdmin.Actions { public class DownloadUpdatesXmlAction : AsyncAction { - private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType); private const string ClientVersionsNode = "versions"; private const string XenServerVersionsNode = "serverversions"; @@ -353,7 +350,7 @@ namespace XenAdmin.Actions else { var authToken = XenAdminConfigManager.Provider.GetInternalStageAuthToken(); - uriBuilder.Query = AddAuthTokenToQueryString(authToken, uriBuilder.Query); + uriBuilder.Query = Helpers.AddAuthTokenToQueryString(authToken, uriBuilder.Query); var proxy = XenAdminConfigManager.Provider.GetProxyFromSettings(Connection, false); @@ -368,46 +365,5 @@ namespace XenAdmin.Actions return checkForUpdatesXml; } - - /// - /// Adds the specified authentication token to the existing query string and returns - /// the modified query string. - /// - /// The authentication token to add to the query string. - /// The existing query string to add the token to. - /// The modified query string. - private static string AddAuthTokenToQueryString(string authToken, string existingQueryString) - { - var queryString = existingQueryString; - if (string.IsNullOrEmpty(authToken)) - { - return queryString; - } - - try - { - var query = new NameValueCollection(); - if (!string.IsNullOrEmpty(existingQueryString)) - { - query.Add(HttpUtility.ParseQueryString(existingQueryString)); - } - - var tokenQueryString = HttpUtility.ParseQueryString(authToken); - - query.Add(tokenQueryString); - - queryString = string.Join("&", - query.AllKeys - .Where(key => !string.IsNullOrWhiteSpace(key)) - .Select(key => $"{key}={query[key]}") - ); - } - catch (Exception ex) - { - Log.Error(ex); - } - - return queryString; - } } } diff --git a/XenModel/Utils/Helpers.cs b/XenModel/Utils/Helpers.cs index ef23ab03a..c78588020 100755 --- a/XenModel/Utils/Helpers.cs +++ b/XenModel/Utils/Helpers.cs @@ -30,12 +30,14 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; +using System.Web; using System.Xml; using XenAdmin.Network; using XenAPI; @@ -1537,5 +1539,46 @@ namespace XenAdmin.Core return GetCoordinator(connection).external_auth_type != Auth.AUTH_TYPE_NONE; } + + /// + /// Adds the specified authentication token to the existing query string and returns + /// the modified query string. + /// + /// The authentication token to add to the query string. + /// The existing query string to add the token to. + /// The modified query string. + public static string AddAuthTokenToQueryString(string authToken, string existingQueryString) + { + var queryString = existingQueryString; + if (string.IsNullOrEmpty(authToken)) + { + return queryString; + } + + try + { + var query = new NameValueCollection(); + if (!string.IsNullOrEmpty(existingQueryString)) + { + query.Add(HttpUtility.ParseQueryString(existingQueryString)); + } + + var tokenQueryString = HttpUtility.ParseQueryString(authToken); + + query.Add(tokenQueryString); + + queryString = string.Join("&", + query.AllKeys + .Where(key => !string.IsNullOrWhiteSpace(key)) + .Select(key => $"{key}={query[key]}") + ); + } + catch (Exception ex) + { + log.Error(ex); + } + + return queryString; + } } }