Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add s3 --host_prefix #1083

Merged
merged 2 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/dpl/providers/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class S3 < Provider
opt '--default_text_charset CHARSET', 'Default character set to append to the content-type of text files'
opt '--max_threads NUM', 'The number of threads to use for S3 file uploads', default: 5, max: 15, type: :integer
opt '--overwrite', 'Whether or not to overwrite existing files', default: true
opt '--force_path_style', 'Whether to force keeping the bucket name on the path'
opt '--verbose', 'Be verbose about uploading files'
# how come there is no glob or file option?

Expand Down Expand Up @@ -101,7 +102,7 @@ def progress(file, data)
end

def upload_file(file, opts)
object = s3.bucket(bucket).object(upload_path(file))
object = bucket.object(upload_path(file))
return warn :upload_skipped, file: file if !overwrite && object.exists?
info :upload_file, file, upload_dir || '/', to_pairs(opts)
object.upload_file(file, opts) || warn(:upload_failed, file)
Expand All @@ -110,7 +111,7 @@ def upload_file(file, opts)
def index_document_suffix
info :index_document_suffix, super
body = { website_configuration: { index_document: { suffix: super } } }
s3.bucket(bucket).website.put(body)
bucket.website.put(body)
end

def upload_path(file)
Expand Down Expand Up @@ -179,8 +180,21 @@ def handle_error(e)
end
end

def s3
@s3 ||= Aws::S3::Resource.new(compact(region: region, credentials: credentials, endpoint: endpoint))
def bucket
@bucket ||= Aws::S3::Resource.new(client: client).bucket(super)
end

def client
Aws::S3::Client.new(s3_opts)
end

def s3_opts
compact(
region: region,
credentials: credentials,
endpoint: endpoint,
force_path_style: force_path_style?
)
end

def credentials
Expand Down
4 changes: 4 additions & 0 deletions spec/dpl/providers/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
it { should create_client endpoint: URI.parse('https://host.com') }
end

describe 'given --force_path_style' do
it { should create_client force_path_style: true }
end

describe 'given --region us-west-1' do
it { should create_client region: 'us-west-1' }
end
Expand Down