Module: Istox::Vault

Defined in:
lib/istox/helpers/vault.rb

Defined Under Namespace

Modules: TOTP

Class Method Summary collapse

Class Method Details

.get_otp(sid, host) ⇒ Object



77
78
79
80
# File 'lib/istox/helpers/vault.rb', line 77

def get_otp(sid, host)
  ::Istox::Vault::TOTP.create(sid, host)
  Istox::Vault::TOTP.generate_code(sid)
end

.initialize(secret_key, file_location) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/istox/helpers/vault.rb', line 62

def initialize(secret_key, file_location)
  ::Vault.configure do |config|
    config.address = secret_key

    if File.exist?(file_location)
      token = File.read(file_location).strip
      config.token = token
      config.ssl_verify = false
      config.timeout = 60
    else
      Rails.logger.info 'Vault token not found, OTP will not be able to use'
    end
  end
end

.logicalObject



58
59
60
# File 'lib/istox/helpers/vault.rb', line 58

def logical
  ::Vault.logical
end

.validate_otp(sid, otp) ⇒ Object



82
83
84
85
86
87
# File 'lib/istox/helpers/vault.rb', line 82

def validate_otp(sid, otp)
  return ::Istox::Vault::TOTP.validate?(sid, otp)
rescue => e
  raise e
  false
end