Class: RightScraper::Scanners::WorkflowS3Upload

Inherits:
Base
  • Object
show all
Defined in:
lib/right_scraper/scanners/workflow_s3_upload.rb

Overview

Upload workflow definition and metadata to an S3 bucket.

Instance Method Summary collapse

Methods inherited from Base

#begin, #finish, #notice_dir

Constructor Details

#initialize(options = {}) ⇒ WorkflowS3Upload

Create a new S3Upload. In addition to the options recognized by Scanner, this class recognizes :s3_key, :s3_secret, and :s3_bucket and requires all of those.

Options

:s3_key

Required. S3 access key.

:s3_secret

Required. S3 secret key.

:s3_bucket

Required. Bucket to upload workflows to.

Parameters

options(Hash)

scanner options



42
43
44
45
46
47
48
49
50
51
# File 'lib/right_scraper/scanners/workflow_s3_upload.rb', line 42

def initialize(options={})
  super
  s3_key = options.fetch(:s3_key)
  s3_secret = options.fetch(:s3_secret)
  s3 = RightAws::S3.new(aws_access_key_id=s3_key,
                        aws_secret_access_key=s3_secret,
                        :logger => Logger.new)
  @bucket = s3.bucket(options.fetch(:s3_bucket))
  raise "Need an actual, existing S3 bucket!" if @bucket.nil?
end

Instance Method Details

#end(workflow) ⇒ Object

Upon ending a scan for a workflows, upload the workflows contents to S3.

Parameters

workflows(RightScraper::Workflows)

Workflow to scan



58
59
60
61
62
63
64
# File 'lib/right_scraper/scanners/workflow_s3_upload.rb', line 58

def end(workflow)
  @bucket.put(File.join('Workflows', workflow.resource_hash),
              {
                :metadata => workflow.,
                :manifest => workflow.manifest
              }.to_json)
end

#notice(relative_position) ⇒ Object

Upload a file during scanning.

Block

Return the data for this file. We use a block because it may not always be necessary to read the data.

Parameters

relative_position(String)

relative pathname for file from root of cookbook



74
75
76
77
78
79
80
81
82
# File 'lib/right_scraper/scanners/workflow_s3_upload.rb', line 74

def notice(relative_position)
  # TBD: Only uplad definition and metadata, will there be more files?
  contents = yield
  name = Digest::SHA1.hexdigest(contents)
  path = File.join('Files', name)
  unless @bucket.key(path).exists?
    @bucket.put(path, contents)
  end
end