module Awspec::Helper::Finder::S3

Public Instance Methods

find_bucket(id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/awspec/helper/finder/s3.rb, line 88
def select_all_buckets
  s3_client.list_buckets.buckets
end