class Bazil::Client::Options
Constants
- API_KEYS_API_KEY_KEY
- API_KEYS_FILE_KEY
- API_KEYS_SECRET_KEY_KEY
- AVAILABLE_SCHEMA
- AVAILABLE_SSL_VERSIONS
- BAZIL_CONFIG_DIRS
- CA_FILE_KEY
- DEFAULT_API_KEYS_FILES
- DEFAULT_CA_FILE
- DEFAULT_SKIP_VERIFY
- DEFAULT_SSL_VERSION
- DEFAULT_URL
- SKIP_VERIFY_KEY
- SSL_VERSION_KEY
- URL_KEY
Attributes
api_key[R]
api_root[R]
ca_file[R]
host[R]
port[R]
scheme[R]
secret_key[R]
ssl_version[R]
verify_mode[R]
Public Class Methods
new(options)
click to toggle source
# File lib/bazil/client.rb, line 18 def initialize(options) if options.kind_of? String options = {CA_FILE_KEY => options} end options = symbolize_keys(options) load_url_option(options) load_ca_file_option(options) load_ssl_version_option(options) load_verify_option(options) load_api_keys_option(options) end
Private Instance Methods
load_api_keys_option(options)
click to toggle source
# File lib/bazil/client.rb, line 64 def load_api_keys_option(options) if options.has_key?(API_KEYS_FILE_KEY) && options[API_KEYS_FILE_KEY].nil? # skip warning if specified nil explicitly return end api_keys_file = options[API_KEYS_FILE_KEY] || DEFAULT_API_KEYS_FILES.find{|file| File::readable?(file) && File::file?(file) } raise "API keys file is not found" if api_keys_file.nil? api_keys = symbolize_keys(JSON::parse(File::read(api_keys_file))) @api_key = api_keys[API_KEYS_API_KEY_KEY] @secret_key = api_keys[API_KEYS_SECRET_KEY_KEY] rescue SystemCallError, RuntimeError => e STDERR.puts "" STDERR.puts "WARNING: Failed to read api_keys file. Check your api_keys file, or set api_keys manually by set_api_keys(API_KEY, SECRET_KEY): ERROR = #{e.to_s}" STDERR.puts "" end
load_ca_file_option(options)
click to toggle source
# File lib/bazil/client.rb, line 43 def load_ca_file_option(options) @ca_file = options[CA_FILE_KEY] || DEFAULT_CA_FILE if @ca_file raise "ca_file option must be string value" unless @ca_file.is_a? String raise "ca_file option must be absolute path" unless @ca_file[0] == '/' raise "ca_file '#{@ca_file}' doesn't exist" unless File::exists? @ca_file end end
load_ssl_version_option(options)
click to toggle source
# File lib/bazil/client.rb, line 52 def load_ssl_version_option(options) ssl_version = options[SSL_VERSION_KEY] || DEFAULT_SSL_VERSION raise "Unsupported SSL version '#{ssl_version}'" unless AVAILABLE_SSL_VERSIONS.has_key? ssl_version @ssl_version = AVAILABLE_SSL_VERSIONS[ssl_version] end
load_url_option(options)
click to toggle source
# File lib/bazil/client.rb, line 33 def load_url_option(options) url = URI::parse(options[URL_KEY] || DEFAULT_URL) @host = url.host or raise "Failed to obtain host name from given url: url = #{url.to_s}" @port = url.port or raise "Failed to obtain port number from given url: url = #{url.to_s}" @scheme = url.scheme or raise "Failed to obtain scheme from given url: url = #{url.to_s}" raise "Unsupported scheme '#{@scheme}'" unless AVAILABLE_SCHEMA.include? @scheme @api_root = url.path @api_root += '/' unless @api_root.end_with? '/' end
load_verify_option(options)
click to toggle source
# File lib/bazil/client.rb, line 58 def load_verify_option(options) skip_verify = options[SKIP_VERIFY_KEY] || DEFAULT_SKIP_VERIFY raise "skip_verify option must be boolean value" unless skip_verify.is_a?(TrueClass) || skip_verify.is_a?(FalseClass) @verify_mode = skip_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER end
symbolize_keys(hash)
click to toggle source
# File lib/bazil/client.rb, line 84 def symbolize_keys(hash) {}.tap{|new_hash| hash.each{|k,v| new_hash[k.to_s.to_sym] = v } } end