class NxtHerokuDatabaseBackup::Uploader::S3

Public Class Methods

build(bucket_name:, file_path:, backup_name:, credentials: default_credentials) click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 7
def build(bucket_name:, file_path:, backup_name:, credentials: default_credentials)
  new(
    bucket_name: bucket_name,
    file_path: file_path,
    backup_name: backup_name,
    credentials: credentials
  )
end

Private Class Methods

default_credentials() click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 18
def default_credentials
  {
    access_key_id: ENV.fetch('DATABASE_BACKUP_AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('DATABASE_BACKUP_AWS_SECRET_ACCESS_KEY'),
    region: ENV.fetch('DATABASE_BACKUP_AWS_REGION')
  }
end

Public Instance Methods

aws_object() click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 33
def aws_object
  @aws_object ||= begin
    ensure_bucket_exists
    Aws::S3::Resource.new(credentials).bucket(bucket_name).object(backup_name)
  end
end
call() click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 29
def call
  aws_object.upload_file(file_path)
end
client() click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 46
def client
  @client ||= Aws::S3::Client.new(**credentials)
end
ensure_bucket_exists() click to toggle source
# File lib/nxt_heroku_database_backup/uploader/s3.rb, line 40
def ensure_bucket_exists
  client.head_bucket(bucket: bucket_name)
rescue Aws::S3::Errors::NotFound
  client.create_bucket(bucket: bucket_name)
end