Class: Healthchecker::Checks::S3

Inherits:
Healthchecker::Check show all
Defined in:
lib/healthchecker/checks/s3.rb

Instance Attribute Summary

Attributes inherited from Healthchecker::Check

#options

Instance Method Summary collapse

Methods inherited from Healthchecker::Check

#initialize, #perform_check

Constructor Details

This class inherits a constructor from Healthchecker::Check

Instance Method Details

#check!Object



6
7
8
9
# File 'lib/healthchecker/checks/s3.rb', line 6

def check!
  options[:buckets].each {|bucket| check_bucket_access(bucket)}
  nil
end

#check_bucket_access(bucket) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/healthchecker/checks/s3.rb', line 15

def check_bucket_access(bucket)
  object_key = options[:object_key] || "healthchecker/#{Time.now.to_i}.json"
  client.put_object(body: 'ok', bucket: bucket, key: object_key)
  raise "Could not read object from bucket '#{bucket}'" unless client.get_object(
    bucket: bucket,
    key: object_key,
  ).body.read == 'ok'
  client.delete_object(bucket: bucket, key: object_key)
end

#clientObject



11
12
13
# File 'lib/healthchecker/checks/s3.rb', line 11

def client
  options[:client] || Aws::S3::Client.new
end