class CuffSert::RxS3Client
Public Class Methods
new(cli_args, aws_region = nil, client: nil)
click to toggle source
# File lib/cuffsert/rxs3client.rb, line 6 def initialize(cli_args, aws_region = nil, client: nil) @bucket, @path_prefix = split_prefix(cli_args[:s3_upload_prefix]) initargs = {retry_limit: 8} initargs[:region] = aws_region if aws_region @client = client || Aws::S3::Client.new(initargs) end
Public Instance Methods
upload(stack_uri)
click to toggle source
# File lib/cuffsert/rxs3client.rb, line 13 def upload(stack_uri) file = stack_uri.to_s.sub(/^file:\/+/, '/') name = File.basename(file) s3_uri = "s3://#{@bucket}/#{@path_prefix}#{name}" observable = Rx::Observable.create do |observer| body = open(file).read begin observer.on_next(Report.new("Uploading template to #{s3_uri}")) @client.put_object({ body: body, bucket: @bucket, key: "#{@path_prefix}#{name}" }) observer.on_completed rescue => e observer.on_error(e) end end [URI(s3_uri), observable] end
Private Instance Methods
split_prefix(s3_upload_prefix)
click to toggle source
# File lib/cuffsert/rxs3client.rb, line 36 def split_prefix(s3_upload_prefix) m = s3_upload_prefix.match(/^s3:\/\/([-a-z0-9]+)(\/?.*)$/) bucket = m[1] prefix = m[2].sub(/^\//, '') prefix += '/' unless prefix.empty? || prefix.end_with?('/') [bucket, prefix] end