Skip to content

Commit

Permalink
Reimplemented Windows Vault logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromonaco committed Jan 30, 2025
1 parent f76744c commit 667e31c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/DevEx.Console/DevEx.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackAsTool>true</PackAsTool>
<!-- The command users will run -->
<ToolCommandName>dxc</ToolCommandName>
<UserSecretsId>5a2cdd97-0170-4aaa-9816-a59401e8de2b</UserSecretsId>
<UserSecretsId>6b2e2731-a735-438e-bf6f-e749e0ebcd02</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/DevEx.Console/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"DevEx.Console": {
"commandName": "Project",
"commandLineArgs": "vault delete --key \"a\""
"commandLineArgs": "vault delete --key ab"
}
}
}
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}");
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DevEx.Core;
using DevEx.Core.Storage;

namespace DevEx.Modules.Vault.Windows.Handlers
{
Expand All @@ -7,16 +8,20 @@ public class WindowsVaultDeleteCommandHandler : ICommandHandler
{
public void Execute(Dictionary<string, string> options)
{
Console.WriteLine("Executing Vault Delete Command:");
PrintOptions(options);
}
var key = options["key"];

private void PrintOptions(Dictionary<string, string> options)
{
foreach (var option in options)
if (string.IsNullOrWhiteSpace(key))
{
Console.WriteLine($"{option.Key}: {option.Value}");
Console.WriteLine("--key is required for delete.");
return;
}

var userStorage = UserStorageManager.GetUserStorage();
userStorage.Vault.Remove(key);
UserStorageManager.SaveUserStorage(userStorage);
Console.WriteLine($"Deleted item with Key={options["key"]}");
}


}
}
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}");
}
}
}
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}");
}
}
}

0 comments on commit 667e31c

Please sign in to comment.