Class: Amazon::Coral::Service
Overview
Provides a simple command-line interface to call remote services.
Constant Summary collapse
- @@command_arguments =
[ Option.new({:long => 'help', :short => 'h'}), Option.new({:long => 'url', :short => 'u', :parameters => 1}), Option.new({:long => 'awsAccessKey', :short => 'a', :parameters => 1}), Option.new({:long => 'awsSecretKey', :short => 's', :parameters => 1}), Option.new({:long => 'v0'}), Option.new({:long => 'v1'}), Option.new({:long => 'timeout', :parameters => 1}), Option.new({:long => 'connect_timeout', :parameters => 1}), Option.new({:long => 'input', :short => 'i', :parameters => 1}), Option.new({:long => 'operation', :short => 'o', :parameters => 1}), Option.new({:long => 'verbose', :short => 'v'})]
Instance Method Summary collapse
-
#initialize(args) ⇒ Service
constructor
Initializes a Service object with the specified arguments.
-
#main ⇒ Object
Runs the command line client application.
-
#print_usage ⇒ Object
Prints to STDOUT a help message describing how to use the application.
Constructor Details
#initialize(args) ⇒ Service
Initializes a Service object with the specified arguments. Possible arguments include:
- :orchestrator_helper
-
A class that responds to self.new_orchestrator create the necessary orchestrator. By default the AwsQueryChainHelper is used.
- :service
-
The name of the service to be called.
- :operations
-
A list naming the operations available on the remote service.
39 40 41 42 43 44 45 |
# File 'lib/amazon/coral/service.rb', line 39 def initialize(args) @orchestrator_helper_class = args[:orchestrator_helper] @orchestrator_helper_class = AwsQuery if @orchestrator_helper_class.nil? @service_name = args[:service] @operation_names = args[:operations] end |
Instance Method Details
#main ⇒ Object
Runs the command line client application.
48 49 50 51 52 53 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 |
# File 'lib/amazon/coral/service.rb', line 48 def main if ARGV.length == 0 then print_usage exit end args = Option.parse(@@command_arguments, ARGV) if(args.length == 0 || !args['help'].nil?) then print_usage exit end raise "the 'url' parameter is required" if(args['url'].nil?) url = args['url'][0] input = nil input = eval(args['input'][0]) unless args['input'].nil? raise "the 'operation' parameter is required" if(args['operation'].nil?) operation = args['operation'][0] raise "operation '#{operation}' is not valid for this service" unless @operation_names.include?(operation) verbose = !args['verbose'].nil? timeout = Float(args['timeout'][0]) unless args['timeout'].nil? connect_timeout = Float(args['connect_timeout'][0]) unless args['connect_timeout'].nil? aws_access_key = nil aws_secret_key = nil signature_algorithm = nil if(!args['awsAccessKey'].nil? && !args['awsSecretKey'].nil?) then aws_access_key = args['awsAccessKey'][0] aws_secret_key = args['awsSecretKey'][0] signature_algorithm = :V2 signature_algorithm = :V0 if !args['v0'].nil? signature_algorithm = :V1 if !args['v1'].nil? end helper_args = {:endpoint => url, :signature_algorithm => signature_algorithm, :verbose => verbose, :timeout => timeout, :connect_timeout => connect_timeout} orchestrator = @orchestrator_helper_class.new_orchestrator(helper_args) dispatcher = Dispatcher.new(orchestrator, @service_name, operation) call = Call.new(dispatcher) call.identity[:aws_access_key] = aws_access_key call.identity[:aws_secret_key] = aws_secret_key output = call.call(input) puts output.inspect end |
#print_usage ⇒ Object
Prints to STDOUT a help message describing how to use the application.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/amazon/coral/service.rb', line 107 def print_usage puts "#{@service_name} ruby client" puts "Usage:" puts " -h --help" puts " -u --url" puts " -o --operation OPERATION" puts " -i --input INPUT" puts " -a --awsAccessKey KEY" puts " -s --awsSecretKey SECRET_KEY" puts " --v0" puts " --v1" puts " -v --verbose" puts "" puts "Available operations:" @operation_names.each { |name| puts(" #{name}") } unless @operation_names.nil? end |