Class: MinimalPipeline::Crossing

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeCrossing

Returns a new instance of Crossing.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/minimal_pipeline/crossing.rb', line 27

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

Parameters:

  • config_bucket (String)

    The name of the S3 bucket

  • filename (String)

    The name of the file that contains the desired content

Returns:

  • (String)

    The content that was stored in the file


58
59
60
# File 'lib/minimal_pipeline/crossing.rb', line 58

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

Parameters:

  • config_bucket (String)

    The name of the S3 bucket

  • filename (String)

    The name of the file to save content to in the bucket

  • content (String)

    The content to store in the file


48
49
50
# File 'lib/minimal_pipeline/crossing.rb', line 48

def upload_content(config_bucket, filename, content)
  @crossing.put_content(config_bucket, filename, content)
end