Skip to content

Commit

Permalink
(GH-604) Licensed source - ensure config exists
Browse files Browse the repository at this point in the history
When attempting to set configuration for the licensed source, it must
come after the config file has been extracted by default first. This
corrects an issue when running choco the first time after install.
  • Loading branch information
ferventcoder committed Feb 15, 2016
1 parent 7c4519d commit a83d5c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ that chocolatey.licensed.dll exists at
}
var container = SimpleInjectorContainer.Container;

add_or_remove_licensed_source(license, container);

var config = container.GetInstance<ChocolateyConfiguration>();
var fileSystem = container.GetInstance<IFileSystem>();

Expand Down Expand Up @@ -224,37 +222,6 @@ private static void remove_old_chocolatey_exe(IFileSystem fileSystem)
}
}

private static void add_or_remove_licensed_source(ChocolateyLicense license, Container container)
{
var addOrUpdate = license.IsValid;
var config = new ChocolateyConfiguration {
RegularOutput = false,
QuietOutput = true,
};

var sourceService = container.GetInstance<IChocolateyConfigSettingsService>();
var sources = sourceService.source_list(config);

config.SourceCommand.Name = ApplicationParameters.ChocolateyLicensedFeedSourceName;
config.Sources = ApplicationParameters.ChocolateyLicensedFeedSource;
config.SourceCommand.Username = "customer";
config.SourceCommand.Password = license.Id;
config.SourceCommand.Priority = 10;

if (addOrUpdate && !sources.Any(s =>
s.Id.is_equal_to(ApplicationParameters.ChocolateyLicensedFeedSourceName)
&& s.Authenticated)
)
{
sourceService.source_add(config);
}

if (!addOrUpdate)
{
sourceService.source_remove(config);
}
}

private static void pause_execution_if_debug()
{
#if DEBUG
Expand Down
33 changes: 33 additions & 0 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ public static void set_up_configuration(IList<string> args, ChocolateyConfigurat
var fileSystem = container.GetInstance<IFileSystem>();
var xmlService = container.GetInstance<IXmlService>();
var configFileSettings = get_config_file_settings(fileSystem, xmlService);
// must be done prior to setting the file configuration
add_or_remove_licensed_source(license, configFileSettings);
set_file_configuration(config, configFileSettings, fileSystem, notifyWarnLoggingAction);
ConfigurationOptions.reset_options();
set_global_options(args, config, container);
set_environment_options(config);
set_environment_variables(config);
// must be done last for overrides
set_licensed_options(config, license, configFileSettings);
// save all changes if there are any
set_config_file_settings(configFileSettings, xmlService);
}

Expand All @@ -98,6 +101,36 @@ private static void set_config_file_settings(ConfigFileSettings configFileSettin
logWarningInsteadOfError: true);
}

private static void add_or_remove_licensed_source(ChocolateyLicense license, ConfigFileSettings configFileSettings)
{
// do not enable or disable the source, in case the user has disabled it
var addOrUpdate = license.IsValid;
var sources = configFileSettings.Sources.Where(s => !s.Disabled).or_empty_list_if_null().ToList();

var configSource = new ConfigFileSourceSetting
{
Id = ApplicationParameters.ChocolateyLicensedFeedSourceName,
Value = ApplicationParameters.ChocolateyLicensedFeedSource,
UserName = "customer",
Password = NugetEncryptionUtility.EncryptString(license.Id),
Priority = 10
};

if (addOrUpdate && !sources.Any(s =>
s.Id.is_equal_to(ApplicationParameters.ChocolateyLicensedFeedSourceName)
&& NugetEncryptionUtility.DecryptString(s.Password).is_equal_to(license.Id)
)
)
{
configFileSettings.Sources.Add(configSource);
}

if (!addOrUpdate)
{
configFileSettings.Sources.RemoveWhere(s => s.Id.is_equal_to(configSource.Id));
}
}

private static void set_file_configuration(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem, Action<string> notifyWarnLoggingAction)
{
var sources = new StringBuilder();
Expand Down

0 comments on commit a83d5c5

Please sign in to comment.