Module: Yubikey::Configuration

Included in:
Yubikey
Defined in:
lib/yubikey/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Yubikey::OTP::Verify

[
  :api_id,
  :url,
  :api_key,
  :certificate_chain,
].freeze
DEFAULT_API_URL =

By default, we want to point to Yubicloud

'https://api.yubico.com/wsapi/2.0/'
DEFAULT_API_ID =

By default, don't have an api_id

nil
DEFAULT_API_KEY =

By default, don't have an api_key

nil
DEFAULT_CERTIFICATE_CHAIN =

Default location of the Yubico certificate chain

File.join(File.dirname(__FILE__), '../cert/chain.pem')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values


28
29
30
# File 'lib/yubikey/configuration.rb', line 28

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:


33
34
35
# File 'lib/yubikey/configuration.rb', line 33

def configure
  yield self
end

#optionsObject

Create a hash of options and their values


38
39
40
41
42
# File 'lib/yubikey/configuration.rb', line 38

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to defaults


45
46
47
48
49
50
# File 'lib/yubikey/configuration.rb', line 45

def reset
  self.api_id            = DEFAULT_API_ID
  self.url               = DEFAULT_API_URL
  self.api_key           = DEFAULT_API_KEY
  self.certificate_chain = DEFAULT_CERTIFICATE_CHAIN
end