Module: Awspec::Helper::Finder::S3

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/s3.rb

Instance Method Summary collapse

Instance Method Details

#find_bucket(id) ⇒ Object



4
5
6
7
8
# File 'lib/awspec/helper/finder/s3.rb', line 4

def find_bucket(id)
  s3_client.list_buckets[:buckets].find do |bucket|
    bucket.name == id
  end
end

#find_bucket_acl(id) ⇒ Object



10
11
12
13
14
# File 'lib/awspec/helper/finder/s3.rb', line 10

def find_bucket_acl(id)
  s3_client.get_bucket_acl(bucket: id)
rescue Aws::S3::Errors::ServiceError
  nil
end

#find_bucket_cors(id) ⇒ Object



26
27
28
29
30
# File 'lib/awspec/helper/finder/s3.rb', line 26

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



62
63
64
65
66
# File 'lib/awspec/helper/finder/s3.rb', line 62

def find_bucket_lifecycle_configuration(id)
  s3_client.get_bucket_lifecycle_configuration(bucket: id)
rescue Aws::S3::Errors::ServiceError
  nil
end

#find_bucket_logging(id) ⇒ Object



38
39
40
41
42
# File 'lib/awspec/helper/finder/s3.rb', line 38

def find_bucket_logging(id)
  s3_client.get_bucket_logging(bucket: id)
rescue Aws::S3::Errors::ServiceError
  nil
end

#find_bucket_policy(id) ⇒ Object



32
33
34
35
36
# File 'lib/awspec/helper/finder/s3.rb', line 32

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



68
69
70
71
72
73
# File 'lib/awspec/helper/finder/s3.rb', line 68

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



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/awspec/helper/finder/s3.rb', line 44

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



56
57
58
59
60
# File 'lib/awspec/helper/finder/s3.rb', line 56

def find_bucket_versioning(id)
  s3_client.get_bucket_versioning(bucket: id)
rescue Aws::S3::Errors::ServiceError
  nil
end

#head_object(id, key) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/awspec/helper/finder/s3.rb', line 16

def head_object(id, key)
  res = s3_client.head_object({
                                bucket: id,
                                key: key.sub(%r(\A/), '')
                              })
  res.data.class == Aws::S3::Types::HeadObjectOutput
rescue Aws::S3::Errors::NotFound
  false
end

#select_all_bucketsObject



75
76
77
# File 'lib/awspec/helper/finder/s3.rb', line 75

def select_all_buckets
  s3_client.list_buckets.buckets
end