Пример #1
0
        Task IConfigurableComponent.UnconfigureAsync(
            IEnvironment environment, EnvironmentVariableTarget environmentTarget,
            IGitConfiguration configuration, GitConfigurationLevel configurationLevel)
        {
            string helperKey        = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
            string gitConfigAppName = GetGitConfigAppName();

            using (IGitConfiguration targetConfig = configuration.GetFilteredConfiguration(configurationLevel))
            {
                Context.Trace.WriteLine("Removing Git credential helper configuration...");

                // Clear any blank 'reset' entries
                targetConfig.DeleteMultivarEntry(helperKey, Constants.RegexPatterns.Empty);

                // Clear GCM executable entries
                targetConfig.DeleteMultivarEntry(helperKey, Regex.Escape(gitConfigAppName));
            }

            // NOTE: We currently only update the PATH in Windows installations and leave removing the GCM executable
            //       on the PATH on other platform to their installers.
            // Remove GCM executable from the PATH
            if (PlatformUtils.IsWindows())
            {
                Context.Trace.WriteLine("Removing application from the PATH...");
                string directoryPath = Path.GetDirectoryName(_appPath);
                environment.RemoveDirectoryFromPath(directoryPath, environmentTarget);
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        Task IConfigurableComponent.ConfigureAsync(
            IEnvironment environment, EnvironmentVariableTarget environmentTarget,
            IGitConfiguration configuration, GitConfigurationLevel configurationLevel)
        {
            // NOTE: We currently only update the PATH in Windows installations and leave putting the GCM executable
            //       on the PATH on other platform to their installers.
            if (PlatformUtils.IsWindows())
            {
                string directoryPath = Path.GetDirectoryName(_appPath);
                if (!environment.IsDirectoryOnPath(directoryPath))
                {
                    Context.Trace.WriteLine("Adding application to PATH...");
                    environment.AddDirectoryToPath(directoryPath, environmentTarget);
                }
                else
                {
                    Context.Trace.WriteLine("Application is already on the PATH.");
                }
            }

            string helperKey        = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
            string gitConfigAppName = GetGitConfigAppName();

            using (IGitConfiguration targetConfig = configuration.GetFilteredConfiguration(configurationLevel))
            {
                /*
                 * We are looking for the following to be considered already set:
                 *
                 * [credential]
                 *     ...                         # any number of helper entries
                 *     helper =                    # an empty value to reset/clear any previous entries
                 *     helper = {gitConfigAppName} # the expected executable value in the last position & directly following the empty value
                 *
                 */

                string[] currentValues = targetConfig.GetMultivarValue(helperKey, Constants.RegexPatterns.Any).ToArray();
                if (currentValues.Length < 2 ||
                    !string.IsNullOrWhiteSpace(currentValues[currentValues.Length - 2]) ||    // second to last entry is empty
                    currentValues[currentValues.Length - 1] != gitConfigAppName)              // last entry is the expected executable
                {
                    Context.Trace.WriteLine("Updating Git credential helper configuration...");

                    // Clear any existing entries in the configuration.
                    targetConfig.DeleteMultivarEntry(helperKey, Constants.RegexPatterns.Any);

                    // 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.
                    targetConfig.SetValue(helperKey, string.Empty);
                    targetConfig.SetMultivarValue(helperKey, Constants.RegexPatterns.None, gitConfigAppName);
                }
                else
                {
                    Context.Trace.WriteLine("Credential helper configuration is already set correctly.");
                }
            }

            return(Task.CompletedTask);
        }
Пример #3
0
        public Task UnconfigureAsync(
            IEnvironment environment, EnvironmentVariableTarget environmentTarget,
            IGitConfiguration configuration, GitConfigurationLevel configurationLevel)
        {
            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...");

            using (IGitConfiguration targetConfig = configuration.GetFilteredConfiguration(configurationLevel))
            {
                targetConfig.DeleteEntry(useHttpPathKey);
            }

            return(Task.CompletedTask);
        }
Пример #4
0
        public Task ConfigureAsync(
            IEnvironment environment, EnvironmentVariableTarget environmentTarget,
            IGitConfiguration configuration, GitConfigurationLevel configurationLevel)
        {
            string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}";

            using (IGitConfiguration targetConfig = configuration.GetFilteredConfiguration(configurationLevel))
            {
                if (targetConfig.TryGetValue(useHttpPathKey, 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.SetValue(useHttpPathKey, "true");
                }
            }

            return(Task.CompletedTask);
        }