awful 0.0.106 → 0.0.107

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/awful/s3.rb +35 -0
  3. data/lib/awful/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f47d50305aa745ea1d3e1ebccf4019a5834aea45
4
- data.tar.gz: 68a3a50fcabc0a9afd326836fdc70181f0938844
3
+ metadata.gz: 51063a3a1c4c58bab96dfa743006f334a9ffbdb5
4
+ data.tar.gz: f6bf657fb70555adad45c6b0878bd921e83da297
5
5
  SHA512:
6
- metadata.gz: df09dbe48421998771f3aa5591430ebd2cccdf2a7a1bd9061e4d9515e01289ad4dce64c376a287c3a35727a629806f6695ab4839737335ab31a122365bc81cbd
7
- data.tar.gz: fc42025f14e2f16a17a5cebbbb75c9091a059fccdcb37cb2fb398e002e39030afce635f230465b8ba51e0992cfef2d45b3269828a57018d58549558fe5e29295
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
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.106'
2
+ VERSION = '0.0.107'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.106
4
+ version: 0.0.107
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister