module Dotenv::S3

Constants

VERSION

Public Class Methods

decode64(body) click to toggle source
# File lib/dotenv/s3.rb, line 45
def decode64(body)
  Base64.decode64(body)
end
kms_client() click to toggle source
# File lib/dotenv/s3.rb, line 37
def kms_client
  Aws::KMS::Client.new(
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    region:            ENV['AWS_REGION']
  )
end
load(bucket: nil, filename: nil, base64_encoded: false, kms_key_id: nil) { |f| ... } click to toggle source
# File lib/dotenv/s3.rb, line 10
def load(bucket: nil, filename: nil, base64_encoded: false, kms_key_id: nil)
  dotenv_body = s3_client.get_object(bucket: bucket, key: filename).body.read

  if kms_key_id
    blob = decode64(dotenv_body)
    dotenv_body = decrypt_by_kms(blob)
  end

  dotenv_body = decode64(dotenv_body) if base64_encoded

  if block_given?
    create_tempfile(dotenv_body) do |f|
      yield f
    end
  else
    create_dotenv(dotenv_body)
  end
end
s3_client() click to toggle source
# File lib/dotenv/s3.rb, line 29
def s3_client
  Aws::S3::Client.new(
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    region:            ENV['AWS_REGION']
  )
end

Private Class Methods

create_dotenv(body) click to toggle source
# File lib/dotenv/s3.rb, line 63
def create_dotenv(body)
  File.open('.env', 'w') do |f|
    f.write(body)
  end
end
create_tempfile(body) { |f| ... } click to toggle source
# File lib/dotenv/s3.rb, line 55
def create_tempfile(body, &block)
  Tempfile.create("s3-dotenv") do |f|
    f.write(body)
    f.rewind
    yield f
  end
end
decrypt_by_kms(body) click to toggle source
# File lib/dotenv/s3.rb, line 51
def decrypt_by_kms(body)
  kms_client.decrypt(ciphertext_blob: body).plaintext
end