Class: S3crets::Actions::Get

Inherits:
Base
  • Object
show all
Defined in:
lib/s3crets/actions/get.rb

Overview

Fetch a single secret

Instance Attribute Summary collapse

Attributes inherited from Base

#logger, #options

Instance Method Summary collapse

Constructor Details

#initialize(ui, options, path) ⇒ Get

Returns a new instance of Get.



12
13
14
15
# File 'lib/s3crets/actions/get.rb', line 12

def initialize(ui, options, path)
  super(ui, options)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/s3crets/actions/get.rb', line 10

def path
  @path
end

Instance Method Details

#fetch_secret(path) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/s3crets/actions/get.rb', line 21

def fetch_secret(path)
  filename = File.basename(path)

  s3 = ::Aws::S3::Client.new(region: options['region'])
  resp = s3.get_object(bucket: options['bucket'],
                       key: path)

  File.write(filename, resp.body.read)
end

#runObject



17
18
19
# File 'lib/s3crets/actions/get.rb', line 17

def run
  fetch_secret(@path)
end