Class: HammerCLIForeman::Api::InteractiveBasicAuth

Inherits:
ApipieBindings::Authenticators::BasicAuth
  • Object
show all
Defined in:
lib/hammer_cli_foreman/api/interactive_basic_auth.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(request, args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 4

def authenticate(request, args)
  if HammerCLI.interactive?
    get_user
    get_password
  end
  super
end

#clearObject



45
46
47
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 45

def clear
  set_credentials(nil, nil)
end

#error(ex) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 12

def error(ex)
  if ex.is_a?(RestClient::Unauthorized)
    self.clear
    message = _('Invalid username or password.')
    begin
      message = JSON.parse(ex.response.body)['error']['message']
    rescue
    end
    UnauthorizedError.new(message)
  end
end

#password(ask = nil) ⇒ Object



36
37
38
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 36

def password(ask=nil)
  @password ||= ask && get_password
end

#set_credentials(user, password) ⇒ Object



40
41
42
43
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 40

def set_credentials(user, password)
  @user = user
  @password = password
end

#statusObject



24
25
26
27
28
29
30
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 24

def status
  unless @user.nil? || @password.nil?
    _("Using configured credentials for user '%s'.") % @user
  else
    _("Credentials are not configured.")
  end
end

#user(ask = nil) ⇒ Object



32
33
34
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 32

def user(ask=nil)
  @user ||= ask && get_user
end