class HammerCLIForeman::Api::Connection
Attributes
authenticator[R]
Public Class Methods
new(settings, logger = nil, locale = nil, auth_type = nil)
click to toggle source
Calls superclass method
# File lib/hammer_cli_foreman/api/connection.rb, line 25 def initialize(settings, logger = nil, locale = nil, auth_type = nil) auth_type ||= default_auth_type(settings) default_params = build_default_params(settings, logger, locale, auth_type) super(default_params, :logger => logger, :reload_cache => settings.get(:_params, :reload_cache) || settings.get(:reload_cache) ) end
Public Instance Methods
login()
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 34 def login # Call some api entry point to trigger the successful connection @api.resource(:home).action(:status).call end
login_status()
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 43 def login_status @authenticator.status end
logout()
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 39 def logout @authenticator.clear if @authenticator.respond_to?(:clear) end
Protected Instance Methods
build_default_params(settings, logger, locale, auth_type)
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 59 def build_default_params(settings, logger, locale, auth_type) config = {} config[:uri] = settings.get(:_params, :host) || settings.get(:foreman, :host) config[:logger] = logger unless logger.nil? config[:api_version] = 2 config[:follow_redirects] = settings.get(:foreman, :follow_redirects) || :never config[:aggressive_cache_checking] = settings.get(:foreman, :refresh_cache) || false unless locale.nil? config[:headers] = { "Accept-Language" => locale } config[:language] = locale end config[:timeout] = settings.get(:foreman, :request_timeout) config[:timeout] = -1 if (config[:timeout] && config[:timeout].to_i < 0) config[:apidoc_authenticated] = false config[:authenticator] = create_authenticator(config[:uri], settings, auth_type) config end
create_authenticator(uri, settings, auth_type)
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 53 def create_authenticator(uri, settings, auth_type) return @authenticator if @authenticator @authenticator = HammerCLIForeman::Api::Authenticator.new(auth_type, uri, settings).fetch end
default_auth_type(_settings)
click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 49 def default_auth_type(_settings) HammerCLI::Settings.get(:foreman, :default_auth_type) || AUTH_TYPES[:basic_auth] end