-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76744c
commit 667e31c
Showing
6 changed files
with
50 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 14 additions & 7 deletions
21
src/DevEx.Modules/DevEx.Modules.Vault/Windows/Handlers/WindowsVaultCreateCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
using DevEx.Core; | ||
using DevEx.Core.Storage; | ||
|
||
namespace DevEx.Modules.Vault.Windows.Handlers | ||
{ | ||
public class WindowsVaultCreateCommandHandler : ICommandHandler | ||
{ | ||
public void Execute(Dictionary<string, string> options) | ||
{ | ||
Console.WriteLine("Executing Vault Create Command:"); | ||
PrintOptions(options); | ||
} | ||
var key = options["key"]; | ||
var value = options["value"]; | ||
|
||
private void PrintOptions(Dictionary<string, string> options) | ||
{ | ||
foreach (var option in options) | ||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) | ||
{ | ||
Console.WriteLine($"{option.Key}: {option.Value}"); | ||
Console.WriteLine("Both --key and --value are required for create."); | ||
return; | ||
} | ||
|
||
var userStorage = UserStorageManager.GetUserStorage(); | ||
value = WindowsVaultHelper.Encrypt(value); | ||
userStorage.Vault.Add(key, value); | ||
UserStorageManager.SaveUserStorage(userStorage); | ||
|
||
Console.WriteLine($"Created item: Key={key}, New Value={value}"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
src/DevEx.Modules/DevEx.Modules.Vault/Windows/Handlers/WindowsVaultReadCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
using DevEx.Core; | ||
using DevEx.Core.Storage; | ||
|
||
namespace DevEx.Modules.Vault.Windows.Handlers | ||
{ | ||
public class WindowsVaultReadCommandHandler : ICommandHandler | ||
{ | ||
public void Execute(Dictionary<string, string> options) | ||
{ | ||
Console.WriteLine("Executing Vault Read Command:"); | ||
PrintOptions(options); | ||
} | ||
|
||
private void PrintOptions(Dictionary<string, string> options) | ||
{ | ||
foreach (var option in options) | ||
var key = options["key"]; | ||
if (string.IsNullOrWhiteSpace(key)) | ||
{ | ||
Console.WriteLine($"{option.Key}: {option.Value}"); | ||
Console.WriteLine("--key is required for read."); | ||
return; | ||
} | ||
|
||
var userStorage = UserStorageManager.GetUserStorage(); | ||
var value = userStorage.Vault.FirstOrDefault(v => v.Key.Equals(key)).Value; | ||
value = WindowsVaultHelper.Decrypt(value); | ||
Console.WriteLine($"Fetched item with Key={options["key"]} and Value={value}"); | ||
} | ||
} | ||
} |
19 changes: 12 additions & 7 deletions
19
src/DevEx.Modules/DevEx.Modules.Vault/Windows/Handlers/WindowsVaultUpdateCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
using DevEx.Core; | ||
using DevEx.Core.Storage; | ||
|
||
namespace DevEx.Modules.Vault.Windows.Handlers | ||
{ | ||
public class WindowsVaultUpdateCommandHandler : ICommandHandler | ||
{ | ||
public void Execute(Dictionary<string, string> options) | ||
{ | ||
Console.WriteLine("Executing Vault Update Command:"); | ||
PrintOptions(options); | ||
} | ||
var key = options["key"]; | ||
var value = options["value"]; | ||
|
||
private void PrintOptions(Dictionary<string, string> options) | ||
{ | ||
foreach (var option in options) | ||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value)) | ||
{ | ||
Console.WriteLine($"{option.Key}: {option.Value}"); | ||
Console.WriteLine("Both --key and --value are required for modify."); | ||
return; | ||
} | ||
|
||
var userStorage = UserStorageManager.GetUserStorage(); | ||
userStorage.Vault[key] = WindowsVaultHelper.Encrypt(value); | ||
UserStorageManager.SaveUserStorage(userStorage); | ||
|
||
Console.WriteLine($"Modified item: Key={key}, New Value={value}"); | ||
} | ||
} | ||
} |