class ReceptorController::Client

Constants

STATUS_DISCONNECTED
VERSION

Attributes

config[RW]
default_headers[RW]
identity_header[RW]
logger[RW]
response_worker[RW]

Public Class Methods

configure() { |default| ... } click to toggle source
# File lib/receptor_controller/client.rb, line 18
def configure
  if block_given?
    yield(Configuration.default)
  else
    Configuration.default
  end
end
new(config: Configuration.default, logger: ManageIQ::Messaging::NullLogger.new) click to toggle source
# File lib/receptor_controller/client.rb, line 28
def initialize(config: Configuration.default, logger: ManageIQ::Messaging::NullLogger.new)
  self.config          = config
  self.default_headers = {"Content-Type" => "application/json"}
  self.logger          = logger
  self.response_worker = ResponseWorker.new(config, logger)
end

Public Instance Methods

connection_status(account_number, node_id) click to toggle source
# File lib/receptor_controller/client.rb, line 35
def connection_status(account_number, node_id)
  body = {
    :account => account_number,
    :node_id => node_id
  }.to_json

  response = Faraday.post(config.connection_status_url, body, headers(account_number))
  if response.success?
    JSON.parse(response.body)
  else
    logger.error(receptor_log_msg("Connection_status failed: HTTP #{response.status}", account_number, node_id))
    STATUS_DISCONNECTED
  end
rescue Faraday::Error => e
  logger.error(receptor_log_msg("Connection_status failed", account_number, node_id, e))
  STATUS_DISCONNECTED
end
directive(account_number, node_id, payload:, directive:, log_message_common: nil, type: :non_blocking) click to toggle source
# File lib/receptor_controller/client.rb, line 53
def directive(account_number, node_id,
              payload:,
              directive:,
              log_message_common: nil,
              type: :non_blocking)
  klass = type == :non_blocking ? DirectiveNonBlocking : DirectiveBlocking
  klass.new(:name               => directive,
            :account            => account_number,
            :node_id            => node_id,
            :payload            => payload,
            :log_message_common => log_message_common,
            :client             => self)
end
headers(account = nil) click to toggle source
# File lib/receptor_controller/client.rb, line 67
def headers(account = nil)
  default_headers.merge(auth_headers(account) || {})
end
receptor_log_msg(msg, account, node_id, exception = nil) click to toggle source
# File lib/receptor_controller/client.rb, line 71
def receptor_log_msg(msg, account, node_id, exception = nil)
  message = "Receptor: #{msg}"
  message += "; #{exception.class.name}: #{exception.message}" if exception.present?
  message + " [Account number: #{account}; Receptor node: #{node_id}]"
end

Private Instance Methods

auth_headers(account) click to toggle source

Use x-rh-receptor-controller-psk if present, x-rh-identity otherwise

# File lib/receptor_controller/client.rb, line 82
def auth_headers(account)
  if config.pre_shared_key.present? && account.present?
    {
      'x-rh-receptor-controller-psk'       => config.pre_shared_key,
      'x-rh-receptor-controller-client-id' => config.client_id_header,
      'x-rh-receptor-controller-account'   => account
    }
  else
    identity_header || {}
  end
end