Sha256: 9cd003c7f74ed87ed20c491f5879dc4836d1c5e12d47e4e0673a0312eee33db9

Contents?: true

Size: 950 Bytes

Versions: 5

Compression:

Stored size: 950 Bytes

Contents

require 'aws-sdk-s3'

module S3
  extend self

  # Write value to key in S3 bucket, with logging.
  #
  # @param bucket [String]
  # @param key [String]
  # @param value [String]
  def write(bucket, key, value)
    Vault::Log.log(:fn => __method__, :key => key) do
      s3.put_object({bucket: bucket, key: key, body: value})
    end
  end

  # Read value from key in S3 bucket, with logging.
  #
  # @param bucket [String]
  # @param key [String]
  def read(bucket, key)
    Vault::Log.log(:fn => __method__, :key => key) do
      s3.get_object({bucket: bucket, key: key}).body.read
    end
  end

  # Get the underlying AWS::S3::Client instance, creating it using environment
  # vars if necessary.
  def s3
    @s3 ||= Aws::S3::Client.new(
      credentials: Aws::Credentials.new(Config.env('AWS_ACCESS_KEY_ID'),
                                        Config.env('AWS_SECRET_ACCESS_KEY')),
      region: Config.env('AWS_REGION')
    )
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vault-tools-2.1.1 lib/vault-tools/s3.rb
vault-tools-2.1.0 lib/vault-tools/s3.rb
vault-tools-2.0.2 lib/vault-tools/s3.rb
vault-tools-2.0.1 lib/vault-tools/s3.rb
vault-tools-2.0.0 lib/vault-tools/s3.rb