awful 0.0.106 → 0.0.107
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/awful/s3.rb +35 -0
- data/lib/awful/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51063a3a1c4c58bab96dfa743006f334a9ffbdb5
|
4
|
+
data.tar.gz: f6bf657fb70555adad45c6b0878bd921e83da297
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 383850d370c8e8b791b0208c22749917576a37fc494b1fe849d2f59b04f0fb5abf616b959c4a73dd6819c868e8f8e519f891ae9e5029c9abb8852a3157c0edb0
|
7
|
+
data.tar.gz: 3eeed77f798bfb99032b9b7435f6b0c9ec87e662476f02ff89b6a288b00f344d4f3629a495bc126b68622a88b96d4a3efbcabcbe01b42ee19127041e0cf1e96c
|
data/lib/awful/s3.rb
CHANGED
@@ -11,6 +11,12 @@ module Awful
|
|
11
11
|
def s3_resource
|
12
12
|
Aws::S3::Resource.new(client: s3)
|
13
13
|
end
|
14
|
+
|
15
|
+
def get_tags(bucket_name)
|
16
|
+
s3.get_bucket_tagging(bucket: bucket_name).tag_set
|
17
|
+
rescue Aws::S3::Errors::NoSuchTagSet # sdk throws this if no tags
|
18
|
+
nil
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
desc 'ls PATTERN', 'list buckets or objects'
|
@@ -45,6 +51,35 @@ module Awful
|
|
45
51
|
end.tap { |list| puts list }
|
46
52
|
end
|
47
53
|
|
54
|
+
desc 'tagged [NAME_PREFIX]', 'list buckets matching given tags'
|
55
|
+
method_option :tags, aliases: '-t', type: :array, default: [], desc: 'List of tag=value to filter'
|
56
|
+
method_option :stack, aliases: '-s', type: :string, default: nil, desc: 'Filter by stack name'
|
57
|
+
method_option :resource, aliases: '-r', type: :string, default: nil, desc: 'Filter by stack resource logical id'
|
58
|
+
def tagged(name = '.')
|
59
|
+
conditions = options[:tags].map do |tag|
|
60
|
+
key, value = tag.split('=')
|
61
|
+
->(set) { (set[0] == key) && (set[1] == value) }
|
62
|
+
end
|
63
|
+
if options[:stack]
|
64
|
+
conditions << ->(set) { (set[0] == 'aws:cloudformation:stack-name') && (set[1] == options[:stack]) }
|
65
|
+
end
|
66
|
+
if options[:resource]
|
67
|
+
conditions << ->(set) { (set[0] == 'aws:cloudformation:logical-id') && (set[1] == options[:resource]) }
|
68
|
+
end
|
69
|
+
|
70
|
+
## get all buckets and check for a match with conditions
|
71
|
+
s3.list_buckets.buckets.select do |b|
|
72
|
+
b.name.match(/^#{name}/i)
|
73
|
+
end.map do |bucket|
|
74
|
+
tags = get_tags(bucket.name) or next
|
75
|
+
tags.any? do |set|
|
76
|
+
conditions.any? { |c| c.call(set) }
|
77
|
+
end && bucket
|
78
|
+
end.select{|b| b}.tap do |buckets|
|
79
|
+
puts buckets.map(&:name)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
48
83
|
desc 'cat BUCKET/OBJECT', 'stream s3 object to stdout'
|
49
84
|
def cat(path)
|
50
85
|
bucket, key = path.split('/', 2)
|
data/lib/awful/version.rb
CHANGED