From c51fa0570a5a19b3365d4fd540213a97f936744a Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 15 Feb 2015 09:23:12 -0600 Subject: [PATCH] (GH-52) Rename config confirmation setting Rename `allowInsecureConfirmation` to `allowGlobalConfirmation`. Warn when the feature is turned on. --- src/chocolatey.console/Program.cs | 20 +++++++++++++++-- src/chocolatey/GetChocolatey.cs | 2 +- .../ApplicationParameters.cs | 2 +- .../builders/ConfigurationBuilder.cs | 22 +++++++++++++++---- .../configuration/chocolatey.config | 2 +- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index dfb6a4b8d3..0ce102e286 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -55,7 +55,15 @@ private static void Main(string[] args) var config = container.GetInstance(); var fileSystem = container.GetInstance(); - ConfigurationBuilder.set_up_configuration(args, config, fileSystem, container.GetInstance()); + var warnings = new List(); + + ConfigurationBuilder.set_up_configuration( + args, + config, + fileSystem, + container.GetInstance(), + warning => { warnings.Add(warning); } + ); Config.initialize_with(config); if (config.RegularOuptut) @@ -67,7 +75,15 @@ private static void Main(string[] args) "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1}".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion)); #endif } - + + if (warnings.Count != 0) + { + foreach (var warning in warnings.or_empty_list_if_null()) + { + "chocolatey".Log().Warn(ChocolateyLoggers.Important, warning); + } + } + if (config.HelpRequested) { pause_execution_if_debug(); diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs index d5c19ecfbe..a7b5f67d93 100644 --- a/src/chocolatey/GetChocolatey.cs +++ b/src/chocolatey/GetChocolatey.cs @@ -58,7 +58,7 @@ public GetChocolatey() private void set_defaults() { - ConfigurationBuilder.set_up_configuration(null, _configuration, _fileSystem, _container.GetInstance()); + ConfigurationBuilder.set_up_configuration(null, _configuration, _fileSystem, _container.GetInstance(), null); Config.initialize_with(_configuration); _configuration.PromptForConfirmation = false; diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 121c2d9e40..0b098c18fe 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -70,7 +70,7 @@ public static class Features { public static readonly string CheckSumFiles = "checksumFiles"; public static readonly string AutoUninstaller = "autoUninstaller"; - public static readonly string AllowInsecureConfirmation = "allowInsecureConfirmation"; + public static readonly string AllowGlobalConfirmation = "allowGlobalConfirmation"; } public static class Messages diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 7b062a42aa..51c1ed599e 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -56,14 +56,15 @@ private static IEnvironment Environment /// The configuration. /// The file system. /// The XML service. - public static void set_up_configuration(IList args, ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService) + /// Notify warn logging action + public static void set_up_configuration(IList args, ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action notifyWarnLoggingAction) { - set_file_configuration(config, fileSystem, xmlService); + set_file_configuration(config, fileSystem, xmlService, notifyWarnLoggingAction); set_global_options(args, config); set_environment_options(config); } - private static void set_file_configuration(ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService) + private static void set_file_configuration(ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action notifyWarnLoggingAction) { var globalConfigPath = ApplicationParameters.GlobalConfigFileLocation; AssemblyFileExtractor.extract_text_file_from_assembly(fileSystem, Assembly.GetExecutingAssembly(), ApplicationParameters.ChocolateyConfigFileResource, globalConfigPath); @@ -101,6 +102,19 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile config.CommandExecutionTimeoutSeconds = configFileSettings.CommandExecutionTimeoutSeconds; set_feature_flags(config, configFileSettings); + if (!config.PromptForConfirmation) + { + if (notifyWarnLoggingAction != null) + { + const string logMessage = @" +Config has insecure allowGlobalConfirmation set to true. + This setting lowers the integrity of the security of your system. If + this is not intended, please change the setting using the feature + command. +"; + notifyWarnLoggingAction.Invoke(logMessage); + } + } try { @@ -117,7 +131,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile { config.Features.CheckSumFiles = set_feature_flag(ApplicationParameters.Features.CheckSumFiles, configFileSettings); config.Features.AutoUninstaller = set_feature_flag(ApplicationParameters.Features.AutoUninstaller, configFileSettings); - config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowInsecureConfirmation, configFileSettings); + config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings); } private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings) diff --git a/src/chocolatey/infrastructure.app/configuration/chocolatey.config b/src/chocolatey/infrastructure.app/configuration/chocolatey.config index 712f5d9be0..866e586ce2 100644 --- a/src/chocolatey/infrastructure.app/configuration/chocolatey.config +++ b/src/chocolatey/infrastructure.app/configuration/chocolatey.config @@ -8,6 +8,6 @@ - + \ No newline at end of file