Class: Browserctl::State::Transports::S3

Inherits:
Browserctl::State::Transport::Base show all
Defined in:
lib/browserctl/state/transports/s3.rb

Overview

S3 transport — shells out to the ‘aws` CLI so we don’t drag the aws-sdk gem into core. URIs look like ‘s3://bucket/path/key.bctl`. Credentials/region come from the user’s normal AWS environment (env vars, ‘~/.aws/credentials`, IAM, etc.).

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Browserctl::State::Transport::Base

#handles?

Class Method Details

.schemeObject



14
# File 'lib/browserctl/state/transports/s3.rb', line 14

def self.scheme = "s3"

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/browserctl/state/transports/s3.rb', line 16

def available?
  system("which", "aws", out: ::File::NULL, err: ::File::NULL)
end

#read(parsed) ⇒ Object



20
21
22
# File 'lib/browserctl/state/transports/s3.rb', line 20

def read(parsed)
  run!("aws", "s3", "cp", parsed.to_s, "-", binmode: true)
end

#run!(*cmd, binmode: false) ⇒ Object



31
32
33
34
35
36
# File 'lib/browserctl/state/transports/s3.rb', line 31

def run!(*cmd, binmode: false)
  out, err, status = Open3.capture3(*cmd, binmode: binmode)
  return out if status.success?

  raise Transport::TransportError, "#{cmd.first} failed: #{err.strip.empty? ? out : err}"
end

#write(parsed, blob) ⇒ Object



24
25
26
27
28
29
# File 'lib/browserctl/state/transports/s3.rb', line 24

def write(parsed, blob)
  out, err, status = Open3.capture3("aws", "s3", "cp", "-", parsed.to_s, stdin_data: blob, binmode: true)
  return if status.success?

  raise Transport::TransportError, "aws s3 cp failed: #{err.strip.empty? ? out : err}"
end