diff --git a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs index a2057d8e67..d9ec4e9b5d 100644 --- a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs +++ b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs @@ -8,6 +8,10 @@ public class Config { public string InstallationToken { get; set; } public Dictionary CollectorFields { get; set; } + public bool RemotelyManaged { get; set; } + public bool Ephemeral { get; set; } + public string OpAmpFolder { get; set; } + public string Api { get; set; } public Config() { this.CollectorFields = new Dictionary(); diff --git a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs index 502dce6c2b..c655e51fab 100644 --- a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs +++ b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs @@ -53,6 +53,47 @@ public void Update(Config config) collectorFields.Children[field.Key] = field.Value; } } + + if (config.RemotelyManaged) + { + EnsureMapKey(extensions, "opamp"); + YamlMappingNode opamp = (YamlMappingNode)extensions.Children["opamp"]; + EnsureScalarKey(opamp, "remote_configuration_directory"); + opamp.Children["remote_configuration_directory"] = config.OpAmpFolder; + + // Add OpAmp extension to service section + EnsureMapKey(root, "service"); + YamlMappingNode service = (YamlMappingNode)root.Children["service"]; + EnsureSequenceKey(service, "extensions"); + YamlSequenceNode serviceExtensions = (YamlSequenceNode)service.Children["extensions"]; + if (!serviceExtensions.Children.Contains("opamp")) + { + serviceExtensions.Children.Add("opamp"); + } + } + + if (config.Ephemeral) + { + EnsureScalarKey(sumologic, "ephemeral"); + sumologic.Children["ephemeral"] = "true"; + } + + if (!string.IsNullOrEmpty(config.Api)) + { + EnsureScalarKey(sumologic, "api_base_url"); + sumologic.Children["api_base_url"] = config.Api; + } + + // Make sure the sumologic processor node is a map node, otherwise an empty string + // is generated as the value instead of an empty node. + if (root.Children.ContainsKey("processors")) + { + YamlMappingNode processors = (YamlMappingNode)root.Children["processors"]; + if (processors.Children.ContainsKey("sumologic")) + { + EnsureMapKey(processors, "sumologic"); + } + } } public void Save(StreamWriter streamWriter) @@ -100,5 +141,22 @@ private void EnsureScalarKey(YamlMappingNode node, string key) // Add empty YamlScalarNode to key node.Children.Add(key, new YamlScalarNode()); } + + private void EnsureSequenceKey(YamlMappingNode node, string key) + { + if (node.Children.ContainsKey(key)) + { + if (node.Children[key].NodeType == YamlNodeType.Sequence) + { + return; + } + + // TODO: is this how we want to handle incorrect node types? + // YamlNode is wrong type, remove it + node.Children.Remove(key); + } + // Add empty YamlScalarNode to key + node.Children.Add(key, new YamlSequenceNode()); + } } } diff --git a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs index d4d011d2a6..f6d636c0f7 100644 --- a/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs +++ b/packaging/msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text.RegularExpressions; +using System.Windows.Forms; using WixToolset.Dtf.WindowsInstaller; namespace SumoLogic.wixext @@ -13,9 +14,21 @@ public class CustomActions // WiX property names private const string pCommonConfigPath = "CommonConfigPath"; + private const string pSumoLogicConfigPath = "SumoLogicConfigPath"; private const string pInstallationToken = "InstallationToken"; private const string pInstallToken = "InstallToken"; private const string pTags = "Tags"; + private const string pApi = "Api"; + private const string pRemotelyManaged = "RemotelyManaged"; + private const string pEphemeral = "Ephemeral"; + private const string pConfigFolder = "ConfigFolder"; + private const string pOpAmpFolder = "OpAmpFolder"; + private const string pConfigFragmentsFolder = "ConfigFragmentsFolder"; + private const string pServiceArgumentsProperty = "ServiceArgumentsProperty"; + + // WiX features + private const string fEphemeral = "EPHEMERALD"; + private const string fRemotelyManaged = "REMOTELYMANAGED"; [CustomAction] public static ActionResult UpdateConfig(Session session) @@ -41,25 +54,39 @@ public static ActionResult UpdateConfig(Session session) } var commonConfigPath = session.CustomActionData[pCommonConfigPath]; + var sumoLogicConfigPath = session.CustomActionData[pSumoLogicConfigPath]; var tags = session.CustomActionData[pTags]; var installationToken = ""; - if (session.CustomActionData.ContainsKey(pInstallationToken) && session.CustomActionData[pInstallationToken] != "") { + if (session.CustomActionData.ContainsKey(pInstallationToken) && session.CustomActionData[pInstallationToken] != "") + { installationToken = session.CustomActionData[pInstallationToken]; - } else if (session.CustomActionData.ContainsKey(pInstallToken)){ + } + else if (session.CustomActionData.ContainsKey(pInstallToken)) + { installationToken = session.CustomActionData[pInstallToken]; } + 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 api = session.CustomActionData[pApi]; + // Load config from disk and replace values Config config = new Config(); config.InstallationToken = installationToken; config.SetCollectorFieldsFromTags(tags); + config.RemotelyManaged = remotelyManaged; + config.Ephemeral = ephemeral; + config.OpAmpFolder = opAmpFolder; + config.Api = api; + var configFile = remotelyManaged ? sumoLogicConfigPath : commonConfigPath; try { - ConfigUpdater configUpdater = new ConfigUpdater(new StreamReader(commonConfigPath)); + ConfigUpdater configUpdater = new ConfigUpdater(new StreamReader(configFile)); configUpdater.Update(config); - configUpdater.Save(new StreamWriter(commonConfigPath)); + configUpdater.Save(new StreamWriter(configFile)); } catch (Exception e) { @@ -72,6 +99,33 @@ public static ActionResult UpdateConfig(Session session) return ActionResult.Success; } + [CustomAction] + public static ActionResult PopulateServiceArguments(Session session) + { + try + { + var configFolder = session.GetTargetPath(pConfigFolder); + var configFragmentsFolder = session.GetTargetPath(pConfigFragmentsFolder); + var remotelyManaged = session.Features.Contains(fRemotelyManaged) && session.Features[fRemotelyManaged].RequestState == InstallState.Local; + + if (remotelyManaged) + { + session["SERVICEARGUMENTS"] = " --remote-config \"opamp:" + configFolder + "sumologic.yaml\""; + } + else + { + session["SERVICEARGUMENTS"] = " --config \"" + configFolder + "sumologic.yaml\" --config \"glob:" + configFragmentsFolder + "*.yaml\""; + } + } + catch (Exception e) + { + showErrorMessage(session, ecConfigError, e.Message + e.StackTrace); + return ActionResult.Failure; + } + + return ActionResult.Success; + } + private static void showErrorMessage(Session session, short errCode, string key) { Record record = new Record(3); diff --git a/packaging/msi/wix/components.wxs b/packaging/msi/wix/components.wxs index b0cb1e0e69..f09087576f 100644 --- a/packaging/msi/wix/components.wxs +++ b/packaging/msi/wix/components.wxs @@ -70,6 +70,11 @@ + + + + + @@ -84,7 +89,9 @@ - + diff --git a/packaging/msi/wix/folders.wxs b/packaging/msi/wix/folders.wxs index b788da2e70..35d209252b 100644 --- a/packaging/msi/wix/folders.wxs +++ b/packaging/msi/wix/folders.wxs @@ -16,6 +16,7 @@ + diff --git a/packaging/msi/wix/package.wxs b/packaging/msi/wix/package.wxs index 645a76bfbd..4903853990 100644 --- a/packaging/msi/wix/package.wxs +++ b/packaging/msi/wix/package.wxs @@ -74,24 +74,51 @@ + +