module Controls::Default
Default
options merged with environment specific overrides to satisfy the options specified in the {Controls::Configurable} module
Constants
- API_ENDPOINT
@return [String] the API endpoint to connect to. default: nexpose.local:3780/insight/controls/api/1.0 @since API v1.0.0
- API_VERSION
@return [String] the API version to connect to. default: 1.0 @since API v1.0.0
- MEDIA_TYPE
@return [String] the default media type to send with requests. default: application/json @since API v1.0.0
- USER_AGENT
@return [String] the user agent to send with API requests. example: “controls/v1.0.0.beta (ruby; 2.0.0p247; [x86_64-darwin12.4.0]; Faraday v0.8.8)”
- WEB_ENDPOINT
@return [String] the web endpoint to connect to. default: nexpose.local:3780/insight/controls
Public Class Methods
@return [String] the API endpoint's URI as a URL
# File lib/controls/default.rb, line 32 def api_endpoint endpoint = ENV['CONTROLS_API_ENDPOINT'] || API_ENDPOINT # [todo] - this raises an exception, it is only used for URI validation so it's being commented out for now # URI.parse(endpoint).to_s end
@return [String] the API version to connect to
# File lib/controls/default.rb, line 39 def api_version if ENV['CONTROLS_API_VERSION'].to_s =~ /\d+.\d+/ ENV['CONTROLS_API_VERSION'] else API_VERSION end end
@return [Hash] the current connection options (headers, etc.)
# File lib/controls/default.rb, line 48 def connection_options { headers: { accept: default_media_type, user_agent: user_agent } } end
@return [String] the environment specific default media type.
default: {MEDIA_TYPE}
# File lib/controls/default.rb, line 59 def default_media_type ENV['CONTROLS_MEDIA_TYPE'] || MEDIA_TYPE end
REVIEW: Ensure that middleware is unique to the client instance @return [Faraday::Connection] the middleware used to send requests
# File lib/controls/default.rb, line 65 def middleware @middleware ||= Faraday.new(api_endpoint, connection_options) do |conn| conn.adapter Faraday.default_adapter conn.response :logger if ENV['CONTROLS_DEBUG'] end end
@return [Boolean] whether to fallback on authentication using the
specified netrc file
# File lib/controls/default.rb, line 74 def netrc ENV['CONTROLS_NETRC'] || false end
@return [String] the netrc file to use for authentication.
default: ~/.netrc
# File lib/controls/default.rb, line 80 def netrc_file ENV['CONTROLS_NETRC_FILE'] || File.join(Dir.home, '.netrc') end
@return [Hash] options as a Hash, mapped by keys from {Controls::Configurable}
# File lib/controls/default.rb, line 27 def options Hash[Controls::Configurable.keys.map { |key| [key, send(key)] }] end
@return [String] the password to use for authentication
# File lib/controls/default.rb, line 86 def password ENV['CONTROLS_PASSWORD'] end
@return [String] the user agent that will be sent along any requests
sent using {#connection_options}
# File lib/controls/default.rb, line 92 def user_agent ENV['CONTROLS_USER_AGENT'] || USER_AGENT end
@return [String] the username to use for authentication
# File lib/controls/default.rb, line 97 def username ENV['CONTROLS_USERNAME'] end
@return [String] the web endpoint's URI as a URL
# File lib/controls/default.rb, line 102 def web_endpoint endpoint = ENV['CONTROLS_WEB_ENDPOINT'] || WEB_ENDPOINT URI.parse(endpoint).to_s end