Class: Falcon::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/crimson-falcon/configuration.rb

Overview

The ‘Falcon::Configuration` class defines the configuration settings for the CrowdStrike API client. The `ATTRIBUTES` constant is an array of symbols that represent the configuration options, such as the HTTP scheme, API host, and base path. The `Configuration` class provides default values for these options, but they can be overridden by setting the corresponding instance variables. The `Configuration` class is used by the CrowdStrike API client to ensure that API requests are sent to the correct endpoint and with the correct settings.

Constant Summary collapse

ATTRIBUTES =
[
  # The HTTP scheme (http or https) to use for API requests
  :scheme,

  # The API host to send requests to (defaults to api.crowdstrike.com)
  :host,

  # The base path for API requests (defaults to /)
  :base_path,

  # The client ID to use for authentication
  :client_id,

  # The client secret to use for authentication
  :client_secret,

  # The member CID to use for authentication
  :member_cid,

  # The cloud to use for API requests (defaults to us-1)
  :cloud,

  # The access token to use for authentication (overrides access_token_getter)
  :access_token,

  # A lambda that returns the access token to use for authentication
  :access_token_getter,

  # The user agent string to use for API requests
  :user_agent_override,

  # Whether to return binary data in the response
  :return_binary_data,

  # Whether to enable debugging mode
  :debugging,

  # The logger to use for debugging
  :logger,

  # The path to a temporary folder to use for file uploads
  :temp_folder_path,

  # The timeout for API requests, in seconds
  :timeout,

  # Whether to perform client-side validation of API requests
  :client_side_validation,

  # Whether to verify the SSL certificate of the API host
  :verify_ssl,

  # Whether to verify the SSL hostname of the API host
  :verify_ssl_host,

  # The path to the SSL CA certificate file to use for SSL verification
  :ssl_ca_cert,

  # The path to the client certificate file to use for SSL verification
  :cert_file,

  # The path to the client key file to use for SSL verification
  :key_file,

  # The encoding to use for query string and form parameter values
  :params_encoding,

  # The format to inject into the API path
  :inject_format,

  # The format to use for API requests that don't specify a format
  :force_ending_format,
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/crimson-falcon/configuration.rb', line 113

def initialize
  @scheme = "https"
  @cloud = "us-1"
  @host = "api.crowdstrike.com"
  @base_path = ""
  @user_agent_override = nil
  @client_side_validation = true
  @verify_ssl = true
  @verify_ssl_host = true
  @cert_file = nil
  @key_file = nil
  @timeout = 0
  @params_encoding = :multi
  @debugging = false
  @inject_format = false
  @force_ending_format = false
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)

  yield(self) if block_given?
end

Class Method Details

.defaultObject



134
135
136
# File 'lib/crimson-falcon/configuration.rb', line 134

def self.default
  @default ||= new
end

Instance Method Details

#access_token_with_refreshObject



172
173
174
175
# File 'lib/crimson-falcon/configuration.rb', line 172

def access_token_with_refresh
  return access_token if access_token_getter.nil?
  access_token_getter.call
end

#api_key_with_prefix(param_name, param_alias = nil) ⇒ Object



162
163
164
165
166
167
168
169
170
# File 'lib/crimson-falcon/configuration.rb', line 162

def api_key_with_prefix(param_name, param_alias = nil)
  key = @api_key[param_name]
  key = @api_key.fetch(param_alias, key) unless param_alias.nil?
  if @api_key_prefix[param_name]
    "#{@api_key_prefix[param_name]} #{key}"
  else
    key
  end
end

#auth_settingsObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/crimson-falcon/configuration.rb', line 177

def auth_settings
  {
    "oauth2" => {
      type: "oauth2",
      in: "header",
      key: "Authorization",
      value: "Bearer #{access_token_with_refresh}",
    },
  }
end

#base_path=(base_path) ⇒ Object



152
153
154
155
# File 'lib/crimson-falcon/configuration.rb', line 152

def base_path=(base_path)
  @base_path = "/#{base_path}".gsub(/\/+/, "/")
  @base_path = "" if @base_path == "/"
end

#base_urlObject

Returns base URL for specified operation based on server settings



158
159
160
# File 'lib/crimson-falcon/configuration.rb', line 158

def base_url
  "#{scheme}://#{[host, base_path].join("/").gsub(/\/+/, "/")}".sub(/\/+\z/, "")
end

#cloud=(cloud) ⇒ Object

When cloud is set, update host



147
148
149
150
# File 'lib/crimson-falcon/configuration.rb', line 147

def cloud=(cloud)
  @cloud = cloud
  @host = Cloud.new(@cloud).host
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



138
139
140
# File 'lib/crimson-falcon/configuration.rb', line 138

def configure
  yield(self) if block_given?
end

#scheme=(scheme) ⇒ Object



142
143
144
# File 'lib/crimson-falcon/configuration.rb', line 142

def scheme=(scheme)
  @scheme = scheme.sub(/:\/\//, "")
end