Ejemplo n.º 1
0
 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));
     }
 }
Ejemplo n.º 2
0
    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 !);
    }
Ejemplo n.º 3
0
    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));
    }