Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): add -OpAmpApi option to install.ps1 #73

Merged
merged 15 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion install-script/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ param (
[bool] $Ephemeral,

# The API URL used to communicate with the SumoLogic backend
[string] $Api
[string] $Api,
rnishtala-sumo marked this conversation as resolved.
Show resolved Hide resolved

# The OpAmp Endpoint used to communicate with the OpAmp backend
[string] $OpAmpApi
)

$PackageGithubOrg = "SumoLogic"
Expand Down Expand Up @@ -516,6 +519,9 @@ try {
}
if ($RemotelyManaged -eq $true) {
$msiAddLocal += "REMOTELYMANAGED"
if ($OpAmpApi.Length -gt 0) {
$msiProperties += "OPAMPAPI=`"${OpAmpApi}`""
}
}
if ($Ephemeral -eq $true) {
$msiAddLocal += "EPHEMERAL"
Expand Down
1 change: 1 addition & 0 deletions msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Config
public bool Ephemeral { get; set; }
public string OpAmpFolder { get; set; }
public string Api { get; set; }
public string OpAmpApi { get; set; }

public Config() {
this.CollectorFields = new Dictionary<string, string>();
Expand Down
6 changes: 6 additions & 0 deletions msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public void Update(Config config)
EnsureScalarKey(opamp, "remote_configuration_directory");
opamp.Children["remote_configuration_directory"] = config.OpAmpFolder;

if (!string.IsNullOrEmpty(config.OpAmpApi))
{
EnsureScalarKey(opamp, "endpoint");
opamp.Children["endpoint"] = config.OpAmpApi;
}

// Add OpAmp extension to service section
EnsureMapKey(root, "service");
YamlMappingNode service = (YamlMappingNode)root.Children["service"];
Expand Down
4 changes: 3 additions & 1 deletion msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CustomActions
private const string pEphemeral = "Ephemeral";
private const string pConfigFolder = "ConfigFolder";
private const string pOpAmpFolder = "OpAmpFolder";
private const string pOpAmpApi = "OpAmpApi";
private const string pConfigFragmentsFolder = "ConfigFragmentsFolder";

// WiX features
Expand Down Expand Up @@ -68,6 +69,7 @@ public static ActionResult UpdateConfig(Session session)
var remotelyManaged = (session.CustomActionData.ContainsKey(pRemotelyManaged) && session.CustomActionData[pRemotelyManaged] == "true");
var ephemeral = (session.CustomActionData.ContainsKey(pEphemeral) && session.CustomActionData[pEphemeral] == "true");
var opAmpFolder = session.CustomActionData[pOpAmpFolder];
var opAmpApi = session.CustomActionData[pOpAmpApi];
var api = session.CustomActionData[pApi];

if (remotelyManaged && string.IsNullOrEmpty(opAmpFolder))
Expand All @@ -78,7 +80,7 @@ public static ActionResult UpdateConfig(Session session)

// Load config from disk and replace values
Config config = new Config { InstallationToken = installationToken, RemotelyManaged = remotelyManaged, Ephemeral = ephemeral,
OpAmpFolder = opAmpFolder, Api = api };
OpAmpFolder = opAmpFolder, OpAmpApi = opAmpApi, Api = api };
config.SetCollectorFieldsFromTags(tags);

var configFile = remotelyManaged ? sumoLogicConfigPath : commonConfigPath;
Expand Down
48 changes: 48 additions & 0 deletions msi/SumoLogic.wixext/SumoLogicTests/ConfigUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ public void ApiAssertions(Config config, StreamReader sr)
Assert.AreEqual(config.Api, apiBaseUrl.ToString());
}

public void OpAmpApiAssertions(Config config, StreamReader sr)
{
YamlStream ys = new YamlStream();
ys.Load(sr);
YamlMappingNode root = (YamlMappingNode)ys.Documents[0].RootNode;

Assert.IsTrue(root.Children.ContainsKey("extensions"));
Assert.AreEqual(YamlNodeType.Mapping, root.Children["extensions"].NodeType);
var extensions = (YamlMappingNode)root.Children["extensions"];

Assert.IsTrue(extensions.Children.ContainsKey("opamp"));
Assert.AreEqual(YamlNodeType.Mapping, extensions.Children["opamp"].NodeType);
var opamp = (YamlMappingNode)extensions.Children["opamp"];

Assert.IsTrue(opamp.Children.ContainsKey("endpoint"));
Assert.AreEqual(YamlNodeType.Scalar, opamp.Children["endpoint"].NodeType);
var endpoint = (YamlScalarNode)opamp.Children["endpoint"];
Assert.AreEqual(config.OpAmpApi, endpoint.ToString());
}

[TestMethod]
public void TestUpdate_WithExtensionsBlock()
{
Expand Down Expand Up @@ -406,5 +426,33 @@ public void TestUpdate_Api()
ApiAssertions(config, sr);
}
}

[TestMethod]
public void TestUpdate_OpAmpApi()
{
var filePath = Path.Combine(testDataPath, "with-extensions-block.yaml");
var config = new Config { InstallationToken = "foobar", RemotelyManaged = true, OpAmpApi = "http://opampapiurl.local", OpAmpFolder = "/opamp" };
config.SetCollectorFieldsFromTags(@"foo=bar,baz=kaz,xaz=yaz");

using (MemoryStream ms = new MemoryStream())
{
var configUpdater = new ConfigUpdater(new StreamReader(filePath));
configUpdater.Update(config);
configUpdater.Save(new StreamWriter(ms));

ms.Seek(0, SeekOrigin.Begin);

StreamReader sr = new StreamReader(ms);
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}

ms.Seek(0, SeekOrigin.Begin);

OpAmpApiAssertions(config, sr);
}
}

}
}
5 changes: 4 additions & 1 deletion msi/wix/package.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<!-- The API base URL if overriden -->
<Property Id="API" Hidden="yes" />

<!-- The OpAmp UrL if overriden -->
<Property Id="OPAMPAPI" Hidden="yes" />

<!-- UI Properties -->
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />

Expand All @@ -99,7 +102,7 @@
<CustomAction Id="UpdateConfigActionData1" Property="UpdateConfigAction1"
Value="CommonConfigPath=[ConfigFragmentsFolder]common.yaml;SumoLogicConfigPath=[ConfigFolder]sumologic.yaml;InstallToken=[INSTALLTOKEN];InstallationToken=[INSTALLATIONTOKEN]" />
<CustomAction Id="UpdateConfigActionData2" Property="UpdateConfigAction2"
Value="Tags=[TAGS];OpAmpFolder=[OpAmpFolder];Ephemeral=[EPHEMERALSELECTED];RemotelyManaged=[REMOTELYMANAGEDSELECTED];Api=[API]" />
Value="Tags=[TAGS];OpAmpFolder=[OpAmpFolder];OpAmpApi=[OPAMPAPI];Ephemeral=[EPHEMERALSELECTED];RemotelyManaged=[REMOTELYMANAGEDSELECTED];Api=[API]" />
<CustomAction Id="UpdateConfigActionData" Property="UpdateConfigAction" Value="[UpdateConfigAction1];[UpdateConfigAction2]" />

<!-- Before updating the config files set the properties indicating whether or not the remotely managed and ephemeral features are selected -->
Expand Down
Loading