module Opendistro::Configuration
Defines constants and methods related to configuration.
Constants
- DEFAULT_USER_AGENT
The user agent that will be sent to the
API
endpoint if none is set.- DEFAULT_VERIFY_SSL
- VALID_OPTIONS_KEYS
An array of valid keys in the options hash when configuring a
Opendistro::API
.
Public Class Methods
extended(base)
click to toggle source
Sets all configuration options to their default values when this module is extended.
# File lib/opendistro/configuration.rb, line 17 def self.extended(base) base.reset end
Public Instance Methods
configure() { |self| ... }
click to toggle source
Convenience method to allow configuration options to be set in a block.
# File lib/opendistro/configuration.rb, line 22 def configure yield self end
options()
click to toggle source
Creates a hash of options and their values.
# File lib/opendistro/configuration.rb, line 27 def options VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end
reset()
click to toggle source
Resets all configuration options to the defaults.
# File lib/opendistro/configuration.rb, line 34 def reset self.endpoint = ENV['OPENDISTRO_API_ENDPOINT'] self.username = ENV['OPENDISTRO_API_USER'] self.password = ENV['OPENDISTRO_API_PASSWORD'] self.ca_cert = ENV['OPENDISTRO_API_CA_CERT_PATH'] self.httparty = get_httparty_config(ENV['OPENDISTRO_API_HTTPARTY_OPTIONS']) self.user_agent = DEFAULT_USER_AGENT self.verify_ssl = ENV['OPENDISTRO_API_VERIFY_SSL'] || DEFAULT_VERIFY_SSL end
Private Instance Methods
get_httparty_config(options)
click to toggle source
Allows HTTParty config to be specified in ENV using YAML hash.
# File lib/opendistro/configuration.rb, line 47 def get_httparty_config(options) return if options.nil? httparty = Opendistro::CLI::Helpers.yaml_load(options) raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash Opendistro::CLI::Helpers.symbolize_keys httparty end