Class: Gem::GemcutterUtilities::WebauthnPoller
- Inherits:
 - 
      Object
      
        
- Object
 - Gem::GemcutterUtilities::WebauthnPoller
 
 
- Includes:
 - Gem::GemcutterUtilities
 
- Defined in:
 - lib/rubygems/gemcutter_utilities/webauthn_poller.rb
 
Constant Summary collapse
- TIMEOUT_IN_SECONDS =
 300
Constants included from Gem::GemcutterUtilities
Instance Attribute Summary collapse
- 
  
    
      #host  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute host.
 - 
  
    
      #options  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute options.
 
Attributes included from Gem::GemcutterUtilities
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #initialize(options, host)  ⇒ WebauthnPoller 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of WebauthnPoller.
 - #poll_for_otp(webauthn_url, credentials) ⇒ Object
 
Methods included from Gem::GemcutterUtilities
#add_key_option, #add_otp_option, #api_key, #mfa_unauthorized?, #otp, #rubygems_api_request, #set_api_key, #sign_in, #update_scope, #verify_api_key, #with_response
Methods included from Text
#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text
Constructor Details
#initialize(options, host) ⇒ WebauthnPoller
Returns a new instance of WebauthnPoller.
      29 30 31 32  | 
    
      # File 'lib/rubygems/gemcutter_utilities/webauthn_poller.rb', line 29 def initialize(, host) @options = @host = host end  | 
  
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
      27 28 29  | 
    
      # File 'lib/rubygems/gemcutter_utilities/webauthn_poller.rb', line 27 def host @host end  | 
  
#options ⇒ Object (readonly)
Returns the value of attribute options.
      27 28 29  | 
    
      # File 'lib/rubygems/gemcutter_utilities/webauthn_poller.rb', line 27 def @options end  | 
  
Class Method Details
.poll_thread(options, host, webauthn_url, credentials) ⇒ Object
      34 35 36 37 38 39 40 41 42 43  | 
    
      # File 'lib/rubygems/gemcutter_utilities/webauthn_poller.rb', line 34 def self.poll_thread(, host, webauthn_url, credentials) Thread.new do thread = Thread.current thread.abort_on_exception = true thread.report_on_exception = false thread[:otp] = new(, host).poll_for_otp(webauthn_url, credentials) rescue Gem::WebauthnVerificationError, Timeout::Error => e thread[:error] = e end end  | 
  
Instance Method Details
#poll_for_otp(webauthn_url, credentials) ⇒ Object
      45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63  | 
    
      # File 'lib/rubygems/gemcutter_utilities/webauthn_poller.rb', line 45 def poll_for_otp(webauthn_url, credentials) Timeout.timeout(TIMEOUT_IN_SECONDS) do loop do response = webauthn_verification_poll_response(webauthn_url, credentials) raise Gem::WebauthnVerificationError, response. unless response.is_a?(Net::HTTPSuccess) require "json" parsed_response = JSON.parse(response.body) case parsed_response["status"] when "pending" sleep 5 when "success" return parsed_response["code"] else raise Gem::WebauthnVerificationError, parsed_response.fetch("message", "Invalid response from server") end end end end  |