Class: MinimalPipeline::Crossing
- Inherits:
-
Object
- Object
- MinimalPipeline::Crossing
- Defined in:
- lib/minimal_pipeline/crossing.rb
Overview
Here is an example of how to use this class to interact with Crossing.
“‘ crossing = MinimalPipeline::Crossing.new
# Upload crossing.upload_content(‘my-config-bucket’, ‘example.txt’, ‘foo’)
# Download content = crossing.download_file(‘my-config-bucket’, ‘example.txt’) puts content # Outputs ‘foo’ “‘
You will need the following environment variables to be present:
-
‘AWS_REGION` or `region`
-
‘keystore_kms_id`
For more information on Crossing see github.com/stelligent/crossing
Instance Method Summary collapse
-
#download_file(config_bucket, filename) ⇒ String
Securely downloads a file from an S3 bucket.
-
#initialize ⇒ Crossing
constructor
A new instance of Crossing.
-
#upload_content(config_bucket, filename, content) ⇒ Object
Securely uploads a file to an S3 bucket.
Constructor Details
#initialize ⇒ Crossing
Returns a new instance of Crossing.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/minimal_pipeline/crossing.rb', line 26 def initialize raise 'You must set env variable AWS_REGION or region.' \ if ENV['AWS_REGION'].nil? && ENV['region'].nil? raise 'You must set env variable keystore_kms_id.' \ if ENV['inventory_store_key'].nil? && ENV['keystore_kms_id'].nil? region = ENV['AWS_REGION'] || ENV['region'] keystore_kms_id = ENV['keystore_kms_id'] || ENV['inventory_store_key'] kms = Aws::KMS::Client.new(region: region) s3 = Aws::S3::Encryption::Client.new(kms_key_id: keystore_kms_id, kms_client: kms, region: region) @crossing = ::Crossing.new(s3) end |
Instance Method Details
#download_file(config_bucket, filename) ⇒ String
Securely downloads a file from an S3 bucket
57 58 59 |
# File 'lib/minimal_pipeline/crossing.rb', line 57 def download_file(config_bucket, filename) @crossing.get_content(config_bucket, filename) end |
#upload_content(config_bucket, filename, content) ⇒ Object
Securely uploads a file to an S3 bucket
47 48 49 |
# File 'lib/minimal_pipeline/crossing.rb', line 47 def upload_content(config_bucket, filename, content) @crossing.put_content(config_bucket, filename, content) end |