Class: Secrets::S3
- Inherits:
-
Object
- Object
- Secrets::S3
- Defined in:
- lib/secrets_parser/s3.rb
Instance Method Summary collapse
- #decrypt(io) ⇒ Object
- #download(filename) ⇒ Object
-
#initialize(s3_client, kms_client, logger) ⇒ S3
constructor
A new instance of S3.
- #logger ⇒ Object
Constructor Details
#initialize(s3_client, kms_client, logger) ⇒ S3
Returns a new instance of S3.
12 13 14 15 16 |
# File 'lib/secrets_parser/s3.rb', line 12 def initialize(s3_client, kms_client, logger) @s3_client = s3_client @kms_client = kms_client @logger = logger end |
Instance Method Details
#decrypt(io) ⇒ Object
30 31 32 |
# File 'lib/secrets_parser/s3.rb', line 30 def decrypt(io) @kms_client.decrypt(ciphertext_blob: io.read).plaintext end |
#download(filename) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/secrets_parser/s3.rb', line 18 def download(filename) bucket_name, file = filename.split('/', 2) @logger.info "Downloading #{file} from #{bucket_name}" begin resp = @s3_client.get_object(bucket: bucket_name, key: file) resp.body rescue Aws::S3::Errors::NoSuchKey raise Secrets::Errors::NoSuchFile, "Secret file #{file} does not exist in #{bucket_name}" end end |
#logger ⇒ Object
34 35 36 |
# File 'lib/secrets_parser/s3.rb', line 34 def logger @config.logger end |