Skip to content

Commit

Permalink
Merge pull request #333 from petr-jancik-swi/feature/change-swis-rest…
Browse files Browse the repository at this point in the history
…-enpoint-port

Changes to SWIS REST endpoint
  • Loading branch information
danjagnow authored Mar 31, 2023
2 parents eea01a6 + b351fb5 commit 14a18a2
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 20 deletions.
1 change: 1 addition & 0 deletions Src/SwqlStudio/ConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static List<ServerType> AvailableServerTypes
new ServerType { Type = "Orion (v3) AD", IsAuthenticationRequired = false },
new ServerType { Type = "Orion (v3) Certificate", IsAuthenticationRequired = false },
new ServerType { Type = "Orion (v3) over HTTPS", IsAuthenticationRequired = true },
new ServerType { Type = "Orion (v3) over HTTPS legacy pre-2023", IsAuthenticationRequired = true}
};

if (Settings.Default.ShowCompressedModes)
Expand Down
3 changes: 3 additions & 0 deletions Src/SwqlStudio/InfoServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static InfoServiceBase Create(string serverType, string username, string

case "ORION (V3) OVER HTTPS":
return new OrionHttpsInfoService(username, password);

case "ORION (V3) OVER HTTPS LEGACY PRE-2023":
return new OrionLegacyHttpsInfoService(username, password);
}

return null;
Expand Down
32 changes: 31 additions & 1 deletion Src/SwqlStudio/MainForm.Designer.cs

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

10 changes: 10 additions & 0 deletions Src/SwqlStudio/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ private void curlBashToolStripMenuItem_Click(object sender, EventArgs e)
CopyQueryAs(CommandLineGenerator.GetQueryForCurlBash);
}

private void curlCmdToolStripMenuItem1_Click(object sender, EventArgs e)
{
CopyQueryAs(CommandLineGenerator.GetQueryForLegacyCurlCmd);
}

private void curlBashToolStripMenuItem1_Click(object sender, EventArgs e)
{
CopyQueryAs(CommandLineGenerator.GetQueryForLegacyCurlBash);
}

private void getSwisDataPowerShellToolStripMenuItem_Click(object sender, EventArgs e)
{
CopyQueryAs(CommandLineGenerator.GetQueryForPowerShellGetSwisData);
Expand Down
21 changes: 21 additions & 0 deletions Src/SwqlStudio/ProductSpecific/OrionLegacyHttpsInfoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Net;

namespace SwqlStudio
{
internal class OrionLegacyHttpsInfoService : OrionHttpsInfoService
{
static OrionLegacyHttpsInfoService()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = CertificateValidatorWithCache.ValidateRemoteCertificate;
}

public OrionLegacyHttpsInfoService(string username, string password) : base(username, password)
{
}

public override string ServiceType => "Orion over HTTPS legacy pre-2023";

protected override int Port => 17778;
}
}
2 changes: 1 addition & 1 deletion Src/SwqlStudio/Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion Src/SwqlStudio/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Value Profile="(Default)">SolarWinds/InformationService/OrionBasic</Value>
</Setting>
<Setting Name="DefaultInfoServiceHttpsPort" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">17778</Value>
<Value Profile="(Default)">17774</Value>
</Setting>
<Setting Name="NCMForwarderEndpointPath" Type="System.String" Scope="Application">
<Value Profile="(Default)">SolarWinds/InformationService/NCMIntegration/ssl</Value>
Expand Down
2 changes: 1 addition & 1 deletion Src/SwqlStudio/Subscriptions/SubscriptionServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SubscriptionServiceHost(INotificationSubscriber subscriber)
var processId = Process.GetCurrentProcess().Id;
netTcpAddress = string.Format("net.tcp://{0}:17777/SolarWinds/SwqlStudio/{1}", ResolveLocalIPAddress(), processId);

httpAddress = string.Format("https://{0}:17778/SolarWinds/SwqlStudio/{1}", Utility.GetFqdn(), processId);
httpAddress = string.Format("https://{0}:17774/SolarWinds/SwqlStudio/{1}", Utility.GetFqdn(), processId);
}

public bool IsListening()
Expand Down
57 changes: 42 additions & 15 deletions Src/SwqlStudio/Utils/CommandLineGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,47 @@ namespace SwqlStudio.Utils
{
internal static class CommandLineGenerator
{
public const int LegacyRestPort = 17778;
public const int RestPort = 17774;

public static string GetQueryForCurlCmd(string query, ConnectionInfo connection, PropertyBag parameters)
{
return GetQueryForCurlCmdInternal(query, connection, parameters, RestPort);
}

public static string GetQueryForLegacyCurlCmd(string query, ConnectionInfo connection, PropertyBag parameters)
{
return GetQueryForCurlCmdInternal(query, connection, parameters, LegacyRestPort);
}

public static string GetQueryForCurlBash(string query, ConnectionInfo connection, PropertyBag parameters)
{
return GetQueryForCurlBashInternal(query, connection, parameters, RestPort);
}
public static string GetQueryForLegacyCurlBash(string query, ConnectionInfo connection, PropertyBag parameters)
{
return GetQueryForCurlBashInternal(query, connection, parameters, LegacyRestPort);
}

public static string GetQueryForPowerShellGetSwisData(string query, ConnectionInfo connection, PropertyBag parameters)
{
Func<string, string> q = QuoteForPowerShell;
var paramsObjectString = GetParamsObjectInPowershellFormat(parameters);
return $"Get-SwisData (Connect-Swis -Hostname {connection.Server} -Username {q(connection.UserName)} " +
$"-Password {q(connection.Password)}) -Query {q(CollapseWhitespace(query))} -Parameters {paramsObjectString}";
}

private static string GetQueryForCurlCmdInternal(string query, ConnectionInfo connection, PropertyBag parameters, int port)
{
string creds = QuoteForCmd($"{connection.UserName}:{connection.Password}");
if (!parameters.Any())
{
return $"curl.exe -k -u {creds} {GetUrlForQuery(query, connection)}";
return $"curl.exe -k -u {creds} {GetUrlForQuery(query, connection, port)}";
}
else
{
var escapedQuery = CollapseWhitespace(query);
var postUrl = $"https://{connection.Server}:17778/SolarWinds/InformationService/v3/Json/Query";
var postUrl = GetUrlForQuery(null, connection, port);
var parametersSerialized = string.Join(
",",
parameters.Select(x => string.Format("\"{0}\" : \"{1}\"", x.Key, x.Value.ToString())));
Expand All @@ -30,29 +60,21 @@ public static string GetQueryForCurlCmd(string query, ConnectionInfo connection,
}
}

public static string GetQueryForCurlBash(string query, ConnectionInfo connection, PropertyBag parameters)
private static string GetQueryForCurlBashInternal(string query, ConnectionInfo connection, PropertyBag parameters, int port)
{
string creds = $"{connection.UserName}:{connection.Password}";
var url = GetUrlForQuery(query, connection);
var url = GetUrlForQuery(query, connection, port);
Func<string, string> q = QuoteForBash;
if (!parameters.Any())
{
return $"curl -k -u {QuoteForBash(creds)} {QuoteForBash(url)}";
}
else
{
return GetQueryForCurlCmd(query, connection, parameters);
return GetQueryForCurlCmdInternal(query, connection, parameters, port);
}
}

public static string GetQueryForPowerShellGetSwisData(string query, ConnectionInfo connection, PropertyBag parameters)
{
Func<string, string> q = QuoteForPowerShell;
var paramsObjectString = GetParamsObjectInPowershellFormat(parameters);
return $"Get-SwisData (Connect-Swis -Hostname {connection.Server} -Username {q(connection.UserName)} " +
$"-Password {q(connection.Password)}) -Query {q(CollapseWhitespace(query))} -Parameters {paramsObjectString}";
}

private static string GetParamsObjectInPowershellFormat(PropertyBag parameters)
{
var parametersSerialized = string.Join(
Expand All @@ -62,10 +84,15 @@ private static string GetParamsObjectInPowershellFormat(PropertyBag parameters)
return string.Format("@{{{0}}}", parametersSerialized.ToString());
}

private static string GetUrlForQuery(string query, ConnectionInfo connection)
private static string GetUrlForQuery(string query, ConnectionInfo connection, int port)
{
string queryEndpoint = $"https://{connection.Server}:{port}/SolarWinds/InformationService/v3/Json/Query";

if (string.IsNullOrEmpty(query))
return queryEndpoint;

var encodedQuery = HttpUtility.UrlEncode(CollapseWhitespace(query));
return $"https://{connection.Server}:17778/SolarWinds/InformationService/v3/Json/Query?query={encodedQuery}";
return $"{queryEndpoint}?query={encodedQuery}";
}

private static string CollapseWhitespace(string str)
Expand Down
2 changes: 1 addition & 1 deletion Src/SwqlStudio/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<value>SolarWinds/InformationService/OrionBasic</value>
</setting>
<setting name="DefaultInfoServiceHttpsPort" serializeAs="String">
<value>17778</value>
<value>17774</value>
</setting>
<setting name="NCMForwarderEndpointPath" serializeAs="String">
<value>SolarWinds/InformationService/NCMIntegration/ssl</value>
Expand Down

0 comments on commit 14a18a2

Please sign in to comment.