aws-sdk 3.0.0.rc8 → 3.0.0.rc9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aws-sdk.rb +1 -107
- metadata +6 -1380
- data/bin/aws.rb +0 -189
data/bin/aws.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'optparse'
|
5
|
-
require 'logger'
|
6
|
-
|
7
|
-
def env_bool key, default
|
8
|
-
if ENV.key?(key)
|
9
|
-
['0', 'false', 'no', 'off'].exclude?(ENV[key].downcase)
|
10
|
-
else
|
11
|
-
default
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# setup default options, check ENV for most
|
16
|
-
options = {
|
17
|
-
repl: env_bool('AWSRB', nil),
|
18
|
-
log: env_bool('AWSRB_LOG', true),
|
19
|
-
color: env_bool('AWSRB_COLOR', true),
|
20
|
-
debug: env_bool('AWSRB_DEBUG', false),
|
21
|
-
load_paths: [],
|
22
|
-
require: [],
|
23
|
-
execute: [],
|
24
|
-
}
|
25
|
-
|
26
|
-
OptionParser.new do |opts|
|
27
|
-
|
28
|
-
opts.banner = "Usage: aws-rb [options]"
|
29
|
-
|
30
|
-
opts.on("--region NAME", "specify the AWS region, e.g. us-west-2") do |value|
|
31
|
-
options[:region] = value
|
32
|
-
end
|
33
|
-
|
34
|
-
opts.on("--repl REPL", "specify the repl environment, pry or irb") do |value|
|
35
|
-
options[:repl] = value
|
36
|
-
end
|
37
|
-
|
38
|
-
opts.on("-e 'command'", "one line of script. Several -e's allowed.") do |value|
|
39
|
-
options[:execute] << value
|
40
|
-
options[:log] = false unless options[:log_set]
|
41
|
-
options[:debug] = false unless options[:debug_set]
|
42
|
-
end
|
43
|
-
|
44
|
-
opts.on("-l", "--[no-]log", "log client requets, on by default") do |value|
|
45
|
-
options[:log] = value
|
46
|
-
options[:log_set] = true
|
47
|
-
end
|
48
|
-
|
49
|
-
opts.on("-c", "--[no-]color", "colorize request logging, on by default") do |value|
|
50
|
-
options[:color] = value
|
51
|
-
end
|
52
|
-
|
53
|
-
opts.on("-d", "--[no-]debug", "log HTTP wire traces, off by default") do |value|
|
54
|
-
options[:debug] = value
|
55
|
-
options[:debug_set] = true
|
56
|
-
end
|
57
|
-
|
58
|
-
opts.on("-Idirectory", Array, "specify $LOAD_PATH directory (may be used more than once)") do |values|
|
59
|
-
options[:load_paths] += values
|
60
|
-
end
|
61
|
-
|
62
|
-
opts.on("-rlibrary", Array, "require the library") do |values|
|
63
|
-
options[:require] += values
|
64
|
-
end
|
65
|
-
|
66
|
-
opts.on("-v", "--verbose", "enable client logging and HTTP wire tracing") do |value|
|
67
|
-
options[:log] = true
|
68
|
-
options[:log_set] = true
|
69
|
-
options[:debug] = true
|
70
|
-
options[:debug_set] = true
|
71
|
-
end
|
72
|
-
|
73
|
-
opts.on("-q", "--quiet", "disable client logging and HTTP wire tracing") do |value|
|
74
|
-
options[:log] = false
|
75
|
-
options[:log_set] = true
|
76
|
-
options[:debug] = false
|
77
|
-
options[:debug_set] = true
|
78
|
-
end
|
79
|
-
|
80
|
-
opts.on("-h", "--help") do
|
81
|
-
puts opts
|
82
|
-
exit
|
83
|
-
end
|
84
|
-
|
85
|
-
end.parse!
|
86
|
-
|
87
|
-
# amend the $LOAD_PATH
|
88
|
-
options[:load_paths].each do |path|
|
89
|
-
$LOAD_PATH.unshift(path)
|
90
|
-
end
|
91
|
-
|
92
|
-
# load the aws-sdk gem
|
93
|
-
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
94
|
-
require 'aws-sdk'
|
95
|
-
|
96
|
-
# when running the REPL locally, we want to load all of the gems from source
|
97
|
-
if File.directory?(File.expand_path('../../../../build_tools', __FILE__))
|
98
|
-
gems = %w(aws-sdk-core aws-sigv4 aws-sigv2 aws-partitions)
|
99
|
-
Aws.constants.each do |const_name|
|
100
|
-
if Aws.autoload?(const_name)
|
101
|
-
gems << "aws-sdk-#{const_name.downcase}"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
gems.each do |gem_name|
|
105
|
-
$LOAD_PATH.unshift(File.expand_path("../../../#{gem_name}/lib", __FILE__))
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# add helper methods
|
110
|
-
module Aws
|
111
|
-
class << self
|
112
|
-
Aws.constants.each do |const_name|
|
113
|
-
if Aws.autoload?(const_name)
|
114
|
-
define_method(const_name.downcase) do |options = {}|
|
115
|
-
Aws.const_get(const_name).const_get(:Client).new(options)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# add the `#resource` helper method to client classes
|
123
|
-
require 'aws-sdk-core'
|
124
|
-
class Seahorse::Client::Base
|
125
|
-
def resource
|
126
|
-
name = self.class.name.split('::')[1]
|
127
|
-
Aws.const_get(name).const_get(:Resource).new(client: self)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# configure the sdk
|
132
|
-
|
133
|
-
cfg = {}
|
134
|
-
|
135
|
-
cfg[:region] = options[:region] if options[:region]
|
136
|
-
|
137
|
-
if options[:log]
|
138
|
-
logger = Logger.new($stdout)
|
139
|
-
logger.formatter = proc {|severity, datetime, progname, msg| msg }
|
140
|
-
cfg[:logger] = logger
|
141
|
-
end
|
142
|
-
|
143
|
-
if options[:color]
|
144
|
-
cfg[:log_formatter] = Aws::Log::Formatter.colored
|
145
|
-
end
|
146
|
-
|
147
|
-
if options[:debug]
|
148
|
-
cfg[:http_wire_trace] = true
|
149
|
-
end
|
150
|
-
|
151
|
-
Aws.config = cfg
|
152
|
-
|
153
|
-
options[:require].each do |library|
|
154
|
-
require(library)
|
155
|
-
end
|
156
|
-
|
157
|
-
unless options[:execute].empty?
|
158
|
-
eval(options[:execute].join("\n"))
|
159
|
-
exit
|
160
|
-
end
|
161
|
-
|
162
|
-
class PryNotAvailable < StandardError; end
|
163
|
-
|
164
|
-
def run_with_pry
|
165
|
-
begin
|
166
|
-
require 'pry'
|
167
|
-
rescue LoadError
|
168
|
-
raise PryNotAvailable
|
169
|
-
end
|
170
|
-
Pry.config.prompt = [proc { "Aws> " }, proc { "Aws| " }]
|
171
|
-
Aws.pry
|
172
|
-
end
|
173
|
-
|
174
|
-
def run_with_irb
|
175
|
-
require 'irb'
|
176
|
-
IRB.start
|
177
|
-
end
|
178
|
-
|
179
|
-
case options[:repl]
|
180
|
-
when 'pry' then run_with_pry
|
181
|
-
when 'irb' then run_with_irb
|
182
|
-
else
|
183
|
-
begin
|
184
|
-
run_with_pry
|
185
|
-
rescue PryNotAvailable
|
186
|
-
warn("Pry not available, falling back to irb")
|
187
|
-
run_with_irb
|
188
|
-
end
|
189
|
-
end
|