Class: RHC::Auth::Token
Constant Summary
Constants included
from Helpers
Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES
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?, #pluralize, #protonbox_online_server?, #protonbox_rest_endpoint, #protonbox_server, #protonbox_url, #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
#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, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message
Constructor Details
#initialize(opt, auth = nil, store = nil) ⇒ Token
Returns a new instance of Token.
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/rhc/auth/token.rb', line 3
def initialize(opt, auth=nil, store=nil)
if opt.is_a?(String)
@token = opt
else
@options = opt || Commander::Command::Options.new
@token = options[:token]
@no_interactive = options[:noprompt]
@allows_tokens = options[:use_authorization_tokens]
end
@auth = auth
@store = store
read_token
end
|
Instance Method Details
#can_authenticate? ⇒ Boolean
45
46
47
|
# File 'lib/rhc/auth/token.rb', line 45
def can_authenticate?
token || auth && auth.can_authenticate?
end
|
#retry_auth?(response, client) ⇒ Boolean
28
29
30
31
32
33
34
|
# File 'lib/rhc/auth/token.rb', line 28
def retry_auth?(response, client)
if response.status == 401
token_rejected(response, client)
else
false
end
end
|
#save(token) ⇒ Object
40
41
42
43
|
# File 'lib/rhc/auth/token.rb', line 40
def save(token)
store.put(username, protonbox_server, token) if store
@token = token
end
|
#to_request(request) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rhc/auth/token.rb', line 17
def to_request(request)
if token
debug "Using token authentication"
(request[:headers] ||= {})['authorization'] = "Bearer #{token}"
elsif auth and (!@allows_tokens or @can_get_token == false)
debug "Bypassing token auth"
auth.to_request(request)
end
request
end
|
36
37
38
|
# File 'lib/rhc/auth/token.rb', line 36
def username
auth && auth.respond_to?(:username) && auth.username || options[:username]
end
|