4
4
5
5
namespace GitCredentialManager ;
6
6
7
+ public interface ICredentialManager : ICredentialStore
8
+ {
9
+ ICommandContext Context { get ; }
10
+ }
11
+
7
12
/// <summary>
8
13
/// Provides the factory method <see cref="Create"/> to instantiate a
9
14
/// <see cref="ICredentialStore"/> appropriate for the current platform and
@@ -21,11 +26,21 @@ public static class CredentialManager
21
26
/// </summary>
22
27
/// <param name="namespace">Optional namespace to scope credential operations.</param>
23
28
/// <returns>The <see cref="ICredentialStore"/>.</returns>
24
- public static ICredentialStore Create ( string ? @namespace = default )
29
+ public static ICredentialManager Create ( string ? @namespace = default )
25
30
{
26
31
// The context already does the check for the platform and configured store to initialize.
27
32
// By overriding the settings with our wrapper, we ensure just the namespace is overriden.
28
- return new CredentialStore ( new CommandContextWrapper ( new CommandContext ( ) , @namespace ) ) ;
33
+ var context = new CommandContextWrapper ( new CommandContext ( ) , @namespace ) ;
34
+ return new CredentialManagerStore ( new CredentialStore ( context ) , context ) ;
35
+ }
36
+
37
+ class CredentialManagerStore ( ICredentialStore store , ICommandContext context ) : ICredentialManager
38
+ {
39
+ public ICommandContext Context => context ;
40
+ public void AddOrUpdate ( string service , string account , string secret ) => store . AddOrUpdate ( service , account , secret ) ;
41
+ public ICredential Get ( string service , string account ) => store . Get ( service , account ) ;
42
+ public IList < string > GetAccounts ( string service ) => store . GetAccounts ( service ) ;
43
+ public bool Remove ( string service , string account ) => store . Remove ( service , account ) ;
29
44
}
30
45
31
46
class CommandContextWrapper ( CommandContext context , string ? @namespace ) : ICommandContext
0 commit comments