Class: RHC::Auth::Basic

Inherits:
Object show all
Includes:
Helpers
Defined in:
lib/rhc/auth/basic.rb

Constant Summary

Constants included from Helpers

Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding

Methods included from OutputHelpers

#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #display_team, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message

Constructor Details

#initialize(*args) ⇒ Basic

Returns a new instance of Basic.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rhc/auth/basic.rb', line 3

def initialize(*args)
  if args[0].is_a?(String) or args.length > 1
    @username, @password = args
  else
    @options = args[0] || Commander::Command::Options.new
    @username = options[:rhlogin]
    @password = options[:password]
    @no_interactive = options[:noprompt]
  end
  @skip_interactive = !@password.nil?
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



35
36
37
# File 'lib/rhc/auth/basic.rb', line 35

def username
  @username
end

Instance Method Details

#can_authenticate?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rhc/auth/basic.rb', line 31

def can_authenticate?
  username? and not (password.nil? and @skip_interactive and @no_interactive)
end

#retry_auth?(response, client) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/rhc/auth/basic.rb', line 23

def retry_auth?(response, client)
  if response.status == 401
    credentials_rejected
  else
    false
  end
end

#to_request(request) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rhc/auth/basic.rb', line 15

def to_request(request)
  request[:user] ||=
    lambda{ username || (request[:lazy_auth] != true && ask_username) || nil }
  request[:password] ||=
    lambda{ password || (username? && request[:lazy_auth] != true && ask_password) || nil }
  request
end