Module: S3

Extended by:
S3
Included in:
S3
Defined in:
lib/vault-tools/s3.rb

Instance Method Summary collapse

Instance Method Details

#read(bucket, key) ⇒ Object

Read value from key in S3 bucket, with logging.

Parameters:

  • bucket (String)
  • key (String)


21
22
23
24
25
# File 'lib/vault-tools/s3.rb', line 21

def read(bucket, key)
  Vault::Log.log(:fn => __method__, :key => key) do
    s3.get_object({bucket: bucket, key: key}).body.read
  end
end

#s3Object

Get the underlying AWS::S3::Client instance, creating it using environment vars if necessary.



29
30
31
32
33
34
35
# File 'lib/vault-tools/s3.rb', line 29

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

#write(bucket, key, value) ⇒ Object

Write value to key in S3 bucket, with logging.

Parameters:

  • bucket (String)
  • key (String)
  • value (String)


11
12
13
14
15
# File 'lib/vault-tools/s3.rb', line 11

def write(bucket, key, value)
  Vault::Log.log(:fn => __method__, :key => key) do
    s3.put_object({bucket: bucket, key: key, body: value})
  end
end