Module: Awspec::Helper::Finder::S3
- Included in:
- Awspec::Helper::Finder
- Defined in:
- lib/awspec/helper/finder/s3.rb
Instance Method Summary collapse
- #find_bucket(id) ⇒ Object
- #find_bucket_acl(id) ⇒ Object
- #find_bucket_cors(id) ⇒ Object
- #find_bucket_lifecycle_configuration(id) ⇒ Object
- #find_bucket_location(id) ⇒ Object
- #find_bucket_logging(id) ⇒ Object
- #find_bucket_policy(id) ⇒ Object
- #find_bucket_server_side_encryption(id) ⇒ Object
- #find_bucket_tag(id, tag_key) ⇒ Object
- #find_bucket_versioning(id) ⇒ Object
- #head_object(id, key) ⇒ Object
- #select_all_buckets ⇒ Object
Instance Method Details
#find_bucket(id) ⇒ Object
6 7 8 9 10 |
# File 'lib/awspec/helper/finder/s3.rb', line 6 def find_bucket(id) s3_client.list_buckets[:buckets].find do |bucket| bucket.name == id end end |
#find_bucket_acl(id) ⇒ Object
12 13 14 15 16 |
# File 'lib/awspec/helper/finder/s3.rb', line 12 def find_bucket_acl(id) s3_client.get_bucket_acl(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_cors(id) ⇒ Object
28 29 30 31 32 |
# File 'lib/awspec/helper/finder/s3.rb', line 28 def find_bucket_cors(id) s3_client.get_bucket_cors(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_lifecycle_configuration(id) ⇒ Object
75 76 77 78 79 |
# File 'lib/awspec/helper/finder/s3.rb', line 75 def find_bucket_lifecycle_configuration(id) s3_client.get_bucket_lifecycle_configuration(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_location(id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/awspec/helper/finder/s3.rb', line 40 def find_bucket_location(id) bucket_location = s3_client.get_bucket_location(bucket: id) if bucket_location.location_constraint.nil? || bucket_location.location_constraint.empty? 'us-east-1' else bucket_location.location_constraint end rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_logging(id) ⇒ Object
51 52 53 54 55 |
# File 'lib/awspec/helper/finder/s3.rb', line 51 def find_bucket_logging(id) s3_client.get_bucket_logging(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_policy(id) ⇒ Object
34 35 36 37 38 |
# File 'lib/awspec/helper/finder/s3.rb', line 34 def find_bucket_policy(id) s3_client.get_bucket_policy(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_server_side_encryption(id) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/awspec/helper/finder/s3.rb', line 81 def find_bucket_server_side_encryption(id) res = s3_client.get_bucket_encryption(bucket: id) res.server_side_encryption_configuration rescue Aws::S3::Errors::ServiceError nil end |
#find_bucket_tag(id, tag_key) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/awspec/helper/finder/s3.rb', line 57 def find_bucket_tag(id, tag_key) tag = nil begin bucket_tagging = s3_client.get_bucket_tagging(bucket: id) tag_set = bucket_tagging.tag_set tag = tag_set.find { |tag_obj| tag_obj.key == tag_key } rescue Aws::S3::Errors::ServiceError nil end return tag if tag end |
#find_bucket_versioning(id) ⇒ Object
69 70 71 72 73 |
# File 'lib/awspec/helper/finder/s3.rb', line 69 def find_bucket_versioning(id) s3_client.get_bucket_versioning(bucket: id) rescue Aws::S3::Errors::ServiceError nil end |
#head_object(id, key) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/awspec/helper/finder/s3.rb', line 18 def head_object(id, key) res = s3_client.head_object({ bucket: id, key: key.sub(%r{\A/}, '') }) res.data.instance_of?(Aws::S3::Types::HeadObjectOutput) rescue Aws::S3::Errors::NotFound false end |
#select_all_buckets ⇒ Object
88 89 90 |
# File 'lib/awspec/helper/finder/s3.rb', line 88 def select_all_buckets s3_client.list_buckets.buckets end |