Skip to content

Commit

Permalink
(GH-584) Build virus check configuration
Browse files Browse the repository at this point in the history
Although virus checking is a pro only feature, add the configuration
hooks to allow for setting default configuration and a feature flip.
  • Loading branch information
ferventcoder committed Jan 30, 2016
1 parent fdc9226 commit 2e2a5a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static class ConfigSettings
public static readonly string Proxy = "proxy";
public static readonly string ProxyUser = "proxyUser";
public static readonly string ProxyPassword = "proxyPassword";
public static readonly string VirusCheckMinimumPositives = "virusCheckMinimumPositives";
}

public static class Features
Expand All @@ -106,6 +107,7 @@ public static class Features
public static readonly string FailOnStandardError = "failOnStandardError";
public static readonly string UsePowerShellHost = "powershellHost";
public static readonly string LogEnvironmentValues = "logEnvironmentValues";
public static readonly string VirusCheck = "virusCheck";
}

public static class Messages
Expand Down
35 changes: 14 additions & 21 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS
config.Proxy.Location = set_config_item(ApplicationParameters.ConfigSettings.Proxy, configFileSettings, string.Empty, "Explicit proxy location.");
config.Proxy.User = set_config_item(ApplicationParameters.ConfigSettings.ProxyUser, configFileSettings, string.Empty, "Optional proxy user.");
config.Proxy.EncryptedPassword = set_config_item(ApplicationParameters.ConfigSettings.ProxyPassword, configFileSettings, string.Empty, "Optional proxy password. Encrypted.");

int minPositives=0;
int.TryParse(set_config_item(ApplicationParameters.ConfigSettings.VirusCheckMinimumPositives, configFileSettings, "5", "Optional proxy password. Encrypted."), out minPositives);
config.VirusCheckMinimumPositives = minPositives == 0 ? 5 : minPositives;
}

private static string set_config_item(string configName, ConfigFileSettings configFileSettings, string defaultValue, string description, bool forceSettingValue = false)
Expand Down Expand Up @@ -196,6 +200,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.FailOnStandardError = set_feature_flag(ApplicationParameters.Features.FailOnStandardError, configFileSettings, defaultEnabled: false, description: "Fail if install provider writes to stderr.");
config.Features.UsePowerShellHost = set_feature_flag(ApplicationParameters.Features.UsePowerShellHost, configFileSettings, defaultEnabled: true, description: "Use Chocolatey's built-in PowerShell host.");
config.Features.LogEnvironmentValues = set_feature_flag(ApplicationParameters.Features.LogEnvironmentValues, configFileSettings, defaultEnabled: false, description: "Log Environment Values - will log values of environment before and after install (could disclose sensitive data).");
config.Features.VirusCheck = set_feature_flag(ApplicationParameters.Features.VirusCheck, configFileSettings, defaultEnabled: false, description: "Virus Check [licensed versions only] - perform virus checking on downloaded files.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down Expand Up @@ -381,20 +386,9 @@ public static void set_environment_variables(ChocolateyConfiguration config)
Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", config.Information.IsProcessElevated ? "true" : "false");
Environment.SetEnvironmentVariable("TEMP", config.CacheLocation);

if (config.Debug)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
}

if (config.Verbose)
{
Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
}

if (!config.Features.CheckSumFiles)
{
Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true");
}
if (config.Debug) Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
if (config.Verbose) Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
if (!config.Features.CheckSumFiles) Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true");

if (!string.IsNullOrWhiteSpace(config.Proxy.Location))
{
Expand All @@ -414,14 +408,13 @@ public static void set_environment_variables(ChocolateyConfiguration config)
Environment.SetEnvironmentVariable("chocolateyProxyLocation", config.Proxy.Location);
}

if (config.Features.UsePowerShellHost)
{
Environment.SetEnvironmentVariable("ChocolateyPowerShellHost", "true");
}

if (config.Information.LicenseIsValid)
if (config.Features.UsePowerShellHost) Environment.SetEnvironmentVariable("ChocolateyPowerShellHost", "true");
if (config.Information.LicenseIsValid) Environment.SetEnvironmentVariable("ChocolateyLicenseValid", "true");
if (config.Force) Environment.SetEnvironmentVariable("ChocolateyForce", "true");
if (config.Features.VirusCheck)
{
Environment.SetEnvironmentVariable("ChocolateyLicenseValid", "true");
Environment.SetEnvironmentVariable("ChocolateyVirusCheckFiles", "true");
Environment.SetEnvironmentVariable("ChocolateyVirusCheckMinimumPositives", config.VirusCheckMinimumPositives.to_string());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ private void append_output(StringBuilder propertyValues, string append)
public bool AllowDowngrade { get; set; }
public bool ForceDependencies { get; set; }

//licensed versions only
public int VirusCheckMinimumPositives { get; set; }

/// <summary>
/// Configuration values provided by choco.
/// </summary>
Expand Down Expand Up @@ -344,6 +347,7 @@ public sealed class FeaturesConfiguration
public bool FailOnStandardError { get; set; }
public bool UsePowerShellHost { get; set; }
public bool LogEnvironmentValues { get; set; }
public bool VirusCheck { get; set; }
}

//todo: retrofit other command configs this way
Expand Down

0 comments on commit 2e2a5a2

Please sign in to comment.