Class: CuffSert::RxS3Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cuffsert/rxs3client.rb

Instance Method Summary collapse

Constructor Details

#initialize(cli_args, aws_region = nil, client: nil) ⇒ RxS3Client

Returns a new instance of RxS3Client.



7
8
9
10
11
12
# File 'lib/cuffsert/rxs3client.rb', line 7

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

Instance Method Details

#upload(stack_uri) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cuffsert/rxs3client.rb', line 14

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