-
Notifications
You must be signed in to change notification settings - Fork 146
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 options to mkdir
#610
Add options to mkdir
#610
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,6 +837,8 @@ async def _mkdir( | |
location=None, | ||
create_parents=True, | ||
enable_versioning=False, | ||
uniform_access=False, | ||
public_access_prevention=True, | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -865,6 +867,12 @@ async def _mkdir( | |
enable_versioning: bool | ||
If True, creates the bucket in question with object versioning | ||
enabled. | ||
uniform_access: bool | ||
If True, creates the bucket in question with uniform access | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if most people will know what "uniform access" means |
||
enabled. | ||
public_access_prevention: bool | ||
If True, creates the bucket in question with public access | ||
prevention enabled. | ||
""" | ||
bucket, object, generation = self.split_path(path) | ||
if bucket in ["", "/"]: | ||
|
@@ -877,12 +885,22 @@ async def _mkdir( | |
return | ||
raise FileNotFoundError(bucket) | ||
|
||
json_data = {"name": bucket} | ||
json_data = {"name": bucket, "iamConfiguration": {}} | ||
location = location or self.default_location | ||
if location: | ||
json_data["location"] = location | ||
if enable_versioning: | ||
json_data["versioning"] = {"enabled": True} | ||
if uniform_access: | ||
# Cannot use ACLs with uniform access | ||
acl = None | ||
default_acl = None | ||
json_data["iamConfiguration"]["uniformBucketLevelAccess"] = { | ||
"enabled": True | ||
} | ||
if public_access_prevention: | ||
json_data["iamConfiguration"]["publicAccessPrevention"] = "enforced" | ||
|
||
await self._call( | ||
method="POST", | ||
path="b", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
TEST_BUCKET = gcsfs.tests.settings.TEST_BUCKET | ||
TEST_PROJECT = gcsfs.tests.settings.TEST_PROJECT | ||
TEST_REQUESTER_PAYS_BUCKET = gcsfs.tests.settings.TEST_REQUESTER_PAYS_BUCKET | ||
TEST_CUSTOM_BUCKET = gcsfs.tests.settings.TEST_CUSTOM_BUCKET | ||
|
||
|
||
def test_simple(gcs): | ||
|
@@ -1478,3 +1479,16 @@ def test_find_maxdepth(gcs): | |
|
||
with pytest.raises(ValueError, match="maxdepth must be at least 1"): | ||
gcs.find(f"{TEST_BUCKET}/nested", maxdepth=0) | ||
|
||
|
||
def test_mkdir_options(gcs): | ||
gcs = GCSFileSystem(endpoint_url=gcs._endpoint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why make a new instance here? |
||
if not gcs.on_google: | ||
pytest.skip("emulator doesn't support IAM policies.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, we should mock to make sure that at least the right IAM config dict is being sent |
||
|
||
gcs.mkdir(TEST_CUSTOM_BUCKET, uniform_access=True, public_access_prevention=True) | ||
info = gcs.info(TEST_CUSTOM_BUCKET) | ||
gcs.rm(TEST_CUSTOM_BUCKET, recursive=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a fixture to make sure the bucket is cleaned up even on failure |
||
|
||
assert info["iamConfiguration"]["uniformBucketLevelAccess"]["enabled"] | ||
assert info["iamConfiguration"]["publicAccessPrevention"] == "enforced" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how many kwargs we should pass before we start to make some Options dataclass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. Would you be in favor of replicating the entire Buckets:Insert api? Or at least the gcloud storage buckets create options? I wanted to add these in particular because they are the default (and recommended) options for buckets created through the console UI.
Looks like some others we are missing are class/autoclass, retention policy and requester pays. Plus some more niche options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we allow "iamConfiguration" as a kwarg, so the caller can put whatever they like in it? We could also other arguments that the API has - then it's just a JSON blob we pass along.