mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-24 22:06:59 +01:00
Move AddAuthTokenToQueryString
to Helpers
Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com>
This commit is contained in:
parent
16ce163e7f
commit
1b3b4b218d
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified authentication token to the existing query string and returns
|
||||
/// the modified query string.
|
||||
/// </summary>
|
||||
/// <param name="authToken">The authentication token to add to the query string.</param>
|
||||
/// <param name="existingQueryString">The existing query string to add the token to.</param>
|
||||
/// <returns>The modified query string.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified authentication token to the existing query string and returns
|
||||
/// the modified query string.
|
||||
/// </summary>
|
||||
/// <param name="authToken">The authentication token to add to the query string.</param>
|
||||
/// <param name="existingQueryString">The existing query string to add the token to.</param>
|
||||
/// <returns>The modified query string.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user