Skip to content

Commit

Permalink
(chocolateyGH-596) Allow failure on invalid license
Browse files Browse the repository at this point in the history
Add feature that allows users to know when a license is invalid,
expired, or missing from a machine.
  • Loading branch information
ferventcoder committed Apr 9, 2016
1 parent 1140679 commit a377b0e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static class Features
public static readonly string UsePowerShellHost = "powershellHost";
public static readonly string LogEnvironmentValues = "logEnvironmentValues";
public static readonly string VirusCheck = "virusCheck";
public static readonly string FailOnInvalidOrMissingLicense = "failOnInvalidOrMissingLicense";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
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.Features.FailOnInvalidOrMissingLicense = set_feature_flag(ApplicationParameters.Features.FailOnInvalidOrMissingLicense, configFileSettings, defaultEnabled: false, description: "Fail On Invalid Or Missing License - allows knowing when a license is expired or not applied to a machine.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public sealed class FeaturesConfiguration
public bool UsePowerShellHost { get; set; }
public bool LogEnvironmentValues { get; set; }
public bool VirusCheck { get; set; }
public bool FailOnInvalidOrMissingLicense { get; set; }
}

//todo: retrofit other command configs this way
Expand Down
13 changes: 13 additions & 0 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,17 @@ private void set_source_type(ChocolateyConfiguration config)
this.Log().Debug(()=> "The source '{0}' evaluated to a '{1}' source type".format_with(config.Sources,sourceType.to_string()));
}

public void fail_when_license_is_missing_or_invalid_if_requested(ChocolateyConfiguration config)
{
if (!config.Features.FailOnInvalidOrMissingLicense) return;

if (!config.Information.IsLicensedVersion) throw new ApplicationException("License is missing or invalid.");
}

public void run(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs);
if(command != null)
{
Expand All @@ -134,6 +143,8 @@ public void run(ChocolateyConfiguration config, Container container, bool isCons

public IEnumerable<T> list<T>(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs) as IListCommand<T>;
if (command == null)
{
Expand All @@ -152,6 +163,8 @@ public IEnumerable<T> list<T>(ChocolateyConfiguration config, Container containe

public int count(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
{
fail_when_license_is_missing_or_invalid_if_requested(config);

var command = find_command(config, container, isConsole, parseArgs) as IListCommand;
if (command == null)
{
Expand Down

0 comments on commit a377b0e

Please sign in to comment.