Class: CF::UAA::CommonCli
Instance Method Summary
collapse
Methods inherited from Topic
#add_command, #ask, #ask_pwd, commands, define_option, desc, #gripe, #help_col_start, #initialize, #opt_help, #opt_strs, option_defs, #opts, #pp, #print_tree, #say, #say_cmd_helper, #say_command_help, #say_commands, #say_definition, #say_help, #terminal_columns, topic
Constructor Details
This class inherits a constructor from CF::UAA::Topic
Instance Method Details
#askd(prompt, defary) ⇒ Object
46
47
48
49
50
|
# File 'lib/cli/common.rb', line 46
def askd(prompt, defary)
return ask(prompt) unless defary
result = ask("#{prompt} [#{Util.strlist(defary)}]")
result.nil? || result.empty? ? defary : result
end
|
25
26
27
28
29
30
|
# File 'lib/cli/common.rb', line 25
def
unless (ttype = Config.value(:token_type)) && (token = Config.value(:access_token))
raise "Need an access token to complete this command. Please login."
end
"#{ttype} #{token}"
end
|
#clientname(name = opts[:client]) ⇒ Object
34
|
# File 'lib/cli/common.rb', line 34
def clientname(name = opts[:client]); name || ask("Client name") end
|
#clientsecret(name = opts[:secret]) ⇒ Object
35
|
# File 'lib/cli/common.rb', line 35
def clientsecret(name = opts[:secret]); name || ask_pwd("Client secret") end
|
#complain(e) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/cli/common.rb', line 52
def complain(e)
case e
when TargetError then gripe "\n#{e.message}:\n#{Util.json_pretty(e.info)}"
when Exception
gripe "\n#{e.class}: #{e.message}\n\n"
gripe e.backtrace if trace?
when String then gripe e
else gripe "unknown type of gripe: #{e.class}, #{e}"
end
end
|
#debug? ⇒ Boolean
23
|
# File 'lib/cli/common.rb', line 23
def debug?; opts[:debug] end
|
#handle_request ⇒ Object
63
64
65
66
67
|
# File 'lib/cli/common.rb', line 63
def handle_request
yield
rescue Exception => e
complain e
end
|
#scim_common_list(type, filter) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/cli/common.rb', line 83
def scim_common_list(type, filter)
pp scim_request { |sr|
query = { attributes: opts[:attrs], filter: filter }
info = opts[:start] || opts[:count] ?
sr.query(type, query.merge!(startIndex: opts[:start], count: opts[:count])):
sr.all_pages(type, query)
nattr = sr.name_attr(type).downcase
info.is_a?(Array) && info.length > 0 && info[0][nattr] ?
info.each_with_object({}) { |v, h| h[v.delete(nattr)] = v } : info
}
end
|
#scim_get_object(scim, type, name, attrs = nil) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/cli/common.rb', line 95
def scim_get_object(scim, type, name, attrs = nil)
query = { attributes: attrs, filter: "#{scim.name_attr(type)} eq \"#{name}\""}
info = scim.all_pages(type, query)
raise BadResponse unless info.is_a?(Array) && info.length < 2
raise NotFound if info.length == 0
info = info[0]
attrs || !info["id"] || info["meta"]? info : scim.get(type, info["id"])
end
|
#scim_request ⇒ Object
69
70
71
72
73
|
# File 'lib/cli/common.rb', line 69
def scim_request
yield Scim.new(Config.target, , { skip_ssl_validation: Config.target_value(:skip_ssl_validation) })
rescue Exception => e
complain e
end
|
#trace? ⇒ Boolean
22
|
# File 'lib/cli/common.rb', line 22
def trace?; opts[:trace] end
|
#update_target_info(info = nil) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/cli/common.rb', line 75
def update_target_info(info = nil)
return if !info && Config.target_value(:prompts)
info ||= @cli_class.uaa_info_client.server
Config.target_opts(prompts: info['prompts'])
Config.target_opts(token_endpoint: info['token_endpoint']) if info['token_endpoint']
info
end
|
#username(name) ⇒ Object
32
|
# File 'lib/cli/common.rb', line 32
def username(name); name || ask("User name") end
|
#userpwd(pwd = opts[:password]) ⇒ Object
33
|
# File 'lib/cli/common.rb', line 33
def userpwd(pwd = opts[:password]); pwd || ask_pwd("Password") end
|
#verified_pwd(prompt, pwd = nil) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/cli/common.rb', line 37
def verified_pwd(prompt, pwd = nil)
while pwd.nil?
pwd_a = ask_pwd prompt
pwd_b = ask_pwd "Verify #{prompt.downcase}"
pwd = pwd_a if pwd_a == pwd_b
end
pwd
end
|