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



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

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

#clearObject



47
48
49
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 47

def clear
  set_credentials(nil, nil)
end

#error(ex) ⇒ Object



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

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
    return UnauthorizedError.new(message)
  end
end

#password(ask = nil) ⇒ Object



38
39
40
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 38

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

#set_credentials(user, password) ⇒ Object



42
43
44
45
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 42

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

#statusObject



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

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



34
35
36
# File 'lib/hammer_cli_foreman/api/interactive_basic_auth.rb', line 34

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