cliaws 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.txt +8 -3
- data/VERSION +1 -1
- data/cliaws.gemspec +2 -2
- data/lib/cliaws/cli/s3.rb +82 -0
- data/lib/cliaws/s3.rb +51 -2
- metadata +2 -2
data/README.txt
CHANGED
@@ -29,6 +29,9 @@ Usage from the command line:
|
|
29
29
|
# Returns a YAML representation of response and metadata headers
|
30
30
|
$ clis3 rm my_awesome_bucket/a_key_name
|
31
31
|
|
32
|
+
$ cliec2 launch AMI --keypair KEYPAIR
|
33
|
+
$ cliec2 list
|
34
|
+
|
32
35
|
Cliaws may also be used from Ruby:
|
33
36
|
|
34
37
|
Cliaws.s3.list("my_awesome_bucket/a_glob") # Returns an array of names
|
@@ -39,10 +42,12 @@ Cliaws may also be used from Ruby:
|
|
39
42
|
Cliaws.s3.head("my_awesome_bucket/a_key_name")
|
40
43
|
Cliaws.s3.rm("my_awesome_bucket/a_key_name")
|
41
44
|
|
45
|
+
Cliaws.ec2.run("AMI", :keypair => "KEYPAIR")
|
46
|
+
Cliaws.ec2.list
|
47
|
+
|
42
48
|
== REQUIREMENTS:
|
43
49
|
|
44
|
-
*
|
45
|
-
* right_aws
|
50
|
+
* thor
|
46
51
|
|
47
52
|
== INSTALL:
|
48
53
|
|
@@ -52,7 +57,7 @@ Cliaws may also be used from Ruby:
|
|
52
57
|
|
53
58
|
(The MIT License)
|
54
59
|
|
55
|
-
Copyright (c) 2008 François Beausoleil (francois@teksol.info)
|
60
|
+
Copyright (c) 2008-2009 François Beausoleil (francois@teksol.info)
|
56
61
|
|
57
62
|
Permission is hereby granted, free of charge, to any person obtaining
|
58
63
|
a copy of this software and associated documentation files (the
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.7.0
|
data/cliaws.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cliaws}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.7.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Fran\303\247ois Beausoleil"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-20}
|
10
10
|
s.description = %q{A command-line suite of tools to access Amazon Web Services, using the RightAws gems.}
|
11
11
|
s.email = %q{francois@teksol.info}
|
12
12
|
s.executables = ["clis3", "clisqs", "cliec2"]
|
data/lib/cliaws/cli/s3.rb
CHANGED
@@ -6,6 +6,32 @@ module Cliaws
|
|
6
6
|
class S3 < Thor
|
7
7
|
map ["-h", "--help"] => :help
|
8
8
|
|
9
|
+
desc "buckets", <<EOD
|
10
|
+
Returns a list of bucket names.
|
11
|
+
EOD
|
12
|
+
def buckets
|
13
|
+
puts Cliaws.s3.buckets.map {|bucket| bucket.name}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "create BUCKET", <<EOD
|
17
|
+
Creates a new bucket. If the bucket already exists, this command returns 1.
|
18
|
+
EOD
|
19
|
+
def create(name)
|
20
|
+
Cliaws.s3.bucket(name, true)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "delete BUCKET", <<EOD
|
24
|
+
Deletes the named bucket. Will only delete the bucket if it is empty, unless --force.
|
25
|
+
Returns 1 if the bucket did not exist.
|
26
|
+
Returns 0 if the bucket existed and was deleted.
|
27
|
+
EOD
|
28
|
+
method_options :force => false
|
29
|
+
def delete(name)
|
30
|
+
bucket = Cliaws.s3.bucket(name, false)
|
31
|
+
exit 1 if bucket.nil?
|
32
|
+
bucket.delete(options[:force])
|
33
|
+
end
|
34
|
+
|
9
35
|
desc "url S3_OBJECT_PATH", <<EOD
|
10
36
|
Returns a signed, private, URL to the given S3 object that is valid for 24 hours.
|
11
37
|
EOD
|
@@ -167,6 +193,62 @@ EOD
|
|
167
193
|
rescue Cliaws::S3::UnknownBucket
|
168
194
|
abort "Could not find bucket named #{$!.bucket_name}"
|
169
195
|
end
|
196
|
+
|
197
|
+
desc "grants BUCKET|KEY", <<EOD
|
198
|
+
Returns a YAML representation of grants assigned to a bucket or key.
|
199
|
+
EOD
|
200
|
+
def grants(thing)
|
201
|
+
result = Cliaws.s3.grants(thing).inject(Hash.new) do |memo, grant|
|
202
|
+
memo[grant.to_s] = grant.perms
|
203
|
+
memo
|
204
|
+
end
|
205
|
+
|
206
|
+
result = {thing => result}.to_yaml
|
207
|
+
puts result
|
208
|
+
end
|
209
|
+
|
210
|
+
desc "grant BUCKET|KEY (ID|EMAIL|AllUsers|AuthenticatedUsers) PERMISSION [PERMISSION...]", <<EOD
|
211
|
+
Grants one or more permissions to a user or group. Returns the new permissions on the bucket or key as YAML.
|
212
|
+
|
213
|
+
Examples
|
214
|
+
cliec2 grant my_awesome_bucket/some/key AllUsers READ
|
215
|
+
cliec2 grant my_private_bucket friend@somewhere.com full-control
|
216
|
+
cliec2 grant movies a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9 read WRITE
|
217
|
+
EOD
|
218
|
+
def grant(thing, who, *permissions)
|
219
|
+
who = case who
|
220
|
+
when /^AllUsers$/i
|
221
|
+
"http://acs.amazonaws.com/groups/global/AllUsers"
|
222
|
+
when /^AuthenticatedUsers$/i
|
223
|
+
"http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
|
224
|
+
else
|
225
|
+
who
|
226
|
+
end
|
227
|
+
Cliaws.s3.grant(thing, who => permissions.map {|perm| perm.gsub('-', '_')})
|
228
|
+
grants(thing)
|
229
|
+
end
|
230
|
+
|
231
|
+
desc "revoke BUCKET|KEY (ID|EMAIL|AllUsers|AuthenticatedUsers) [PERMISSION [PERMISSION...]]", <<EOD
|
232
|
+
Revokes one or more permissions to a user or group. If no permissions are given, all grants are dropped. Returns the new permissions on the bucket or key as YAML.
|
233
|
+
|
234
|
+
Examples
|
235
|
+
cliec2 revoke my_awesome_bucket/some/key AllUsers
|
236
|
+
cliec2 revoke my_awesome_bucket/some/key AllUsers READ
|
237
|
+
cliec2 revoke my_private_bucket friend@somewhere.com full-control
|
238
|
+
cliec2 revoke movies a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9 read WRITE
|
239
|
+
EOD
|
240
|
+
def revoke(thing, who, *permissions)
|
241
|
+
who = case who
|
242
|
+
when /^AllUsers$/i
|
243
|
+
"http://acs.amazonaws.com/groups/global/AllUsers"
|
244
|
+
when /^AuthenticatedUsers$/i
|
245
|
+
"http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
|
246
|
+
else
|
247
|
+
who
|
248
|
+
end
|
249
|
+
Cliaws.s3.grant(thing, who => permissions.map {|perm| perm.gsub('_', '-')})
|
250
|
+
grants(thing)
|
251
|
+
end
|
170
252
|
end
|
171
253
|
end
|
172
254
|
end
|
data/lib/cliaws/s3.rb
CHANGED
@@ -48,16 +48,65 @@ module Cliaws
|
|
48
48
|
bucket.key(keyname).delete
|
49
49
|
end
|
50
50
|
|
51
|
+
def bucket(name, create=false)
|
52
|
+
s3.bucket(name, create)
|
53
|
+
end
|
54
|
+
|
55
|
+
def buckets
|
56
|
+
s3.buckets
|
57
|
+
end
|
58
|
+
|
59
|
+
# +permissions+ is a Hash of ID|EMAIL|URL to permissions.
|
60
|
+
# Cliaws.s3.revoke("my_awesome_bucket/some/key", "francois@teksol.info" => %w(read write))
|
61
|
+
# Cliaws.s3.revoke("my_awesome_bucket/some/key", "francois@teksol.info" => %w()) # Drops all grants for the user
|
62
|
+
def revoke(name, permissions)
|
63
|
+
bucket, thing = bucket_and_thing(name)
|
64
|
+
permissions.each do |subject, perms|
|
65
|
+
grantee = RightAws::S3::Grantee.new(thing, subject, perms.map {|perm| perm.upcase}, :refresh)
|
66
|
+
if perms.empty? then
|
67
|
+
grantee.drop
|
68
|
+
else
|
69
|
+
grantee.revoke(*permissions)
|
70
|
+
grantee.apply
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# +permissions+ is a Hash of ID|EMAIL|URL to permissions.
|
76
|
+
# Cliaws.s3.grant("my_awesome_bucket/some/key", "francois@teksol.info" => %w(read write))
|
77
|
+
def grant(name, permissions)
|
78
|
+
bucket, thing = bucket_and_thing(name)
|
79
|
+
permissions.each do |subject, perms|
|
80
|
+
RightAws::S3::Grantee.new(thing, subject, perms.map {|perm| perm.upcase}, :apply)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def grants(name)
|
85
|
+
bucket, thing = bucket_and_thing(name)
|
86
|
+
_, grantees = RightAws::S3::Grantee.owner_and_grantees(thing)
|
87
|
+
grantees
|
88
|
+
end
|
89
|
+
|
51
90
|
protected
|
52
91
|
def bucket_and_key_name(full_name, create=true)
|
53
92
|
bucket_name, path = full_name.split("/", 2)
|
54
|
-
bucket =
|
93
|
+
bucket = bucket(bucket_name, create)
|
55
94
|
raise UnknownBucket.new(bucket_name) unless bucket
|
56
95
|
[bucket, path]
|
57
96
|
end
|
58
97
|
|
98
|
+
def bucket_and_thing(name)
|
99
|
+
bucket, keyname = bucket_and_key_name(name, false)
|
100
|
+
thing = keyname.nil? ? bucket : bucket.key(keyname)
|
101
|
+
[bucket, thing]
|
102
|
+
end
|
103
|
+
|
59
104
|
def s3
|
60
|
-
@s3 ||=
|
105
|
+
@s3 ||= begin
|
106
|
+
logger = Logger.new(STDOUT)
|
107
|
+
logger.level = Logger::DEBUG
|
108
|
+
RightAws::S3.new(access_key_id, secret_access_key, :logger => logger)
|
109
|
+
end
|
61
110
|
end
|
62
111
|
|
63
112
|
def s3g
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliaws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Fran\xC3\xA7ois Beausoleil"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-20 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|