Skip to content

Commit

Permalink
Add options to mkdir (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
slevang committed Mar 12, 2024
1 parent 8accef8 commit fa6c308
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,22 +837,25 @@ async def _mkdir(
location=None,
create_parents=True,
enable_versioning=False,
enable_object_retention=False,
iam_configuration=None,
**kwargs,
):
"""
New bucket
If path is more than just a bucket, will create bucket if create_parents=True;
otherwise is a noop. If create_parents is False and bucket does not exist,
will produce FileNotFFoundError.
will produce FileNotFoundError.
Parameters
----------
path: str
bucket name. If contains '/' (i.e., looks like subdir), will
have no effect because GCS doesn't have real directories.
acl: string, one of bACLs
access for the bucket itself
access for the bucket itself. See:
https://cloud.google.com/storage/docs/access-control/lists#predefined-acl
default_acl: str, one of ACLs
default ACL for objects created in this bucket
location: Optional[str]
Expand All @@ -865,6 +868,19 @@ async def _mkdir(
enable_versioning: bool
If True, creates the bucket in question with object versioning
enabled.
enable_object_retention: bool
If True, creates the bucket in question with object retention
permanently enabled.
iam_configuration: dict
If provided, sets the IAM policy for the bucket. This argument
allows setting properties such as `{publicAccessPrevention: "enforced"}`
and `{"uniformBucketLevelAccess": {"enabled": True}}`. If passed, `acl`
and `default_acl` are explicitly ignored.
**kwargs
Additional parameters passed to the API call request body. See:
https://cloud.google.com/storage/docs/json_api/v1/buckets/insert#request-body
for all possible options. Pass nested parameters as dictionaries, e.g.:
`{"autoclass": {"enabled": True}}`
"""
bucket, object, generation = self.split_path(path)
if bucket in ["", "/"]:
Expand All @@ -883,12 +899,20 @@ async def _mkdir(
json_data["location"] = location
if enable_versioning:
json_data["versioning"] = {"enabled": True}
if iam_configuration:
json_data["iamConfiguration"] = iam_configuration
acl = None
default_acl = None
if kwargs:
json_data.update(kwargs)

await self._call(
method="POST",
path="b",
predefinedAcl=acl,
project=self.project,
predefinedDefaultObjectAcl=default_acl,
enableObjectRetention=str(enable_object_retention).lower(),
json=json_data,
json_out=True,
)
Expand Down

0 comments on commit fa6c308

Please sign in to comment.