Skip to content

Commit

Permalink
use factory to create instances
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkb7 committed Jan 9, 2025
1 parent 4295354 commit 74eff82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
using System;
using System.Linq;

namespace WixSetup.Datadog_Agent
{
internal static class AgentFlavorFactory
{
public static Type[] GetAllAgentFlavors()
private const string FipsFlavor = "fips";
private const string BaseFlavor = "base";

public static string[] GetAllAgentFlavors()
{
return typeof(AgentFlavorFactory).Assembly.GetTypes()
.Where(t => typeof(IAgentFlavor).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract)
.ToArray();
return new[]
{
BaseFlavor,
FipsFlavor
};
}

public static IAgentFlavor New(AgentVersion agentVersion)
{
var flavor = Environment.GetEnvironmentVariable("AGENT_FLAVOR");
return New(flavor, agentVersion);
}

public static IAgentFlavor New(string flavor, AgentVersion agentVersion)
{
return flavor switch
{
"fips" => new FIPSAgent(agentVersion),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public Project Configure()
// to prevent them from being installed side-by-side.
foreach (var flavorType in AgentFlavorFactory.GetAllAgentFlavors())
{
var flavor = (IAgentFlavor)Activator.CreateInstance(flavorType, _agentVersion);
IAgentFlavor flavor = AgentFlavorFactory.New(flavorType, _agentVersion);
if (flavor.UpgradeCode == _agentFlavor.UpgradeCode)
{
continue;
Expand Down

0 comments on commit 74eff82

Please sign in to comment.