From 242073a1293874a7afed681ac2386c1b7a4083ca Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Mon, 8 Mar 2021 12:02:30 +0000 Subject: [PATCH] azrepos: add cmd to clear the authority cache Add a command to enable clearing of the Azure authority cache manually. --- docs/usage.md | 5 ++++ .../AzureReposHostProvider.cs | 28 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index 567457b4e..699aeb481 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -30,3 +30,8 @@ Read the [Git manual](https://git-scm.com/docs/gitcredentials#_custom_helpers) a Set your user-level Git configuration (`~/.gitconfig`) to use GCM Core. If you pass `--system` to these commands, they act on the system-level Git configuration (`/etc/gitconfig`) instead. + +### azure-repos (experimental) + +Interact with the Azure Repos host provider to manage the authentication +authority cache. diff --git a/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs b/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs index cfc8e5607..5b8a6f409 100644 --- a/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs +++ b/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. using System; using System.Collections.Generic; +using System.CommandLine; +using System.CommandLine.Invocation; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -12,7 +14,7 @@ namespace Microsoft.AzureRepos { - public class AzureReposHostProvider : DisposableObject, IHostProvider, IConfigurableComponent + public class AzureReposHostProvider : DisposableObject, IHostProvider, IConfigurableComponent, ICommandProvider { private readonly ICommandContext _context; private readonly IAzureDevOpsRestApi _azDevOps; @@ -452,5 +454,29 @@ public Task UnconfigureAsync(ConfigurationTarget target) } #endregion + + #region ICommandProvider + + ProviderCommand ICommandProvider.CreateCommand() + { + var clearCacheCmd = new Command("clear-cache") + { + Description = "Clear the Azure authority cache", + Handler = CommandHandler.Create(ClearCacheCmd), + }; + + var rootCmd = new ProviderCommand(this); + rootCmd.AddCommand(clearCacheCmd); + return rootCmd; + } + + private int ClearCacheCmd() + { + _authorityCache.Clear(); + _context.Streams.Out.WriteLine("Authority cache cleared"); + return 0; + } + + #endregion } }