Skip to content

Commit f20d75b

Browse files
committed
make compatible with .NET Framework
1 parent b4db44a commit f20d75b

17 files changed

+75
-22
lines changed

src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,7 @@ public void Dispose()
473473
_restApiRegistry.Dispose();
474474
_bitbucketAuth.Dispose();
475475
}
476+
477+
public Task<bool> ValidateCredentialAsync(Uri remoteUri, ICredential credential) => Task.FromResult(credential.PasswordExpiry == null || credential.PasswordExpiry >= DateTimeOffset.UtcNow);
476478
}
477479
}

src/shared/Core/Credential.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public interface ICredential
2323
/// The expiry date of the password. This is Git's password_expiry_utc
2424
/// attribute. https://git-scm.com/docs/git-credential#Documentation/git-credential.txt-codepasswordexpiryutccode
2525
/// </summary>
26-
DateTimeOffset? PasswordExpiry { get => null; }
26+
DateTimeOffset? PasswordExpiry { get; }
2727

2828
/// <summary>
2929
/// An OAuth refresh token. This is Git's oauth_refresh_token
3030
/// attribute. https://git-scm.com/docs/git-credential#Documentation/git-credential.txt-codeoauthrefreshtokencode
3131
/// </summary>
32-
string OAuthRefreshToken { get => null; }
32+
string OAuthRefreshToken { get; }
3333
}
3434

3535
/// <summary>
@@ -63,12 +63,12 @@ public GitCredential(OAuth2TokenResult tokenResult, string userName)
6363
}
6464
}
6565

66-
public string Account { get; init; }
66+
public string Account { get; set; }
6767

68-
public string Password { get; init; }
68+
public string Password { get; set; }
6969

70-
public DateTimeOffset? PasswordExpiry { get; init; }
70+
public DateTimeOffset? PasswordExpiry { get; set; }
7171

72-
public string OAuthRefreshToken { get; init; }
72+
public string OAuthRefreshToken { get; set; }
7373
}
7474
}

src/shared/Core/FileCredential.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace GitCredentialManager
24
{
35
public class FileCredential : ICredential
@@ -17,5 +19,9 @@ public FileCredential(string fullPath, string service, string account, string pa
1719
public string Account { get; }
1820

1921
public string Password { get; }
22+
23+
public DateTimeOffset? PasswordExpiry => null;
24+
25+
public string OAuthRefreshToken => null;
2026
}
2127
}

src/shared/Core/HostProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public interface IHostProvider : IDisposable
5959
/// <param name="input">Input arguments of a Git credential query.</param>
6060
Task EraseCredentialAsync(InputArguments input);
6161

62-
Task<bool> ValidateCredentialAsync(Uri remoteUri, ICredential credential)
63-
=> Task.FromResult(credential.PasswordExpiry == null || credential.PasswordExpiry >= DateTimeOffset.UtcNow);
62+
Task<bool> ValidateCredentialAsync(Uri remoteUri, ICredential credential);
63+
// => Task.FromResult(credential.PasswordExpiry == null || credential.PasswordExpiry >= DateTimeOffset.UtcNow);
6464
}
6565

6666
/// <summary>

src/shared/Core/ICredentialStore.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public interface ICredentialStore
3232
// [Obsolete("Prefer AddOrUpdate(string, ICredential)")]
3333
void AddOrUpdate(string service, string account, string secret);
3434

35-
void AddOrUpdate(string service, ICredential credential)
36-
=> AddOrUpdate(service, credential.Account, credential.Password);
35+
void AddOrUpdate(string service, ICredential credential);
3736

3837
/// <summary>
3938
/// Delete credential from the store that matches the given query.
@@ -44,10 +43,9 @@ void AddOrUpdate(string service, ICredential credential)
4443
// [Obsolete("Prefer Remove(string, ICredential)")]
4544
bool Remove(string service, string account);
4645

47-
bool Remove(string service, ICredential credential)
48-
=> Remove(service, credential.Account);
46+
bool Remove(string service, ICredential credential);
4947

50-
bool CanStorePasswordExpiry => false;
51-
bool CanStoreOAuthRefreshToken => false;
48+
bool CanStorePasswordExpiry { get; }
49+
bool CanStoreOAuthRefreshToken { get; }
5250
}
5351
}

src/shared/Core/InputArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public InputArguments(IDictionary<string, IList<string>> dict)
3939
/// Return a copy of input, with additional OAuth refresh token.
4040
/// </summary>
4141
public InputArguments(InputArguments input, string oauthRefreshToken) {
42-
_dict = new Dictionary<string, IList<string>>(input._dict)
42+
_dict = new Dictionary<string, IList<string>>(input._dict.ToDictionary(p => p.Key, p => p.Value))
4343
{
4444
["oauth_refresh_token"] = new List<string>() { oauthRefreshToken }
4545
};

src/shared/Core/Interop/Linux/SecretServiceCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private static unsafe ICredential CreateCredentialFromItem(SecretItem* item)
315315
string oauth_refresh_token = null;
316316
DateTimeOffset? password_expiry_utc = null;
317317
for(int i = 1; i < lines.Length; i++) {
318-
var parts = lines[i].Split('=', 2);
318+
var parts = lines[i].Split(['='], 2);
319319
if (parts.Length != 2)
320320
continue;
321321
if (parts[0] == "oauth_refresh_token")
@@ -395,6 +395,8 @@ private static SecretSchema GetSchema()
395395
return schema;
396396
}
397397

398+
public bool Remove(string service, ICredential credential) => Remove(service, credential.Account);
399+
398400
public bool CanStorePasswordExpiry => true;
399401
public bool CanStoreOAuthRefreshToken => true;
400402
}

src/shared/Core/Interop/Linux/SecretServiceCredential.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ internal SecretServiceCredential(string service, string account, string password
1818

1919
public string Password { get; }
2020

21-
public string OAuthRefreshToken { get; init; }
21+
public string OAuthRefreshToken { get; set; }
2222

23-
public DateTimeOffset? PasswordExpiry { get; init; }
23+
public DateTimeOffset? PasswordExpiry { get; set; }
2424
}
2525
}

src/shared/Core/Interop/MacOS/MacOSKeychain.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class MacOSKeychain : ICredentialStore
1414
{
1515
private readonly string _namespace;
1616

17+
public bool CanStorePasswordExpiry => false;
18+
19+
public bool CanStoreOAuthRefreshToken => false;
20+
1721
#region Constructors
1822

1923
/// <summary>
@@ -348,5 +352,8 @@ private string CreateServiceName(string service)
348352
sb.Append(service);
349353
return sb.ToString();
350354
}
355+
356+
public void AddOrUpdate(string service, ICredential credential) => AddOrUpdate(service, credential.Account, credential.Password);
357+
public bool Remove(string service, ICredential credential) => Remove(service, credential.Account);
351358
}
352359
}

src/shared/Core/Interop/MacOS/MacOSKeychainCredential.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Diagnostics;
23

34
namespace GitCredentialManager.Interop.MacOS
@@ -21,6 +22,10 @@ internal MacOSKeychainCredential(string service, string account, string password
2122

2223
public string Password { get; }
2324

25+
public DateTimeOffset? PasswordExpiry => null;
26+
27+
public string OAuthRefreshToken => null;
28+
2429
private string DebuggerDisplay => $"{Label} [Service: {Service}, Account: {Account}]";
2530
}
2631
}

0 commit comments

Comments
 (0)