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

Fixes s3cmd#1197 - add custom header for s3cmd mb #1198

Merged
merged 1 commit into from
Sep 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,11 @@ def bucket_list_noparse(self, bucket, prefix = None, recursive = None, uri_param
#debug(response)
return response

def bucket_create(self, bucket, bucket_location = None):
def bucket_create(self, bucket, bucket_location = None, extra_headers = None):
headers = SortedDict(ignore_case = True)
if extra_headers:
headers.update(extra_headers)

body = ""
if bucket_location and bucket_location.strip().upper() != "US" and bucket_location.strip().lower() != "us-east-1":
bucket_location = bucket_location.strip()
Expand Down
3 changes: 2 additions & 1 deletion s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@ def subcmd_bucket_list(s3, uri, limit):
def cmd_bucket_create(args):
cfg = Config()
s3 = S3(cfg)

for arg in args:
uri = S3Uri(arg)
if not uri.type == "s3" or not uri.has_bucket() or uri.has_object():
raise ParameterError("Expecting S3 URI with just the bucket name set instead of '%s'" % arg)
try:
response = s3.bucket_create(uri.bucket(), cfg.bucket_location)
response = s3.bucket_create(uri.bucket(), cfg.bucket_location, cfg.extra_headers)
output(u"Bucket '%s' created" % uri.uri())
except S3Error as e:
if e.info["Code"] in S3.codes:
Expand Down