54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/spark_api/cli.rb', line 54
def self.setup_options(stdout,arguments)
env_options = {
:oauth2 => false,
:endpoint => ENV[OPTIONS_ENV[:endpoint]],
:access_uri => ENV[OPTIONS_ENV[:access_uri]],
:authorization_uri => ENV[OPTIONS_ENV[:authorization_uri]],
:redirect_uri => ENV[OPTIONS_ENV[:redirect_uri]],
:code => ENV[OPTIONS_ENV[:code]],
:username=> ENV[OPTIONS_ENV[:username]],
:password=> ENV[OPTIONS_ENV[:password]],
:client_id=> ENV[OPTIONS_ENV[:client_id]],
:client_secret=> ENV[OPTIONS_ENV[:client_secret]],
:api_key => ENV[OPTIONS_ENV[:api_key]],
:api_secret => ENV[OPTIONS_ENV[:api_secret]],
:api_user => ENV[OPTIONS_ENV[:api_user]],
:no_verify => ENV.fetch(OPTIONS_ENV[:no_verify], false),
:console => ENV[OPTIONS_ENV[:console]]
}
cli_options = {}
file_options = {}
parser = OptionParser.new do |opts|
opts.banner = <<-BANNER.gsub(/^ /,'')
#{version}
SparkApi Client Console - http://sparkplatform.com/docs/overview/api
Usage: #{File.basename($0)} [options]
Environment Variables: some options (as indicated below), will default to values of keys set in the environment.
Options are:
BANNER
opts.separator ""
opts.on("-e","--endpoint ENDPOINT",
"URI of the API.",
"Default: ENV['#{OPTIONS_ENV[:endpoint]}'] or #{SparkApi::Configuration::DEFAULT_ENDPOINT}") { |arg| cli_options[:endpoint] = arg }
opts.on("-o","--oauth2",
"Run the API using OAuth2 credentials. The client defaults to using the Spark API authentication mode for access. ",
"See http://sparkplatform.com/docs/authentication/authentication for more information on authentication types.",
"Default: false") { |arg| cli_options[:oauth2] = arg }
opts.on("--client_id CLIENT_ID",
"OAuth2 client id",
"Default: ENV['#{OPTIONS_ENV[:client_id]}']") { |arg| cli_options[:client_id] = arg }
opts.on("--client_secret CLIENT_SECRET",
"OAuth2 client secret",
"Default: ENV['#{OPTIONS_ENV[:client_secret]}']") { |arg| cli_options[:client_secret] = arg }
opts.on("-u","--username USERNAME",
"OAuth2 username",
"Default: ENV['#{OPTIONS_ENV[:username]}']") { |arg| cli_options[:username] = arg }
opts.on("-p","--password PASSWORD",
"OAuth2 password",
"Default: ENV['#{OPTIONS_ENV[:password]}']") { |arg| cli_options[:password] = arg }
opts.on("--access_uri ACCESS_URI",
"OAuth2 path for granting access to the application using one of the supported grant types.",
"Default: ENV['#{OPTIONS_ENV[:access_uri]}'] or #{SparkApi::Configuration::DEFAULT_ACCESS_URI}") { |arg| cli_options[:access_uri] = arg }
opts.on("--redirect_uri REDIRECT_URI",
"OAuth2 application redirect for the client id. This needs to match whatever value is saved for the application's client_id",
"Default: ENV['#{OPTIONS_ENV[:redirect_uri]}'] or #{SparkApi::Configuration::DEFAULT_REDIRECT_URI}") { |arg| cli_options[:redirect_uri] = arg }
opts.on("--authorization_uri AUTHORIZATION_URI",
"OAuth2 authorization endpoint for a user. This is where the user should go to sign in and authorize client id.",
"Default: ENV['#{OPTIONS_ENV[:authorization_uri]}'] or #{SparkApi::Configuration::DEFAULT_AUTH_ENDPOINT}") { |arg| cli_options[:authorization_uri] = arg }
opts.on("--code CODE",
"OAuth2 authorization code used for granting application access to the API for a user") { |arg| cli_options[:code] = arg }
opts.on("--api_key API_KEY",
"Authentication key for running the api using the default api authentication",
"Default: ENV['#{OPTIONS_ENV[:api_key]}']") { |arg| cli_options[:api_key] = arg }
opts.on("--api_secret API_SECRET",
"API secret for the api key",
"Default: ENV['#{OPTIONS_ENV[:api_secret]}']") { |arg| cli_options[:api_secret] = arg }
opts.on("--api_user API_USER",
"ID of the Spark user to run the client as.",
"Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg| cli_options[:api_user] = arg }
opts.on("-f", "--file FILE",
"Load configuration for yaml file.") { |arg| file_options = parse_file_options(arg) }
opts.on("--no_verify",
"Disable SSL Certificate verification. This is useful for development servers.") { |arg| cli_options[:no_verify] = arg }
opts.on("-d", "--debug",
"Show detailed request logging information.") { |arg| cli_options[:debug] = arg }
opts.on("-v", "--version",
"Show client version.") { stdout.puts version; exit }
opts.on("-h", "--help",
"Show this help message.") { stdout.puts opts; exit }
opts.parse!(arguments)
end
options = env_options.merge(file_options.merge(cli_options))
return options
end
|