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 options to mkdir #610

Merged
merged 2 commits into from
Mar 12, 2024
Merged

Add options to mkdir #610

merged 2 commits into from
Mar 12, 2024

Conversation

slevang
Copy link
Contributor

@slevang slevang commented Mar 3, 2024

Noticed there was no way to specify a few common options on bucket creation via the IAM API.

I can modify the test if there is a better way, or remove entirely.

def test_mkdir_options(gcs):
gcs = GCSFileSystem(endpoint_url=gcs._endpoint)
if not gcs.on_google:
pytest.skip("emulator doesn't support IAM policies.")
Copy link
Member

Choose a reason for hiding this comment

The 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



def test_mkdir_options(gcs):
gcs = GCSFileSystem(endpoint_url=gcs._endpoint)
Copy link
Member

Choose a reason for hiding this comment

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

Why make a new instance here?


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)
Copy link
Member

Choose a reason for hiding this comment

The 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

gcsfs/core.py Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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

gcsfs/core.py Outdated
@@ -837,6 +837,8 @@ async def _mkdir(
location=None,
create_parents=True,
enable_versioning=False,
uniform_access=False,
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@slevang slevang left a comment

Choose a reason for hiding this comment

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

I think this is a cleaner approach with the kwargs. location and enable_versioning also get passed to the json body but I didn't want to break these.

I got rid of the previous test but lmk if you have a particular way you would like these tested. I found the emulator and on_google split a little confusing to work with, especially for bucket creation.

Also added some more helpful info and links in the docstring.

gcsfs/core.py Show resolved Hide resolved
@slevang slevang changed the title Add IAM options to mkdir Add options to mkdir Mar 10, 2024
@martindurant martindurant merged commit fa6c308 into fsspec:main Mar 12, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants