Skip to content

Commit 2933ffd

Browse files
committed
code_style: rename SystemCredentialManager to SystemKeychain
This is because there is already a similar property `Native.OS.CredentialHelper` Signed-off-by: leo <longshuang@msn.cn>
1 parent 85ec979 commit 2933ffd

6 files changed

Lines changed: 23 additions & 23 deletions

File tree

‎src/AI/ApiKey.cs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SourceGit.AI
1111
public enum ApiKeyStorage
1212
{
1313
EnvironmentVariable = 0,
14-
SystemCredentialManager,
14+
SystemKeychain,
1515
PlainText,
1616
}
1717

@@ -28,7 +28,7 @@ public ApiKeyStorage Storage
2828
get => _storage;
2929
set
3030
{
31-
if (SetProperty(ref _storage, value) && value == ApiKeyStorage.SystemCredentialManager)
31+
if (SetProperty(ref _storage, value) && value == ApiKeyStorage.SystemKeychain)
3232
OnPropertyChanged(nameof(IsValidStorage));
3333
}
3434
}
@@ -44,25 +44,25 @@ public bool IsValidStorage
4444
{
4545
get
4646
{
47-
if (_storage == ApiKeyStorage.SystemCredentialManager)
48-
return Native.OS.CredentialStorage != null;
47+
if (_storage == ApiKeyStorage.SystemKeychain)
48+
return Native.OS.Keychain != null;
4949
return true;
5050
}
5151
}
5252

5353
public void PrepareForSaving()
5454
{
55-
if (Storage == ApiKeyStorage.SystemCredentialManager)
55+
if (Storage == ApiKeyStorage.SystemKeychain)
5656
{
57-
Native.OS.CredentialStorage?.Store(Service, "SourceGit", KeyToAccess);
57+
Native.OS.Keychain?.Store(Service, "SourceGit", KeyToAccess);
5858
KeyToAccess = string.Empty;
5959
}
6060
}
6161

6262
public void Cleanup()
6363
{
64-
if (Storage == ApiKeyStorage.SystemCredentialManager)
65-
Native.OS.CredentialStorage?.Erase(Service, "SourceGit");
64+
if (Storage == ApiKeyStorage.SystemKeychain)
65+
Native.OS.Keychain?.Erase(Service, "SourceGit");
6666
}
6767

6868
public ApiKey CreateEditObject()
@@ -73,8 +73,8 @@ public ApiKey CreateEditObject()
7373
Storage = _storage,
7474
};
7575

76-
if (_storage == ApiKeyStorage.SystemCredentialManager)
77-
cloned.KeyToAccess = Native.OS.CredentialStorage?.Read(Service, "SourceGit") ?? string.Empty;
76+
if (_storage == ApiKeyStorage.SystemKeychain)
77+
cloned.KeyToAccess = Native.OS.Keychain?.Read(Service, "SourceGit") ?? string.Empty;
7878
else
7979
cloned.KeyToAccess = _keyToAccess;
8080

@@ -89,7 +89,7 @@ public ApiKeyCredential ToCredential()
8989
if (_storage == ApiKeyStorage.EnvironmentVariable)
9090
return new ApiKeyCredential(Environment.GetEnvironmentVariable(_keyToAccess));
9191

92-
var rawApiKey = Native.OS.CredentialStorage?.Read(Service, "SourceGit");
92+
var rawApiKey = Native.OS.Keychain?.Read(Service, "SourceGit");
9393
return new ApiKeyCredential(rawApiKey ?? string.Empty);
9494
}
9595

‎src/Native/Linux.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void TerminateProcess(Process proc)
207207
}
208208
}
209209

210-
public OS.ICredentialStorage CreateCredentialStorage()
210+
public OS.IKeychain GetSecretTool()
211211
{
212212
var toolPath = FindExecutable("secret-tool");
213213
if (string.IsNullOrEmpty(toolPath))
@@ -216,7 +216,7 @@ public OS.ICredentialStorage CreateCredentialStorage()
216216
if (!File.Exists(toolPath))
217217
return null;
218218

219-
return new LinuxCredentialStorage(toolPath);
219+
return new SecretTool(toolPath);
220220
}
221221

222222
private string FindExecutable(string filename)
@@ -245,9 +245,9 @@ private string GetXdgDirectory(string envVar, string fallback, string subDirName
245245
}
246246

247247
[SupportedOSPlatform("linux")]
248-
public class LinuxCredentialStorage : OS.ICredentialStorage
248+
public class SecretTool : OS.IKeychain
249249
{
250-
public LinuxCredentialStorage(string toolPath)
250+
public SecretTool(string toolPath)
251251
{
252252
_toolPath = toolPath;
253253
}

‎src/Native/MacOS.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public static void ShowAllApplications()
347347
}
348348

349349
[SupportedOSPlatform("macOS")]
350-
public class MacOSCredentialStorage : OS.ICredentialStorage
350+
public class MacOSKeychain : OS.IKeychain
351351
{
352352
[DllImport("/System/Library/Frameworks/Security.framework/Security")]
353353
private static extern int SecKeychainAddGenericPassword(

‎src/Native/OS.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface IBackend
4040
void TerminateProcess(Process proc);
4141
}
4242

43-
public interface ICredentialStorage
43+
public interface IKeychain
4444
{
4545
void Store(string host, string username, string password);
4646
string Read(string host, string username);
@@ -138,7 +138,7 @@ public static bool UseSystemWindowFrame
138138
set => _enableSystemWindowFrame = value;
139139
}
140140

141-
public static ICredentialStorage CredentialStorage
141+
public static IKeychain Keychain
142142
{
143143
get;
144144
private set;
@@ -149,18 +149,18 @@ static OS()
149149
if (OperatingSystem.IsWindows())
150150
{
151151
_backend = new Windows();
152-
CredentialStorage = new WindowsCredentialStorage();
152+
Keychain = new WindowsCredentialManager();
153153
}
154154
else if (OperatingSystem.IsMacOS())
155155
{
156156
_backend = new MacOS();
157-
CredentialStorage = new MacOSCredentialStorage();
157+
Keychain = new MacOSKeychain();
158158
}
159159
else if (OperatingSystem.IsLinux())
160160
{
161161
var impl = new Linux();
162162
_backend = impl;
163-
CredentialStorage = impl.CreateCredentialStorage();
163+
Keychain = impl.GetSecretTool();
164164
}
165165
else
166166
{

‎src/Native/Windows.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public static void FixWindowFrame(Window w)
474474
}
475475

476476
[SupportedOSPlatform("windows")]
477-
public class WindowsCredentialStorage : OS.ICredentialStorage
477+
public class WindowsCredentialManager : OS.IKeychain
478478
{
479479
[DllImport("Advapi32.dll", EntryPoint = "CredWriteW", CharSet = CharSet.Unicode, SetLastError = true)]
480480
private static extern bool CredWriteW([In] ref CREDENTIAL userCredential, [In] uint flags);

‎src/Views/EditApiKey.axaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.EditApiKey.Storage}"/>
4949
<ComboBox Margin="0,4,0,0" Height="28" HorizontalAlignment="Stretch" SelectedIndex="{Binding Storage, Mode=TwoWay}">
5050
<ComboBoxItem Content="Environment Variable"/>
51-
<ComboBoxItem Content="System Crendential Manager"/>
51+
<ComboBoxItem Content="System Keychain"/>
5252
<ComboBoxItem Content="Plain Text"/>
5353
</ComboBox>
5454

0 commit comments

Comments
 (0)