# frozen_string_literal: true class TOTPService Error = Class.new(StandardError) class < e Rails.logger.error { e } raise Error, '2FA server is under maintenance' if e.message.include?('connection refused') raise Error, 'This code was already used. Wait until the next time period' if e.message.include?('code already used') raise e end def totp_key(uid) "totp/keys/#{Vault.application}_#{uid}" end def totp_code_key(uid) "totp/code/#{Vault.application}_#{uid}" end def read_data(key) with_human_error do vault.read(key) end end def read_code(uid) read_data(totp_code_key(uid)).data[:code] end def write_data(key, params) with_human_error do vault.write(key, params) end end def delete_data(key) with_human_error do vault.delete(key) end end def vault Vault.logical end end end