class Clarion::Stores::S3
Public Class Methods
new(region:, bucket:, prefix: nil, retry_interval: 0.1, retry_max: 10)
click to toggle source
# File lib/clarion/stores/s3.rb, line 6 def initialize(region:, bucket:, prefix: nil, retry_interval: 0.1, retry_max: 10) @region = region @bucket = bucket @prefix = prefix @retry_interval = retry_interval @retry_max = retry_max end
Public Instance Methods
authn_s3_key(authn_id)
click to toggle source
# File lib/clarion/stores/s3.rb, line 45 def authn_s3_key(authn_id) "#{@prefix}authn/#{authn_id}" end
find_authn(id)
click to toggle source
# File lib/clarion/stores/s3.rb, line 25 def find_authn(id) retry_count = 0 json = begin s3.get_object( bucket: @bucket, key: authn_s3_key(id), ).body.read rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::AccessDenied if retry_count < retry_max sleep @retry_interval retry_count += 1 retry else return nil end end Authn.new(**JSON.parse(json, symbolize_names: true)) end
s3()
click to toggle source
# File lib/clarion/stores/s3.rb, line 49 def s3 @s3 ||= Aws::S3::Client.new(region: @region) end
store_authn(authn)
click to toggle source
# File lib/clarion/stores/s3.rb, line 15 def store_authn(authn) s3.put_object( bucket: @bucket, key: authn_s3_key(authn.id), body: "#{authn.to_json(:all)}\n", content_type: 'application/json', ) self end