Class: Assumer::MFA

Inherits:
Object
  • Object
show all
Defined in:
lib/mfa.rb

Overview

A class to manage methods of obtaining OTP codes for MFA

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#otpObject (readonly)

Returns the value of attribute otp.



5
6
7
# File 'lib/mfa.rb', line 5

def otp
  @otp
end

Instance Method Details

#request_one_time_codeString

A method to prompt for the user’s OTP MFA code on the CLI

Returns:

  • (String)

    The MFA code entered by the user



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mfa.rb', line 9

def request_one_time_code
  until @otp =~ /\d{6}/
    print 'Enter MFA: '
    $stdout.flush
    @otp = $stdin.gets(7).chomp
    $stderr.puts 'MFA code should be 6 digits' if @otp !~ /\d{6}/
  end
  @otp # return the MFA code
rescue SystemExit, Interrupt
  exit 0
end