# File lib/hammer_cli_foreman/api/connection.rb, line 10 def initialize(settings, logger = nil, locale = nil) default_params = build_default_params(settings, logger, locale) super(default_params, :logger => logger, :reload_cache => settings.get(:_params, :reload_cache) || settings.get(:reload_cache) ) end
# File lib/hammer_cli_foreman/api/connection.rb, line 18 def login # Call some api entry point to trigger the @api.resource(:home).action(:status).call end
# File lib/hammer_cli_foreman/api/connection.rb, line 27 def login_status @authenticator.status end
# File lib/hammer_cli_foreman/api/connection.rb, line 23 def logout @authenticator.clear if @authenticator.respond_to?(:clear) end
# File lib/hammer_cli_foreman/api/connection.rb, line 66 def build_default_params(settings, logger, locale) 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) config end
# File lib/hammer_cli_foreman/api/connection.rb, line 33 def create_authenticator(uri, settings) return @authenticator if @authenticator if ssl_cert_authentication?(settings) && !use_basic_auth?(settings) @authenticator = VoidAuth.new(_('Using certificate authentication.')) else if settings.get(:foreman, :use_sessions) @authenticator = InteractiveBasicAuth.new( settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'], settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] ) @authenticator = SessionAuthenticatorWrapper.new(@authenticator, uri) else username = settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || settings.get(:foreman, :username) password = settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] if (password.nil? && (username == settings.get(:foreman, :username))) password = settings.get(:foreman, :password) end @authenticator = InteractiveBasicAuth.new(username, password) end @authenticator end end
# File lib/hammer_cli_foreman/api/connection.rb, line 57 def ssl_cert_authentication?(settings) (settings.get(:_params, :ssl_client_cert) || settings.get(:ssl, :ssl_client_cert)) && (settings.get(:_params, :ssl_client_key) || settings.get(:ssl, :ssl_client_key)) end
# File lib/hammer_cli_foreman/api/connection.rb, line 62 def use_basic_auth?(settings) settings.get(:_params, :ssl_with_basic_auth) || settings.get(:ssl, :ssl_with_basic_auth) end