Skip to content

Commit

Permalink
azrepos: add cmd to clear the authority cache
Browse files Browse the repository at this point in the history
Add a command to enable clearing of the Azure authority cache manually.
  • Loading branch information
mjcheetham committed Mar 9, 2021
1 parent 8e351df commit 242073a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
28 changes: 27 additions & 1 deletion src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
}

0 comments on commit 242073a

Please sign in to comment.