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

Make opts.hostedPath (and installation) respect the s3ForcePathStyle param #608

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/util/s3_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const path = require('path');
module.exports.detect = function(opts, config) {
const to = opts.hosted_path;
const uri = url.parse(to);
config.prefix = (!uri.pathname || uri.pathname === '/') ? '' : uri.pathname.replace('/', '');
if (opts.bucket && opts.region) {
config.bucket = opts.bucket;
config.region = opts.region;
Expand All @@ -33,6 +32,10 @@ module.exports.detect = function(opts, config) {
}
}
}
// If we are using s3ForcePathStyle the bucket is part of the http object path
// (but not the S3 key prefix path). If we aren't this isn't as much of a consideration.
const bucket_path = config.s3ForcePathStyle ? `/${config.bucket}/` : '/';
Copy link
Author

@jared-duo jared-duo Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this below the if/else structure does skip an early return on line 21. I think that early return is acting in light of an error condition so not having config.prefix set for it is fine, but I'm not 100% sure.

config.prefix = (!uri.pathname || uri.pathname === bucket_path) ? '' : uri.pathname.replace(bucket_path, '');
};

module.exports.get_s3 = function(config) {
Expand Down
6 changes: 5 additions & 1 deletion lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ module.exports.evaluate = function(package_json, options, napi_build_version) {
const package_name = package_json.binary.package_name ? package_json.binary.package_name : default_package_name;
opts.package_name = eval_template(package_name, opts);
opts.staged_tarball = path.join('build/stage', opts.remote_path, opts.package_name);
opts.hosted_path = url.resolve(opts.host, opts.remote_path);
if (opts.s3ForcePathStyle) {
opts.hosted_path = url.resolve(opts.host, drop_double_slashes(`${opts.bucket}/${opts.remote_path}`));
} else {
opts.hosted_path = url.resolve(opts.host, opts.remote_path);
}
opts.hosted_tarball = url.resolve(opts.hosted_path, opts.package_name);
return opts;
};