private void ValidateKeyId(string input, ValidationContext <IAccessKey> context) { if (!_inputValidator.TryValidateKeyId(input, out ValidationStatus status, out string?allowed)) { context.AddFailure("Invalid key id: " + ValidationMessages.GetMessage(status, allowed)); } }
private string GetKeyId() { string?enteredKeyId; bool validKeyId = true; Console.WriteLine(); Console.WriteLine("Enter your key id - Example: AKIAIOSFODNN7EXAMPLE"); do { if (!validKeyId) { Console.Error.WriteLine("Invalid key id. Try again."); } enteredKeyId = Console.ReadLine(); if (!string.IsNullOrEmpty(enteredKeyId)) { enteredKeyId = enteredKeyId.Trim(); } } while (!(validKeyId = _inputValidator.TryValidateKeyId(enteredKeyId, out _, out _))); return(enteredKeyId !); }
public static void ValidateKeyIdAndThrow(this IInputValidator validator, string?keyId) { if (validator.TryValidateKeyId(keyId, out ValidationStatus status, out string?message)) { return; } throw new ArgumentException("Invalid key id: " + ValidationMessages.GetMessage(status, message), nameof(keyId)); }