Module: Awskeyring::Validate

Defined in:
lib/awskeyring/validate.rb

Overview

Validation methods for Awskeyring

Class Method Summary collapse

Class Method Details

.access_key(aws_access_key) ⇒ Object

Validate an AWS Access Key ID

Parameters:

  • aws_access_key (String)

    The aws_access_key_id



22
23
24
25
26
# File 'lib/awskeyring/validate.rb', line 22

def self.access_key(aws_access_key)
  raise 'Invalid Access Key' unless /\AAKIA[A-Z234567]{16}\z/.match?(aws_access_key)

  aws_access_key
end

.account_name(account_name) ⇒ Object

Validate an account name

Parameters:

  • account_name (String)

    the associated account name.



13
14
15
16
17
# File 'lib/awskeyring/validate.rb', line 13

def self.()
  raise 'Invalid Account Name' unless /\S+/.match?()

  
end

.mfa_arn(mfa_arn) ⇒ Object

Validate an Users mfa ARN

Parameters:

  • mfa_arn (String)

    The users MFA arn



44
45
46
47
48
# File 'lib/awskeyring/validate.rb', line 44

def self.mfa_arn(mfa_arn)
  raise 'Invalid MFA ARN' unless %r(\Aarn:aws:iam::[0-9]{12}:mfa/\S*\z).match?(mfa_arn)

  mfa_arn
end

.mfa_code(mfa_code) ⇒ Object

Validate an MFA CODE

Parameters:

  • mfa_code (String)

    The mfa code



71
72
73
74
75
# File 'lib/awskeyring/validate.rb', line 71

def self.mfa_code(mfa_code)
  raise 'Invalid MFA CODE' unless /\A\d{6}\z/.match?(mfa_code)

  mfa_code
end

.role_arn(role_arn) ⇒ Object

Validate a Role ARN

Parameters:

  • role_arn (String)

    The role arn



62
63
64
65
66
# File 'lib/awskeyring/validate.rb', line 62

def self.role_arn(role_arn)
  raise 'Invalid Role ARN' unless %r(\Aarn:aws:iam::[0-9]{12}:role/\S*\z).match?(role_arn)

  role_arn
end

.role_name(role_name) ⇒ Object

Validate a Role name

Parameters:

  • role_name (String)


53
54
55
56
57
# File 'lib/awskeyring/validate.rb', line 53

def self.role_name(role_name)
  raise 'Invalid Role Name' unless /\S+/.match?(role_name)

  role_name
end

.secret_access_key(aws_secret_access_key) ⇒ Object

Validate an AWS Secret Key ID

Parameters:

  • aws_secret_access_key (String)

    The aws_secret_access_key



31
32
33
34
35
36
37
38
39
# File 'lib/awskeyring/validate.rb', line 31

def self.secret_access_key(aws_secret_access_key)
  begin
    raise 'Invalid Secret Access Key' unless Base64.strict_decode64(aws_secret_access_key).length == 30
  rescue ArgumentError
    raise 'Invalid Secret Access Key'
  end

  aws_secret_access_key
end