X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c183d6ddfd14d0c1a6708127f78558dae9377aa4..55e101c365193a5f3098f9eb75c5219c2188d50c:/bin/google-api diff --git a/bin/google-api b/bin/google-api index 1e41f940d9..e8f3957666 100755 --- a/bin/google-api +++ b/bin/google-api @@ -10,78 +10,29 @@ OAUTH_SERVER_PORT = 12736 require 'rubygems' require 'optparse' +require 'httpadapter' +require 'webrick' require 'google/api_client/version' require 'google/api_client' ARGV.unshift('--help') if ARGV.empty? -command = 'execute' -options = {} -OptionParser.new do |opts| - opts.banner = - "Usage: google-api [options] -- \n" + - " or: google-api --oauth-login= [options]\n" + - " or: google-api --fuzz [options]" +module Google + class APIClient + class CLI + # Used for oauth login + class OAuthVerifierServlet < WEBrick::HTTPServlet::AbstractServlet + attr_reader :verifier - opts.separator "" - - opts.on( - "--oauth-login ", String, "Authorize for the scope") do |s| - command = 'oauth-login' - options[:scope] = s - end - opts.on( - "-s", "--service ", String, "Perform discovery on service") do |s| - options[:service_name] = s - end - opts.on( - "--service-version ", String, "Select service version") do |id| - options[:service_version] = id - end - opts.on( - "--content-type ", String, "Content-Type for request") do |f| - # Resolve content type shortcuts - case f - when 'json' - f = 'application/json' - when 'xml' - f = 'application/xml' - when 'atom' - f = 'application/atom+xml' - when 'rss' - f = 'application/rss+xml' - end - options[:content_type] = f - end - opts.on("--fuzz [rpcname]", String, "Fuzz an API or endpoint") do |rpcname| - command = 'fuzz' - options[:fuzz] = rpcname - end - - opts.on_tail("-v", "--verbose", "Run verbosely") do |v| - options[:verbose] = v - end - opts.on_tail("-h", "--help", "Show this message") do - puts opts - exit - end - opts.on_tail("--version", "Show version") do - puts "google-api-client (#{Google::APIClient::VERSION::STRING})" - exit - end -end.parse! - -if command == 'oauth-login' # Guard to keep start-up time short - require 'webrick' - # Used for oauth login - class OAuthVerifierServlet < WEBrick::HTTPServlet::AbstractServlet - def do_GET(request, response) - $verifier ||= Addressable::URI.unencode_component( - request.request_uri.to_s[/\?.*oauth_verifier=([^&$]+)(&|$)/, 1] - ) - response.status = WEBrick::HTTPStatus::RC_ACCEPTED - # This javascript will auto-close the tab after the verifier is obtained. - response.body = <<-HTML + def do_GET(request, response) + $verifier ||= Addressable::URI.unencode_component( + request.request_uri.to_s[/\?.*oauth_verifier=([^&$]+)(&|$)/, 1] || + request.request_uri.to_s[/\?.*code=([^&$]+)(&|$)/, 1] + ) + response.status = WEBrick::HTTPStatus::RC_ACCEPTED + # This javascript will auto-close the tab after the + # verifier is obtained. + response.body = <<-HTML