Task IConfigurableComponent.UnconfigureAsync(ConfigurationTarget target) { string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; string appPath = GetGitConfigAppPath(); IGitConfiguration config; switch (target) { case ConfigurationTarget.User: // For per-user configuration, we are looking for the following to be set in the global config: // // [credential] // ... # any number of helper entries (possibly none) // helper = # an empty value to reset/clear any previous entries (if applicable) // helper = {appPath} # the expected executable value & directly following the empty value // ... # any number of helper entries (possibly none) // // We should remove the {appPath} entry, and any blank entries immediately preceding IFF there are no more entries following. // Context.Trace.WriteLine("Removing Git credential helper user configuration..."); config = Context.Git.GetConfiguration(GitConfigurationLevel.Global); string[] currentValues = config.GetRegex(helperKey, Constants.RegexPatterns.Any).ToArray(); int appIndex = Array.FindIndex(currentValues, x => Context.FileSystem.IsSamePath(x, appPath)); if (appIndex > -1) { // Check for the presence of a blank entry immediately preceding an app entry in the last position if (appIndex > 0 && appIndex == currentValues.Length - 1 && string.IsNullOrWhiteSpace(currentValues[appIndex - 1])) { // Clear the blank entry config.UnsetAll(helperKey, Constants.RegexPatterns.Empty); } // Clear app entry config.UnsetAll(helperKey, Regex.Escape(appPath)); } break; case ConfigurationTarget.System: // For machine-wide configuration, we are looking for the following to be set in the system config: // // [credential] // helper = {appPath} // // We should remove the {appPath} entry if it exists. // Context.Trace.WriteLine("Removing Git credential helper system configuration..."); config = Context.Git.GetConfiguration(GitConfigurationLevel.System); config.UnsetAll(helperKey, Regex.Escape(appPath)); break; default: throw new ArgumentOutOfRangeException(nameof(target), target, "Unknown configuration target."); } return(Task.CompletedTask); }
public async Task UnconfigureAsync(ConfigurationTarget target) { foreach (IConfigurableComponent component in _components) { _context.Trace.WriteLine($"Unconfiguring component '{component.Name}'..."); _context.Streams.Error.WriteLine($"Unconfiguring component '{component.Name}'..."); await component.UnconfigureAsync(target); } }
public Task UnconfigureAsync(ConfigurationTarget target) { string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}"; _context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com..."); GitConfigurationLevel configurationLevel = target == ConfigurationTarget.System ? GitConfigurationLevel.System : GitConfigurationLevel.Global; IGitConfiguration targetConfig = _context.Git.GetConfiguration(configurationLevel); targetConfig.Unset(useHttpPathKey); return(Task.CompletedTask); }
Task IConfigurableComponent.ConfigureAsync(ConfigurationTarget target) { string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; string appPath = GetGitConfigAppPath(); GitConfigurationLevel configLevel = target == ConfigurationTarget.System ? GitConfigurationLevel.System : GitConfigurationLevel.Global; Context.Trace.WriteLine($"Configuring for config level '{configLevel}'."); IGitConfiguration config = Context.Git.GetConfiguration(configLevel); // We are looking for the following to be set in the config: // // [credential] // ... # any number of helper entries (possibly none) // helper = # an empty value to reset/clear any previous entries (if applicable) // helper = {appPath} # the expected executable value & directly following the empty value // ... # any number of helper entries (possibly none, but not the empty value '') // string[] currentValues = config.GetAll(helperKey).ToArray(); // Try to locate an existing app entry with a blank reset/clear entry immediately preceding, // and no other blank empty/clear entries following (which effectively disable us). int appIndex = Array.FindIndex(currentValues, x => Context.FileSystem.IsSamePath(x, appPath)); int lastEmptyIndex = Array.FindLastIndex(currentValues, string.IsNullOrWhiteSpace); if (appIndex > 0 && string.IsNullOrWhiteSpace(currentValues[appIndex - 1]) && lastEmptyIndex < appIndex) { Context.Trace.WriteLine("Credential helper configuration is already set correctly."); } else { Context.Trace.WriteLine("Updating Git credential helper configuration..."); // Clear any existing app entries in the configuration config.UnsetAll(helperKey, Regex.Escape(appPath)); // Add an empty value for `credential.helper`, which has the effect of clearing any helper value // from any lower-level Git configuration, then add a second value which is the actual executable path. config.Add(helperKey, string.Empty); config.Add(helperKey, appPath); } return(Task.CompletedTask); }
Task IConfigurableComponent.UnconfigureAsync(ConfigurationTarget target) { string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; string appPath = GetGitConfigAppPath(); GitConfigurationLevel configLevel = target == ConfigurationTarget.System ? GitConfigurationLevel.System : GitConfigurationLevel.Global; Context.Trace.WriteLine($"Unconfiguring for config level '{configLevel}'."); IGitConfiguration config = Context.Git.GetConfiguration(configLevel); // We are looking for the following to be set in the config: // // [credential] // ... # any number of helper entries (possibly none) // helper = # an empty value to reset/clear any previous entries (if applicable) // helper = {appPath} # the expected executable value & directly following the empty value // ... # any number of helper entries (possibly none) // // We should remove the {appPath} entry, and any blank entries immediately preceding IFF there are no more entries following. // Context.Trace.WriteLine("Removing Git credential helper configuration..."); string[] currentValues = config.GetAll(helperKey).ToArray(); int appIndex = Array.FindIndex(currentValues, x => Context.FileSystem.IsSamePath(x, appPath)); if (appIndex > -1) { // Check for the presence of a blank entry immediately preceding an app entry in the last position if (appIndex > 0 && appIndex == currentValues.Length - 1 && string.IsNullOrWhiteSpace(currentValues[appIndex - 1])) { // Clear the blank entry config.UnsetAll(helperKey, Constants.RegexPatterns.Empty); } // Clear app entry config.UnsetAll(helperKey, Regex.Escape(appPath)); } return(Task.CompletedTask); }
private async Task RunAsync(ConfigurationTarget target, bool configure) { GitConfigurationLevel configLevel; EnvironmentVariableTarget envTarget; switch (target) { case ConfigurationTarget.User: configLevel = GitConfigurationLevel.Global; envTarget = EnvironmentVariableTarget.User; break; case ConfigurationTarget.System: configLevel = GitConfigurationLevel.System; envTarget = EnvironmentVariableTarget.Machine; break; default: throw new ArgumentOutOfRangeException(nameof(target)); } using (IGitConfiguration config = _context.Git.GetConfiguration()) { foreach (IConfigurableComponent component in _components) { if (configure) { _context.Trace.WriteLine($"Configuring component '{component.Name}'..."); _context.Streams.Error.WriteLine($"Configuring component '{component.Name}'..."); await component.ConfigureAsync(_context.Environment, envTarget, config, configLevel); } else { _context.Trace.WriteLine($"Unconfiguring component '{component.Name}'..."); _context.Streams.Error.WriteLine($"Unconfiguring component '{component.Name}'..."); await component.UnconfigureAsync(_context.Environment, envTarget, config, configLevel); } } } }
public Task ConfigureAsync(ConfigurationTarget target) { string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}"; GitConfigurationLevel configurationLevel = target == ConfigurationTarget.System ? GitConfigurationLevel.System : GitConfigurationLevel.Global; IGitConfiguration targetConfig = _context.Git.GetConfiguration(); if (targetConfig.TryGet(useHttpPathKey, false, out string currentValue) && currentValue.IsTruthy()) { _context.Trace.WriteLine("Git configuration 'credential.useHttpPath' is already set to 'true' for https://dev.azure.com."); } else { _context.Trace.WriteLine("Setting Git configuration 'credential.useHttpPath' to 'true' for https://dev.azure.com..."); targetConfig.Set(configurationLevel, useHttpPathKey, "true"); } return(Task.CompletedTask); }
public Task UnconfigureAsync(ConfigurationTarget target) { string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}"; _context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com..."); GitConfigurationLevel configurationLevel = target == ConfigurationTarget.System ? GitConfigurationLevel.System : GitConfigurationLevel.Global; IGitConfiguration targetConfig = _context.Git.GetConfiguration(); // On Windows, if there is a "manager-core" entry remaining in the system config then we must not clear // the useHttpPath option otherwise this would break the bundled version of GCM in Git for Windows. if (!PlatformUtils.IsWindows() || target != ConfigurationTarget.System || targetConfig.GetAll(helperKey).All(x => !string.Equals(x, "manager-core"))) { targetConfig.Unset(configurationLevel, useHttpPathKey); } return(Task.CompletedTask); }
public Task UnconfigureAsync(ConfigurationTarget target) => RunAsync(target, false);
public Task ConfigureAsync(ConfigurationTarget target) => RunAsync(target, true);
protected override Task ExecuteInternalAsync(ConfigurationTarget target) { return(ConfigurationService.UnconfigureAsync(target)); }
protected abstract Task ExecuteInternalAsync(ConfigurationTarget target);
Task IConfigurableComponent.ConfigureAsync(ConfigurationTarget target) { string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; string appPath = GetGitConfigAppPath(); IGitConfiguration config; switch (target) { case ConfigurationTarget.User: // For per-user configuration, we are looking for the following to be set in the global config: // // [credential] // ... # any number of helper entries (possibly none) // helper = # an empty value to reset/clear any previous entries (if applicable) // helper = {appPath} # the expected executable value & directly following the empty value // ... # any number of helper entries (possibly none) // config = Context.Git.GetConfiguration(GitConfigurationLevel.Global); string[] currentValues = config.GetRegex(helperKey, Constants.RegexPatterns.Any).ToArray(); // Try to locate an existing app entry with a blank reset/clear entry immediately preceding int appIndex = Array.FindIndex(currentValues, x => Context.FileSystem.IsSamePath(x, appPath)); if (appIndex > 0 && string.IsNullOrWhiteSpace(currentValues[appIndex - 1])) { Context.Trace.WriteLine("Credential helper user configuration is already set correctly."); } else { Context.Trace.WriteLine("Updating Git credential helper user configuration..."); // Clear any existing app entries in the configuration config.UnsetAll(helperKey, Regex.Escape(appPath)); // Add an empty value for `credential.helper`, which has the effect of clearing any helper value // from any lower-level Git configuration, then add a second value which is the actual executable path. config.ReplaceAll(helperKey, Constants.RegexPatterns.None, string.Empty); config.ReplaceAll(helperKey, Constants.RegexPatterns.None, appPath); } break; case ConfigurationTarget.System: // For machine-wide configuration, we are looking for the following to be set in the system config: // // [credential] // helper = {appPath} // config = Context.Git.GetConfiguration(GitConfigurationLevel.System); string currentValue = config.GetValue(helperKey); if (Context.FileSystem.IsSamePath(currentValue, appPath)) { Context.Trace.WriteLine("Credential helper system configuration is already set correctly."); } else { Context.Trace.WriteLine("Updating Git credential helper system configuration..."); config.SetValue(helperKey, appPath); } break; default: throw new ArgumentOutOfRangeException(nameof(target), target, "Unknown configuration target."); } return(Task.CompletedTask); }