awscli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/awscli +7 -7
- data/lib/awscli.rb +3 -1
- data/lib/awscli/as.rb +56 -56
- data/lib/awscli/cli.rb +1 -1
- data/lib/awscli/cli/UsageExamples/emr +49 -0
- data/lib/awscli/cli/emr.rb +157 -0
- data/lib/awscli/cli/iam/user.rb +18 -7
- data/lib/awscli/cli/s3/files.rb +43 -37
- data/lib/awscli/connection.rb +34 -31
- data/lib/awscli/ec2.rb +234 -234
- data/lib/awscli/emr.rb +472 -0
- data/lib/awscli/errors.rb +1 -1
- data/lib/awscli/helper.rb +17 -0
- data/lib/awscli/iam.rb +281 -218
- data/lib/awscli/s3.rb +51 -39
- data/lib/awscli/version.rb +1 -1
- metadata +5 -2
data/lib/awscli/s3.rb
CHANGED
@@ -7,37 +7,46 @@ module Awscli
|
|
7
7
|
|
8
8
|
class Files
|
9
9
|
def initialize connection, options = {}
|
10
|
-
|
10
|
+
@conn = connection
|
11
11
|
end
|
12
12
|
|
13
|
-
def list
|
14
|
-
dir =
|
13
|
+
def list(dir_name, prefix=nil)
|
14
|
+
dir = @conn.directories.get(dir_name)
|
15
15
|
abort "cannot find bucket: #{dir_name}" unless dir
|
16
16
|
puts "LastModified \t SIZE \t Object"
|
17
|
-
|
18
|
-
|
17
|
+
if prefix
|
18
|
+
dir.files.all(:prefix => prefix).each do |file|
|
19
|
+
puts "#{file.last_modified} \t #{file.content_length} \t #{file.key}"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
dir.files.each do |file|
|
23
|
+
puts "#{file.last_modified} \t #{file.content_length} \t #{file.key}"
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
|
-
def upload_file
|
23
|
-
dir =
|
28
|
+
def upload_file(dir_name, file_path, dest_path=nil)
|
29
|
+
dir = @conn.directories.get(dir_name)
|
24
30
|
abort "cannot find bucket: #{dir_name}" unless dir
|
25
31
|
file = File.expand_path(file_path)
|
26
32
|
abort "Invalid file path: #{file_path}" unless File.exist?(file)
|
33
|
+
if dest_path && !dest_path.end_with?('/')
|
34
|
+
dest_path = "#{dest_path}/"
|
35
|
+
end
|
27
36
|
file_name = File.basename(file)
|
28
37
|
dir.files.create(
|
29
|
-
:key => file_name,
|
38
|
+
:key => "#{dest_path}#{file_name}",
|
30
39
|
:body => File.open(file),
|
31
40
|
:public => true
|
32
41
|
)
|
33
42
|
puts "Uploaded file: #{file_name} to bucket: #{dir_name}"
|
34
43
|
end
|
35
44
|
|
36
|
-
def upload_file_rec
|
45
|
+
def upload_file_rec(options)
|
37
46
|
dir_name, dir_path, threads_count, is_public = options[:bucket_name], options[:dir_path], options[:thread_count], options[:public]
|
38
47
|
dest_path = options[:dest_path] if options[:dest_path]
|
39
48
|
#check if bucket exists
|
40
|
-
bucket =
|
49
|
+
bucket = @conn.directories.get(dir_name)
|
41
50
|
abort "cannot find bucket: #{dir_name}" unless bucket
|
42
51
|
#check if passed path is a dir
|
43
52
|
dir = File.expand_path(dir_path)
|
@@ -93,9 +102,9 @@ module Awscli
|
|
93
102
|
puts "Uploaded #{total_files} (#{total_size / 1024} KB)"
|
94
103
|
end
|
95
104
|
|
96
|
-
def multipart_upload
|
105
|
+
def multipart_upload(options)
|
97
106
|
bucket_name, file_path, tmp_loc, acl = options[:bucket_name], options[:file_path], options[:tmp_dir], options[:acl]
|
98
|
-
dir =
|
107
|
+
dir = @conn.directories.get(bucket_name)
|
99
108
|
abort "cannot find bucket: #{bucket_name}" unless dir
|
100
109
|
file = File.expand_path(file_path)
|
101
110
|
abort "Invalid file path: #{file_path}" unless File.exist?(file)
|
@@ -128,7 +137,7 @@ module Awscli
|
|
128
137
|
|
129
138
|
#initiate the mulitpart upload & store the returned upload_id
|
130
139
|
puts "Initializing multipart upload"
|
131
|
-
multi_part_up =
|
140
|
+
multi_part_up = @conn.initiate_multipart_upload(
|
132
141
|
bucket_name, # name of the bucket to create object in
|
133
142
|
remote_file, # name of the object to create
|
134
143
|
{ 'x-amz-acl' => acl }
|
@@ -142,7 +151,7 @@ module Awscli
|
|
142
151
|
part_number = (position + 1).to_s
|
143
152
|
puts "Uploading #{part} ..."
|
144
153
|
File.open part do |part_file|
|
145
|
-
response =
|
154
|
+
response = @conn.upload_part(
|
146
155
|
bucket_name,
|
147
156
|
# file[1..-1],
|
148
157
|
remote_file,
|
@@ -155,7 +164,7 @@ module Awscli
|
|
155
164
|
end
|
156
165
|
|
157
166
|
puts "Completing multipart upload ..."
|
158
|
-
response =
|
167
|
+
response = @conn.complete_multipart_upload(
|
159
168
|
bucket_name,
|
160
169
|
# file[1..-1],
|
161
170
|
remote_file,
|
@@ -167,8 +176,8 @@ module Awscli
|
|
167
176
|
puts "Successfully completed multipart upload"
|
168
177
|
end
|
169
178
|
|
170
|
-
def download_file
|
171
|
-
dir =
|
179
|
+
def download_file(dir_name, file_name, path)
|
180
|
+
dir = @conn.directories.get(dir_name)
|
172
181
|
abort "cannot find bucket: #{dir_name}" unless dir
|
173
182
|
local_path = File.expand_path(path)
|
174
183
|
abort "Invalid file path: #{path}" unless File.exist?(local_path)
|
@@ -180,9 +189,9 @@ module Awscli
|
|
180
189
|
puts "Downloaded file: #{remote_file.key} to path: #{local_path}"
|
181
190
|
end
|
182
191
|
|
183
|
-
def delete_file
|
192
|
+
def delete_file(dir_name, file_name)
|
184
193
|
#TODO: Handle globs for deletions
|
185
|
-
dir =
|
194
|
+
dir = @conn.directories.get(dir_name)
|
186
195
|
abort "cannot find bucket: #{dir_name}" unless dir
|
187
196
|
remote_file = dir.files.get(file_name)
|
188
197
|
abort "cannot find file: #{file_name}" unless remote_file
|
@@ -190,35 +199,38 @@ module Awscli
|
|
190
199
|
puts "Deleted file: #{file_name}"
|
191
200
|
end
|
192
201
|
|
193
|
-
def copy_file
|
194
|
-
|
202
|
+
def copy_file(source_dir, source_file, dest_dir, dest_file)
|
203
|
+
@conn.directories.get(source_dir).files.get(source_file).copy(dest_dir, dest_file)
|
195
204
|
end
|
196
205
|
|
197
|
-
def get_public_url
|
198
|
-
url =
|
206
|
+
def get_public_url(dir_name, file_name)
|
207
|
+
url = @conn.directories.get(dir_name).files.get(file_name).public_url
|
199
208
|
puts "public url for the file: #{file_name} is #{url}"
|
200
209
|
end
|
201
210
|
end
|
202
211
|
|
203
212
|
class Directories
|
204
|
-
def initialize
|
205
|
-
|
213
|
+
def initialize(connection, options = {})
|
214
|
+
@conn = connection
|
206
215
|
end
|
207
216
|
|
208
217
|
def list
|
209
|
-
|
218
|
+
@conn.directories.table
|
210
219
|
end
|
211
220
|
|
212
|
-
def create
|
213
|
-
dir =
|
221
|
+
def create(bucket_name, is_public)
|
222
|
+
dir = @conn.directories.create(
|
214
223
|
:key => bucket_name,
|
215
224
|
:public => is_public
|
216
225
|
)
|
226
|
+
rescue Excon::Errors::Conflict
|
227
|
+
puts "Bucket already exists, bucket name should be unique globally"
|
228
|
+
else
|
217
229
|
puts "Created bucket: #{dir.key}"
|
218
230
|
end
|
219
231
|
|
220
232
|
def delete dir_name
|
221
|
-
dir =
|
233
|
+
dir = @conn.directories.get(dir_name)
|
222
234
|
abort "Cannot find bucket #{dir_name}" unless dir
|
223
235
|
#check if the dir is empty or not
|
224
236
|
abort "Bucket is not empty, use rec_delete to force delete bucket" if dir.files.length != 0
|
@@ -226,7 +238,7 @@ module Awscli
|
|
226
238
|
puts "Deleted Bucket: #{dir_name}"
|
227
239
|
end
|
228
240
|
|
229
|
-
def delete_rec
|
241
|
+
def delete_rec(dir_name)
|
230
242
|
#Forked from https://gist.github.com/bdunagan/1383301
|
231
243
|
data_queue = Queue.new
|
232
244
|
semaphore = Mutex.new
|
@@ -234,7 +246,7 @@ module Awscli
|
|
234
246
|
total_listed = 0
|
235
247
|
total_deleted = 0
|
236
248
|
thread_count = 20 #num_of_threads to perform deletion
|
237
|
-
dir =
|
249
|
+
dir = @conn.directories.get(dir_name)
|
238
250
|
abort "Cannot find bucket #{dir_name}" unless dir
|
239
251
|
if dir.files.length != 0
|
240
252
|
if agree("Are you sure want to delete all the objects in the bucket ? ", true)
|
@@ -288,25 +300,25 @@ module Awscli
|
|
288
300
|
end
|
289
301
|
end
|
290
302
|
|
291
|
-
def get_acl
|
292
|
-
dir =
|
303
|
+
def get_acl(dir_name)
|
304
|
+
dir = @conn.directories.get(dir_name)
|
293
305
|
abort "Cannot find bucket #{dir_name}" unless dir
|
294
306
|
puts dir.acl
|
295
307
|
end
|
296
308
|
|
297
|
-
def set_acl
|
298
|
-
dir =
|
309
|
+
def set_acl(dir_name, acl)
|
310
|
+
dir = @conn.directories.get(dir_name)
|
299
311
|
abort "Cannot find bucket #{dir_name}" unless dir
|
300
312
|
dir.acl = acl
|
301
313
|
puts "Acl has been changed to #{acl}"
|
302
314
|
end
|
303
315
|
|
304
|
-
def get_logging_status
|
305
|
-
puts
|
316
|
+
def get_logging_status(dir_name)
|
317
|
+
puts @conn.get_bucket_logging(dir_name).body['BucketLoggingStatus']
|
306
318
|
end
|
307
319
|
|
308
|
-
def set_logging_status
|
309
|
-
|
320
|
+
def set_logging_status(dir_name, logging_status = {})
|
321
|
+
@conn.put_bucket_logging dir_name, logging_status
|
310
322
|
end
|
311
323
|
end
|
312
324
|
|
data/lib/awscli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awscli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashrith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/awscli/cli/ec2/vpc/route_tables.rb
|
135
135
|
- lib/awscli/cli/ec2/vpc.rb
|
136
136
|
- lib/awscli/cli/ec2.rb
|
137
|
+
- lib/awscli/cli/emr.rb
|
137
138
|
- lib/awscli/cli/iam/group.rb
|
138
139
|
- lib/awscli/cli/iam/policies.rb
|
139
140
|
- lib/awscli/cli/iam/profiles.rb
|
@@ -143,9 +144,11 @@ files:
|
|
143
144
|
- lib/awscli/cli/s3/directories.rb
|
144
145
|
- lib/awscli/cli/s3/files.rb
|
145
146
|
- lib/awscli/cli/s3.rb
|
147
|
+
- lib/awscli/cli/UsageExamples/emr
|
146
148
|
- lib/awscli/cli.rb
|
147
149
|
- lib/awscli/connection.rb
|
148
150
|
- lib/awscli/ec2.rb
|
151
|
+
- lib/awscli/emr.rb
|
149
152
|
- lib/awscli/errors.rb
|
150
153
|
- lib/awscli/helper.rb
|
151
154
|
- lib/awscli/iam.rb
|