Class: RightScraper::Scanners::CookbookS3Upload
- Defined in:
- lib/right_scraper/scanners/cookbook_s3_upload.rb
Overview
Upload scanned files to an S3 bucket.
Instance Method Summary collapse
-
#end(cookbook) ⇒ Object
Upon ending a scan for a cookbook, upload the cookbook contents to S3.
-
#initialize(options = {}) ⇒ CookbookS3Upload
constructor
Create a new S3Upload.
-
#notice(relative_position) ⇒ Object
Upload a file during scanning.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ CookbookS3Upload
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 cookbooks to.
Parameters
- options(Hash)
-
scanner options
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/right_scraper/scanners/cookbook_s3_upload.rb', line 43 def initialize(={}) super s3_key = .fetch(:s3_key) s3_secret = .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(.fetch(:s3_bucket)) raise "Need an actual, existing S3 bucket!" if @bucket.nil? end |
Instance Method Details
#end(cookbook) ⇒ Object
Upon ending a scan for a cookbook, upload the cookbook contents to S3.
Parameters
- cookbook(RightScraper::Cookbook)
-
cookbook to scan
59 60 61 62 63 64 65 |
# File 'lib/right_scraper/scanners/cookbook_s3_upload.rb', line 59 def end(cookbook) path = File.join('Cooks', cookbook.resource_hash) unless @bucket.key(path).exists? contents = cookbook.manifest_json @bucket.put(path, contents) end 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
75 76 77 78 79 80 81 82 |
# File 'lib/right_scraper/scanners/cookbook_s3_upload.rb', line 75 def notice(relative_position) contents = yield name = Digest::MD5.hexdigest(contents) path = File.join('Files', name) unless @bucket.key(path).exists? @bucket.put(path, contents) end end |