Skip to content

Commit

Permalink
reformated code
Browse files Browse the repository at this point in the history
  • Loading branch information
BeierKevin committed Apr 26, 2024
1 parent 56ef020 commit 9326cf4
Show file tree
Hide file tree
Showing 37 changed files with 273 additions and 139 deletions.
4 changes: 3 additions & 1 deletion src/KeyVaultCli.Application/Cli/Commands/ExitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace KeyVaultCli.Application.Cli.Commands;
public class ExitCommand(IConsole consoleService) : ICommand
{
private readonly string exitPrompt = "Are you sure you want to close the application?";
private readonly string asciiExitingApplication = " _____ _ _ _ _ _ _ _ _ \n | ____|_ _(_) |_(_)_ __ __ _ / \\ _ __ _ __ | (_) ___ __ _| |_(_) ___ _ __ \n | _| \\ \\/ / | __| | '_ \\ / _` | / _ \\ | '_ \\| '_ \\| | |/ __/ _` | __| |/ _ \\| '_ \\ \n | |___ > <| | |_| | | | | (_| | / ___ \\| |_) | |_) | | | (_| (_| | |_| | (_) | | | |\n |_____/_/\\_\\_|\\__|_|_| |_|\\__, | /_/ \\_\\ .__/| .__/|_|_|\\___\\__,_|\\__|_|\\___/|_| |_|\n |___/ |_| |_| ";

private readonly string asciiExitingApplication =
" _____ _ _ _ _ _ _ _ _ \n | ____|_ _(_) |_(_)_ __ __ _ / \\ _ __ _ __ | (_) ___ __ _| |_(_) ___ _ __ \n | _| \\ \\/ / | __| | '_ \\ / _` | / _ \\ | '_ \\| '_ \\| | |/ __/ _` | __| |/ _ \\| '_ \\ \n | |___ > <| | |_| | | | | (_| | / ___ \\| |_) | |_) | | | (_| (_| | |_| | (_) | | | |\n |_____/_/\\_\\_|\\__|_|_| |_|\\__, | /_/ \\_\\ .__/| .__/|_|_|\\___\\__,_|\\__|_|\\___/|_| |_|\n |___/ |_| |_| ";

public void Execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ namespace KeyVaultCli.Application.Common.Interfaces;

public interface IEncryptionService : IVaultEncryptionService
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ namespace KeyVaultCli.Application.Common.Interfaces;

public interface IFileService : IVaultFileService
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ namespace KeyVaultCli.Application.Common.Interfaces;

public interface IPasswordGeneratorService : IVaultPasswordGenerator
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace KeyVaultCli.Application.Common.Interfaces;

public interface IVaultService: IVaultFactory
public interface IVaultService : IVaultFactory
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.CreatePasswordEntry;
public class CreatePasswordCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsole consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly IConsole consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private const string serviceNamePrompt = "Enter service name for the new password: ";
private const string accountNamePrompt = "Enter account name for the new password: ";
Expand Down Expand Up @@ -44,13 +46,14 @@ public void Execute()
var category = consoleService.GetInputFromPrompt(categoryPrompt);

vault.AddPasswordEntry(serviceName, accountName, password, url, category);

consoleService.WriteSuccess(string.Format(successMessage, serviceName, accountName));
}
catch (Exception ex)
{
// Handle or log exception
consoleService.WriteError("An error occurred while trying to create a password entry. Details: " + ex.Message);
consoleService.WriteError("An error occurred while trying to create a password entry. Details: " +
ex.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.CreatePasswordEntry
public class CreatePasswordGenerateCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));


private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string serviceNamePrompt = "Enter service name for the new password: ";
private readonly string accountNamePrompt = "Enter account name for the new password: ";
private readonly string passwordLengthPrompt = "Enter the desired password length: ";
private readonly string urlPrompt = "Enter the URL (leave empty if not applicable): ";
private readonly string categoryPrompt = "Enter the category (leave empty if not applicable): ";
private readonly string invalidLengthError = "Invalid input for password length. Ensure you enter a valid number.";
private readonly string successMessage = "A new password has been created and stored for {0}, {1} with the value {2}.";

private readonly string invalidLengthError =
"Invalid input for password length. Ensure you enter a valid number.";

private readonly string successMessage =
"A new password has been created and stored for {0}, {1} with the value {2}.";

public void Execute()
{
Expand Down Expand Up @@ -44,7 +50,8 @@ public void Execute()
var url = consoleService.GetInputFromPrompt(urlPrompt);
var category = consoleService.GetInputFromPrompt(categoryPrompt);

var password = vault.GenerateAndAddPasswordEntry(serviceName, accountName, passwordLength, url, category);
var password =
vault.GenerateAndAddPasswordEntry(serviceName, accountName, passwordLength, url, category);
if (string.IsNullOrEmpty(password))
{
consoleService.WriteError("The password was not generated. Please retry the operation.");
Expand All @@ -53,13 +60,14 @@ public void Execute()

consoleService.WriteSuccess(string.Format(successMessage, serviceName, accountName, password));
}
catch(Exception ex)
catch (Exception ex)
{
// Log or display the precise error message
consoleService.WriteError("An error occurred while trying to generate a password. Details: " + ex.Message);
consoleService.WriteError("An error occurred while trying to generate a password. Details: " +
ex.Message);
}
}

private int GetPasswordLength()
{
var passwordLengthStr = consoleService.GetInputFromPrompt(passwordLengthPrompt);
Expand All @@ -68,6 +76,7 @@ private int GetPasswordLength()
consoleService.WriteError(invalidLengthError);
return -1;
}

return passwordLength;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.DeletePasswordEntry
public class DeleteAllPasswordsCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));


private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string confirmationPrompt = "Are you sure you want to delete all passwords?";
private readonly string successMessage = "All passwords have been deleted.";
private readonly string errorMessage = "Operation cancelled.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.DeletePasswordEntry;
public class DeletePasswordCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string serviceNamePrompt = "Enter the service name for the password you want to delete: ";
private readonly string accountNamePrompt = "Enter the account name for the password you want to delete: ";
private readonly string successMessage = "Password entry has been deleted.";
private readonly string errorMessage = "Failed to delete the password entry. Ensure the service and account names are correct.";

private readonly string errorMessage =
"Failed to delete the password entry. Ensure the service and account names are correct.";

public void Execute()
{
Expand Down Expand Up @@ -42,10 +46,11 @@ public void Execute()
consoleService.WriteError(errorMessage);
}
}
catch(Exception ex)
catch (Exception ex)
{
// Handle or log the precise error message
consoleService.WriteError("An error occurred while trying to delete a password entry. Details: " + ex.Message);
consoleService.WriteError("An error occurred while trying to delete a password entry. Details: " +
ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class GetPasswordCommand : ICommand
private readonly string errorEmptyInputMessage = "Service name and account name cannot be empty.";
private readonly string passwordInfoMessage = "Information for {0}, {1}:";
private readonly string passwordNotFoundMessage = "No password entry found for service {0}, account {1}.";
private readonly string warningMessage = "This password is not healthy. A healthy password should be at least 8 characters long, contain at least one uppercase letter, one lowercase letter, one digit and be unique inside this Vault.";

private readonly string warningMessage =
"This password is not healthy. A healthy password should be at least 8 characters long, contain at least one uppercase letter, one lowercase letter, one digit and be unique inside this Vault.";

private readonly string passwordHealthyMessage = "This password is healthy.";

public GetPasswordCommand(IVault vault, IConsoleService consoleService)
Expand Down Expand Up @@ -53,9 +56,10 @@ public void Execute()
consoleService.WriteError(string.Format(passwordNotFoundMessage, serviceName, accountName));
}
}
catch(Exception ex)
catch (Exception ex)
{
consoleService.WriteError($"An error occurred while trying to execute the command. Details: {ex.Message}");
consoleService.WriteError(
$"An error occurred while trying to execute the command. Details: {ex.Message}");
}
}

Expand All @@ -69,7 +73,8 @@ private string GetAccountName()
return consoleService.GetInputFromPrompt(accountNamePrompt);
}

private void WritePasswordInfo(Domain.Entities.PasswordEntry passwordEntry, string serviceName, string accountName)
private void WritePasswordInfo(Domain.Entities.PasswordEntry passwordEntry, string serviceName,
string accountName)
{
var decryptedPassword = vault.GetPassword(serviceName, accountName);
var passwordHealthResult = passwordHealthService.CheckPasswordHealthAsync(decryptedPassword).Result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.GetPasswordEntry
public class SearchPasswordEntriesCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));


private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string searchPrompt = "Enter your search query: ";
private readonly string matchingEntriesMessage = "Matching search entries:";
private readonly string noEntriesFoundError = "No matching entries found.";
private readonly string[] headers = { "GUID", "Service Name", "AccountName", "Password (Decrypted)", "URL", "Category", "Creation Date", "Last Modified Date", };

private readonly string[] headers =
{
"GUID", "Service Name", "AccountName", "Password (Decrypted)", "URL", "Category", "Creation Date",
"Last Modified Date",
};

public void Execute()
{
Expand All @@ -35,13 +42,14 @@ public void Execute()
consoleService.WriteError(noEntriesFoundError);
}
}
catch(Exception ex)
catch (Exception ex)
{
consoleService.WriteError($"An error occurred: {ex.Message}");
}
}

private List<List<object>> GetMatchingEntriesDataRows(IEnumerable<Domain.Entities.PasswordEntry> matchingEntries)
private List<List<object>> GetMatchingEntriesDataRows(
IEnumerable<Domain.Entities.PasswordEntry> matchingEntries)
{
return matchingEntries
.Where(entry => entry != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.UpdatePasswordEntry
public class UpdateMasterPasswordCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string oldPasswordPrompt = "Enter current master password: ";
private readonly string newPasswordPrompt = "Enter new master password: ";
Expand All @@ -30,9 +32,10 @@ public void Execute()
consoleService.WriteError(errorMessage);
}
}
catch(Exception ex)
catch (Exception ex)
{
consoleService.WriteError($"An error occurred while trying to update the master password. Details: {ex.Message}");
consoleService.WriteError(
$"An error occurred while trying to update the master password. Details: {ex.Message}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace KeyVaultCli.Application.PasswordEntry.Commands.UpdatePasswordEntry
public class UpdatePasswordCommand(IVault vault, IConsoleService consoleService) : ICommand
{
private readonly IVault vault = vault ?? throw new ArgumentNullException(nameof(vault));
private readonly IConsoleService consoleService = consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly IConsoleService consoleService =
consoleService ?? throw new ArgumentNullException(nameof(consoleService));

private readonly string currentServiceNamePrompt = "Enter current service name: ";
private readonly string currentAccountNamePrompt = "Enter current account name: ";
Expand All @@ -17,7 +19,9 @@ public class UpdatePasswordCommand(IVault vault, IConsoleService consoleService)
private readonly string newUrlPrompt = "Enter new URL: ";
private readonly string newCategoryPrompt = "Enter new Category: ";
private readonly string successMessage = "The password entry has been updated.";
private readonly string errorMessage = "Failed to update the password entry. Ensure the service and account exists.";

private readonly string errorMessage =
"Failed to update the password entry. Ensure the service and account exists.";

public void Execute()
{
Expand All @@ -31,7 +35,8 @@ public void Execute()
var newUrl = consoleService.GetInputFromPrompt(newUrlPrompt);
var newCategory = consoleService.GetInputFromPrompt(newCategoryPrompt);

if (vault.UpdatePasswordEntry(currentServiceName, currentAccountName, newServiceName, newAccountName, newPassword.Length, newPassword, newUrl, newCategory))
if (vault.UpdatePasswordEntry(currentServiceName, currentAccountName, newServiceName, newAccountName,
newPassword.Length, newPassword, newUrl, newCategory))
{
consoleService.WriteSuccess(successMessage);
}
Expand All @@ -42,7 +47,8 @@ public void Execute()
}
catch (Exception ex)
{
consoleService.WriteError($"An error occurred while trying to update the password entry. Details: {ex.Message}");
consoleService.WriteError(
$"An error occurred while trying to update the password entry. Details: {ex.Message}");
}
}
}
Expand Down
Loading

0 comments on commit 9326cf4

Please sign in to comment.