class HammerCLIForeman::Api::Authenticator
Attributes
auth_type[RW]
settings[RW]
uri[RW]
Public Class Methods
new(auth_type, uri, settings)
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 5 def initialize(auth_type, uri, settings) @auth_type = auth_type @uri = uri @settings = settings end
Public Instance Methods
fetch()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 11 def fetch if ssl_cert_authentication? && !use_basic_auth? void_auth elsif auth_type == AUTH_TYPES[:basic_auth] basic_auth elsif auth_type == AUTH_TYPES[:negotiate] negotiate_auth elsif auth_type == AUTH_TYPES[:oauth_password_grant] oauth_password_grant elsif auth_type == AUTH_TYPES[:oauth_authentication_code_grant] oauth_authentication_code_grant end end
Private Instance Methods
basic_auth()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 31 def basic_auth if HammerCLIForeman::Sessions.enabled? authenticator = InteractiveBasicAuth.new( settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'], settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] ) SessionAuthenticatorWrapper.new(authenticator, uri, auth_type) 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 InteractiveBasicAuth.new(username, password) end end
negotiate_auth()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 48 def negotiate_auth return unless HammerCLIForeman::Sessions.enabled? authenticator = NegotiateAuth.new(uri) SessionAuthenticatorWrapper.new(authenticator, uri, auth_type) end
oauth_authentication_code_grant()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 67 def oauth_authentication_code_grant return unless HammerCLIForeman::Sessions.enabled? authenticator = Oauth::AuthenticationCodeGrant.new( ENV['OIDC_TOKEN_ENDPOINT'] || settings.get(:foreman, :oidc_token_endpoint), ENV['OIDC_AUTHORIZATION_URL'] || settings.get(:foreman, :oidc_authorization_endpoint), ENV['OIDC_CLIENT_ID'] || settings.get(:foreman, :oidc_client_id), ENV['OIDC_REDIRECT_URI'] || settings.get(:foreman, :oidc_redirect_uri) ) SessionAuthenticatorWrapper.new(authenticator, uri, auth_type) end
oauth_password_grant()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 55 def oauth_password_grant return unless HammerCLIForeman::Sessions.enabled? authenticator = Oauth::PasswordGrant.new( ENV['OIDC_TOKEN_ENDPOINT'] || settings.get(:foreman, :oidc_token_endpoint), ENV['OIDC_CLIENT_ID'] || settings.get(:foreman, :oidc_client_id), ENV['OIDC_USERNAME'], ENV['OIDC_PASSWORD'] ) SessionAuthenticatorWrapper.new(authenticator, uri, auth_type) end
ssl_cert_authentication?()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 79 def ssl_cert_authentication? (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
use_basic_auth?()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 84 def use_basic_auth? settings.get(:_params, :ssl_with_basic_auth) || settings.get(:ssl, :ssl_with_basic_auth) end
void_auth()
click to toggle source
# File lib/hammer_cli_foreman/api/authenticator.rb, line 27 def void_auth VoidAuth.new(_('Using certificate authentication.')) end