lib/chef-api/defaults.rb in chef-api-0.10.0 vs lib/chef-api/defaults.rb in chef-api-0.10.2

- old
+ new

@@ -1,13 +1,13 @@ -require 'chef-api/version' -require 'pathname' -require 'json' +require_relative "version" +require "pathname" +require "json" module ChefAPI module Defaults # Default API endpoint - ENDPOINT = 'https://api.opscode.com/'.freeze + ENDPOINT = "https://api.opscode.com/".freeze # Default User Agent header string USER_AGENT = "ChefAPI Ruby Gem #{ChefAPI::VERSION}".freeze class << self @@ -35,21 +35,21 @@ # @return [Pathname] an expanded Pathname or a non-existent Pathname def config_path if result = chef_api_config_path Pathname(result).expand_path else - Pathname('') + Pathname("") end end # # String representation of path to configuration file # # @return [String, nil] Path to config file, or nil def chef_api_config_path - ENV['CHEF_API_CONFIG'] || if ENV.key?('HOME') - '~/.chef-api' + ENV["CHEF_API_CONFIG"] || if ENV.key?("HOME") + "~/.chef-api" else nil end end @@ -68,11 +68,11 @@ # https://chef.server.local:4567/ # # @return [String] (default: +https://api.opscode.com/+) # def endpoint - ENV['CHEF_API_ENDPOINT'] || config['CHEF_API_ENDPOINT'] || ENDPOINT + ENV["CHEF_API_ENDPOINT"] || config["CHEF_API_ENDPOINT"] || ENDPOINT end # # The flavor of the target Chef Server. There are two possible values: # @@ -83,113 +83,114 @@ # covers both Chef Zero and Open Source Chef Server. # # @return [true, false] # def flavor - if ENV['CHEF_API_FLAVOR'] - ENV['CHEF_API_FLAVOR'].to_sym - elsif config['CHEF_API_FLAVOR'] - config['CHEF_API_FLAVOR'] + if ENV["CHEF_API_FLAVOR"] + ENV["CHEF_API_FLAVOR"].to_sym + elsif config["CHEF_API_FLAVOR"] + config["CHEF_API_FLAVOR"] else - endpoint.include?('/organizations') ? :enterprise : :open_source + endpoint.include?("/organizations") ? :enterprise : :open_source end end # # The User Agent header to send along. # # @return [String] # def user_agent - ENV['CHEF_API_USER_AGENT'] || config['CHEF_API_USER_AGENT'] || USER_AGENT + ENV["CHEF_API_USER_AGENT"] || config["CHEF_API_USER_AGENT"] || USER_AGENT end # # The name of the Chef API client. This is the equivalent of # +client_name+ in Chef terminology. In most cases, this is your Chef # username. # # @return [String, nil] # def client - ENV['CHEF_API_CLIENT'] || config['CHEF_API_CLIENT'] + ENV["CHEF_API_CLIENT"] || config["CHEF_API_CLIENT"] end # # The private key to authentication against the Chef Server. This is # equivalent to the +client_key+ in Chef terminology. This value can # be the client key in plain text or a path to the key on disk. # # @return [String, nil] # def key - ENV['CHEF_API_KEY'] || config['CHEF_API_KEY'] + ENV["CHEF_API_KEY"] || config["CHEF_API_KEY"] end + # # The HTTP Proxy server address as a string # # @return [String, nil] # def proxy_address - ENV['CHEF_API_PROXY_ADDRESS'] || config['CHEF_API_PROXY_ADDRESS'] + ENV["CHEF_API_PROXY_ADDRESS"] || config["CHEF_API_PROXY_ADDRESS"] end # # The HTTP Proxy user password as a string # # @return [String, nil] # def proxy_password - ENV['CHEF_API_PROXY_PASSWORD'] || config['CHEF_API_PROXY_PASSWORD'] + ENV["CHEF_API_PROXY_PASSWORD"] || config["CHEF_API_PROXY_PASSWORD"] end # # The HTTP Proxy server port as a string # # @return [String, nil] # def proxy_port - ENV['CHEF_API_PROXY_PORT'] || config['CHEF_API_PROXY_PORT'] + ENV["CHEF_API_PROXY_PORT"] || config["CHEF_API_PROXY_PORT"] end # # The HTTP Proxy server username as a string # # @return [String, nil] # def proxy_username - ENV['CHEF_API_PROXY_USERNAME'] || config['CHEF_API_PROXY_USERNAME'] + ENV["CHEF_API_PROXY_USERNAME"] || config["CHEF_API_PROXY_USERNAME"] end # # The path to a pem file on disk for use with a custom SSL verification # # @return [String, nil] # def ssl_pem_file - ENV['CHEF_API_SSL_PEM_FILE'] || config['CHEF_API_SSL_PEM_FILE'] + ENV["CHEF_API_SSL_PEM_FILE"] || config["CHEF_API_SSL_PEM_FILE"] end # # Verify SSL requests (default: true) # # @return [true, false] # def ssl_verify - if ENV['CHEF_API_SSL_VERIFY'].nil? && config['CHEF_API_SSL_VERIFY'].nil? + if ENV["CHEF_API_SSL_VERIFY"].nil? && config["CHEF_API_SSL_VERIFY"].nil? true else - %w[t y].include?(ENV['CHEF_API_SSL_VERIFY'].downcase[0]) || config['CHEF_API_SSL_VERIFY'] + %w{t y}.include?(ENV["CHEF_API_SSL_VERIFY"].downcase[0]) || config["CHEF_API_SSL_VERIFY"] end end # # Network request read timeout in seconds (default: 60) # # @return [Integer, nil] # def read_timeout - timeout_from_env = ENV['CHEF_API_READ_TIMEOUT'] || config['CHEF_API_READ_TIMEOUT'] + timeout_from_env = ENV["CHEF_API_READ_TIMEOUT"] || config["CHEF_API_READ_TIMEOUT"] Integer(timeout_from_env) unless timeout_from_env.nil? end end end