Module: Controls::Default
- Defined in:
- lib/controls/default.rb
Overview
Default options merged with environment specific overrides to satisfy the options specified in the Configurable module
Constant Summary collapse
- API_VERSION =
Returns the API version to connect to. default: 1.0.
'1.0'.freeze
- API_ENDPOINT =
Returns the API endpoint to connect to. default: nexpose.local:3780/insight/controls/api/1.0.
"https://localhost:3780/insight/controls/api/#{API_VERSION}".freeze
- MEDIA_TYPE =
Returns the default media type to send with requests. default: application/json.
'application/json'
- USER_AGENT =
Returns 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)”.
"controls/v#{Controls::VERSION} (#{(RUBY_DESCRIPTION.split[0..1] + [RUBY_DESCRIPTION.split.last]).join('; ')}; Faraday v#{Faraday::VERSION})".freeze
- WEB_ENDPOINT =
Returns the web endpoint to connect to. default: nexpose.local:3780/insight/controls.
'https://localhost:3780/insight/controls'.freeze
Class Method Summary collapse
-
.api_endpoint ⇒ String
The API endpoint’s URI as a URL.
-
.api_version ⇒ String
The API version to connect to.
-
.connection_options ⇒ Hash
The current connection options (headers, etc.).
-
.default_media_type ⇒ String
The environment specific default media type.
-
.middleware ⇒ Faraday::Connection
REVIEW: Ensure that middleware is unique to the client instance.
-
.netrc ⇒ Boolean
Whether to fallback on authentication using the specified netrc file.
-
.netrc_file ⇒ String
The netrc file to use for authentication.
-
.options ⇒ Hash
Options as a Hash, mapped by keys from Configurable.
-
.password ⇒ String
The password to use for authentication.
-
.user_agent ⇒ String
The user agent that will be sent along any requests sent using Configurable#connection_options.
-
.username ⇒ String
The username to use for authentication.
-
.web_endpoint ⇒ String
The web endpoint’s URI as a URL.
Class Method Details
.api_endpoint ⇒ String
Returns the API endpoint’s URI as a URL.
32 33 34 35 36 |
# 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 |
.api_version ⇒ String
Returns the API version to connect to.
39 40 41 42 43 44 45 |
# 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 |
.connection_options ⇒ Hash
Returns the current connection options (headers, etc.).
48 49 50 51 52 53 54 55 |
# File 'lib/controls/default.rb', line 48 def { headers: { accept: default_media_type, user_agent: user_agent } } end |
.default_media_type ⇒ String
Returns the environment specific default media type. default: MEDIA_TYPE.
59 60 61 |
# File 'lib/controls/default.rb', line 59 def default_media_type ENV['CONTROLS_MEDIA_TYPE'] || MEDIA_TYPE end |
.middleware ⇒ Faraday::Connection
REVIEW: Ensure that middleware is unique to the client instance
65 66 67 68 69 70 |
# File 'lib/controls/default.rb', line 65 def middleware @middleware ||= Faraday.new(api_endpoint, ) do |conn| conn.adapter Faraday.default_adapter conn.response :logger if ENV['CONTROLS_DEBUG'] end end |
.netrc ⇒ Boolean
Returns whether to fallback on authentication using the specified netrc file.
74 75 76 |
# File 'lib/controls/default.rb', line 74 def netrc ENV['CONTROLS_NETRC'] || false end |
.netrc_file ⇒ String
Returns the netrc file to use for authentication. default: ~/.netrc.
80 81 82 |
# File 'lib/controls/default.rb', line 80 def netrc_file ENV['CONTROLS_NETRC_FILE'] || File.join(Dir.home, '.netrc') end |
.options ⇒ Hash
Returns options as a Hash, mapped by keys from Configurable.
27 28 29 |
# File 'lib/controls/default.rb', line 27 def Hash[Controls::Configurable.keys.map { |key| [key, send(key)] }] end |
.password ⇒ String
Returns the password to use for authentication.
86 87 88 |
# File 'lib/controls/default.rb', line 86 def password ENV['CONTROLS_PASSWORD'] end |
.user_agent ⇒ String
Returns the user agent that will be sent along any requests sent using Configurable#connection_options.
92 93 94 |
# File 'lib/controls/default.rb', line 92 def user_agent ENV['CONTROLS_USER_AGENT'] || USER_AGENT end |
.username ⇒ String
Returns the username to use for authentication.
97 98 99 |
# File 'lib/controls/default.rb', line 97 def username ENV['CONTROLS_USERNAME'] end |
.web_endpoint ⇒ String
Returns the web endpoint’s URI as a URL.
102 103 104 105 |
# File 'lib/controls/default.rb', line 102 def web_endpoint endpoint = ENV['CONTROLS_WEB_ENDPOINT'] || WEB_ENDPOINT URI.parse(endpoint).to_s end |