Content-Length: 947239 | pFad | https://www.github.com/googleapis/python-storage/commit/4333caf3674d78b3dfbc161a796abac604d57953

207 fix: add preconditions and retry config support to ACL patch operatio… · googleapis/python-storage@4333caf · GitHub
Skip to content

Commit 4333caf

Browse files
authored
fix: add preconditions and retry config support to ACL patch operationss (#586)
* add preconditions and retry config support to ACL patch operations * update existing unit tests * add unit tests * add preconditions and retry config to bucket make public/private * add preconditions and retry config to blob make public/private * update docstrings * add system tests acl with metegeneration match * revise to use permitted group email
1 parent 3d43049 commit 4333caf

File tree

8 files changed

+639
-44
lines changed

8 files changed

+639
-44
lines changed

google/cloud/storage/acl.py

Lines changed: 165 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@
8484
when sending metadata for ACLs to the API.
8585
"""
8686

87+
from google.cloud.storage._helpers import _add_generation_match_parameters
8788
from google.cloud.storage.constants import _DEFAULT_TIMEOUT
8889
from google.cloud.storage.retry import DEFAULT_RETRY
90+
from google.cloud.storage.retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED
8991

9092

9193
class _ACLEntity(object):
@@ -465,7 +467,18 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
465467
for entry in found.get("items", ()):
466468
self.add_entity(self.entity_from_dict(entry))
467469

468-
def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
470+
def _save(
471+
self,
472+
acl,
473+
predefined,
474+
client,
475+
if_generation_match=None,
476+
if_generation_not_match=None,
477+
if_metageneration_match=None,
478+
if_metageneration_not_match=None,
479+
timeout=_DEFAULT_TIMEOUT,
480+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
481+
):
469482
"""Helper for :meth:`save` and :meth:`save_predefined`.
470483
471484
:type acl: :class:`google.cloud.storage.acl.ACL`, or a compatible list.
@@ -481,12 +494,28 @@ def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
481494
:param client: (Optional) The client to use. If not passed, falls back
482495
to the ``client`` stored on the ACL's parent.
483496
497+
:type if_generation_match: long
498+
:param if_generation_match:
499+
(Optional) See :ref:`using-if-generation-match`
500+
501+
:type if_generation_not_match: long
502+
:param if_generation_not_match:
503+
(Optional) See :ref:`using-if-generation-not-match`
504+
505+
:type if_metageneration_match: long
506+
:param if_metageneration_match:
507+
(Optional) See :ref:`using-if-metageneration-match`
508+
509+
:type if_metageneration_not_match: long
510+
:param if_metageneration_not_match:
511+
(Optional) See :ref:`using-if-metageneration-not-match`
512+
484513
:type timeout: float or tuple
485514
:param timeout:
486515
(Optional) The amount of time, in seconds, to wait
487516
for the server response. See: :ref:`configuring_timeouts`
488517
489-
:type retry: :class:`~google.api_core.retry.Retry`
518+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
490519
:param retry:
491520
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
492521
"""
@@ -500,14 +529,22 @@ def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
500529
if self.user_project is not None:
501530
query_params["userProject"] = self.user_project
502531

532+
_add_generation_match_parameters(
533+
query_params,
534+
if_generation_match=if_generation_match,
535+
if_generation_not_match=if_generation_not_match,
536+
if_metageneration_match=if_metageneration_match,
537+
if_metageneration_not_match=if_metageneration_not_match,
538+
)
539+
503540
path = self.save_path
504541

505542
result = client._patch_resource(
506543
path,
507544
{self._URL_PATH_ELEM: list(acl)},
508545
query_params=query_params,
509546
timeout=timeout,
510-
retry=None,
547+
retry=retry,
511548
)
512549

513550
self.entities.clear()
@@ -517,7 +554,17 @@ def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
517554

518555
self.loaded = True
519556

520-
def save(self, acl=None, client=None, timeout=_DEFAULT_TIMEOUT):
557+
def save(
558+
self,
559+
acl=None,
560+
client=None,
561+
if_generation_match=None,
562+
if_generation_not_match=None,
563+
if_metageneration_match=None,
564+
if_metageneration_not_match=None,
565+
timeout=_DEFAULT_TIMEOUT,
566+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
567+
):
521568
"""Save this ACL for the current bucket.
522569
523570
If :attr:`user_project` is set, bills the API request to that project.
@@ -531,10 +578,30 @@ def save(self, acl=None, client=None, timeout=_DEFAULT_TIMEOUT):
531578
:param client: (Optional) The client to use. If not passed, falls back
532579
to the ``client`` stored on the ACL's parent.
533580
581+
:type if_generation_match: long
582+
:param if_generation_match:
583+
(Optional) See :ref:`using-if-generation-match`
584+
585+
:type if_generation_not_match: long
586+
:param if_generation_not_match:
587+
(Optional) See :ref:`using-if-generation-not-match`
588+
589+
:type if_metageneration_match: long
590+
:param if_metageneration_match:
591+
(Optional) See :ref:`using-if-metageneration-match`
592+
593+
:type if_metageneration_not_match: long
594+
:param if_metageneration_not_match:
595+
(Optional) See :ref:`using-if-metageneration-not-match`
596+
534597
:type timeout: float or tuple
535598
:param timeout:
536599
(Optional) The amount of time, in seconds, to wait
537600
for the server response. See: :ref:`configuring_timeouts`
601+
602+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
603+
:param retry:
604+
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
538605
"""
539606
if acl is None:
540607
acl = self
@@ -543,9 +610,29 @@ def save(self, acl=None, client=None, timeout=_DEFAULT_TIMEOUT):
543610
save_to_backend = True
544611

545612
if save_to_backend:
546-
self._save(acl, None, client, timeout=timeout)
547-
548-
def save_predefined(self, predefined, client=None, timeout=_DEFAULT_TIMEOUT):
613+
self._save(
614+
acl,
615+
None,
616+
client,
617+
if_generation_match=if_generation_match,
618+
if_generation_not_match=if_generation_not_match,
619+
if_metageneration_match=if_metageneration_match,
620+
if_metageneration_not_match=if_metageneration_not_match,
621+
timeout=timeout,
622+
retry=retry,
623+
)
624+
625+
def save_predefined(
626+
self,
627+
predefined,
628+
client=None,
629+
if_generation_match=None,
630+
if_generation_not_match=None,
631+
if_metageneration_match=None,
632+
if_metageneration_not_match=None,
633+
timeout=_DEFAULT_TIMEOUT,
634+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
635+
):
549636
"""Save this ACL for the current bucket using a predefined ACL.
550637
551638
If :attr:`user_project` is set, bills the API request to that project.
@@ -562,15 +649,54 @@ def save_predefined(self, predefined, client=None, timeout=_DEFAULT_TIMEOUT):
562649
:param client: (Optional) The client to use. If not passed, falls back
563650
to the ``client`` stored on the ACL's parent.
564651
652+
:type if_generation_match: long
653+
:param if_generation_match:
654+
(Optional) See :ref:`using-if-generation-match`
655+
656+
:type if_generation_not_match: long
657+
:param if_generation_not_match:
658+
(Optional) See :ref:`using-if-generation-not-match`
659+
660+
:type if_metageneration_match: long
661+
:param if_metageneration_match:
662+
(Optional) See :ref:`using-if-metageneration-match`
663+
664+
:type if_metageneration_not_match: long
665+
:param if_metageneration_not_match:
666+
(Optional) See :ref:`using-if-metageneration-not-match`
667+
565668
:type timeout: float or tuple
566669
:param timeout:
567670
(Optional) The amount of time, in seconds, to wait
568671
for the server response. See: :ref:`configuring_timeouts`
672+
673+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
674+
:param retry:
675+
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
569676
"""
570677
predefined = self.validate_predefined(predefined)
571-
self._save(None, predefined, client, timeout=timeout)
678+
self._save(
679+
None,
680+
predefined,
681+
client,
682+
if_generation_match=if_generation_match,
683+
if_generation_not_match=if_generation_not_match,
684+
if_metageneration_match=if_metageneration_match,
685+
if_metageneration_not_match=if_metageneration_not_match,
686+
timeout=timeout,
687+
retry=retry,
688+
)
572689

573-
def clear(self, client=None, timeout=_DEFAULT_TIMEOUT):
690+
def clear(
691+
self,
692+
client=None,
693+
if_generation_match=None,
694+
if_generation_not_match=None,
695+
if_metageneration_match=None,
696+
if_metageneration_not_match=None,
697+
timeout=_DEFAULT_TIMEOUT,
698+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
699+
):
574700
"""Remove all ACL entries.
575701
576702
If :attr:`user_project` is set, bills the API request to that project.
@@ -585,12 +711,41 @@ def clear(self, client=None, timeout=_DEFAULT_TIMEOUT):
585711
:param client: (Optional) The client to use. If not passed, falls back
586712
to the ``client`` stored on the ACL's parent.
587713
714+
:type if_generation_match: long
715+
:param if_generation_match:
716+
(Optional) See :ref:`using-if-generation-match`
717+
718+
:type if_generation_not_match: long
719+
:param if_generation_not_match:
720+
(Optional) See :ref:`using-if-generation-not-match`
721+
722+
:type if_metageneration_match: long
723+
:param if_metageneration_match:
724+
(Optional) See :ref:`using-if-metageneration-match`
725+
726+
:type if_metageneration_not_match: long
727+
:param if_metageneration_not_match:
728+
(Optional) See :ref:`using-if-metageneration-not-match`
729+
588730
:type timeout: float or tuple
589731
:param timeout:
590732
(Optional) The amount of time, in seconds, to wait
591733
for the server response. See: :ref:`configuring_timeouts`
734+
735+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
736+
:param retry:
737+
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
592738
"""
593-
self.save([], client=client, timeout=timeout)
739+
self.save(
740+
[],
741+
client=client,
742+
if_generation_match=if_generation_match,
743+
if_generation_not_match=if_generation_not_match,
744+
if_metageneration_match=if_metageneration_match,
745+
if_metageneration_not_match=if_metageneration_not_match,
746+
timeout=timeout,
747+
retry=retry,
748+
)
594749

595750

596751
class BucketACL(ACL):

google/cloud/storage/blob.py

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from google.cloud.storage.retry import DEFAULT_RETRY
8484
from google.cloud.storage.retry import DEFAULT_RETRY_IF_ETAG_IN_JSON
8585
from google.cloud.storage.retry import DEFAULT_RETRY_IF_GENERATION_SPECIFIED
86+
from google.cloud.storage.retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED
8687
from google.cloud.storage.fileio import BlobReader
8788
from google.cloud.storage.fileio import BlobWriter
8889

@@ -3226,7 +3227,16 @@ def test_iam_permissions(
32263227

32273228
return resp.get("permissions", [])
32283229

3229-
def make_public(self, client=None, timeout=_DEFAULT_TIMEOUT):
3230+
def make_public(
3231+
self,
3232+
client=None,
3233+
timeout=_DEFAULT_TIMEOUT,
3234+
if_generation_match=None,
3235+
if_generation_not_match=None,
3236+
if_metageneration_match=None,
3237+
if_metageneration_not_match=None,
3238+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
3239+
):
32303240
"""Update blob's ACL, granting read access to anonymous users.
32313241
32323242
:type client: :class:`~google.cloud.storage.client.Client` or
@@ -3239,11 +3249,47 @@ def make_public(self, client=None, timeout=_DEFAULT_TIMEOUT):
32393249
(Optional) The amount of time, in seconds, to wait
32403250
for the server response. See: :ref:`configuring_timeouts`
32413251
3252+
:type if_generation_match: long
3253+
:param if_generation_match:
3254+
(Optional) See :ref:`using-if-generation-match`
3255+
3256+
:type if_generation_not_match: long
3257+
:param if_generation_not_match:
3258+
(Optional) See :ref:`using-if-generation-not-match`
3259+
3260+
:type if_metageneration_match: long
3261+
:param if_metageneration_match:
3262+
(Optional) See :ref:`using-if-metageneration-match`
3263+
3264+
:type if_metageneration_not_match: long
3265+
:param if_metageneration_not_match:
3266+
(Optional) See :ref:`using-if-metageneration-not-match`
3267+
3268+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
3269+
:param retry:
3270+
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
32423271
"""
32433272
self.acl.all().grant_read()
3244-
self.acl.save(client=client, timeout=timeout)
3273+
self.acl.save(
3274+
client=client,
3275+
timeout=timeout,
3276+
if_generation_match=if_generation_match,
3277+
if_generation_not_match=if_generation_not_match,
3278+
if_metageneration_match=if_metageneration_match,
3279+
if_metageneration_not_match=if_metageneration_not_match,
3280+
retry=retry,
3281+
)
32453282

3246-
def make_private(self, client=None, timeout=_DEFAULT_TIMEOUT):
3283+
def make_private(
3284+
self,
3285+
client=None,
3286+
timeout=_DEFAULT_TIMEOUT,
3287+
if_generation_match=None,
3288+
if_generation_not_match=None,
3289+
if_metageneration_match=None,
3290+
if_metageneration_not_match=None,
3291+
retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED,
3292+
):
32473293
"""Update blob's ACL, revoking read access for anonymous users.
32483294
32493295
:type client: :class:`~google.cloud.storage.client.Client` or
@@ -3255,9 +3301,37 @@ def make_private(self, client=None, timeout=_DEFAULT_TIMEOUT):
32553301
:param timeout:
32563302
(Optional) The amount of time, in seconds, to wait
32573303
for the server response. See: :ref:`configuring_timeouts`
3304+
3305+
:type if_generation_match: long
3306+
:param if_generation_match:
3307+
(Optional) See :ref:`using-if-generation-match`
3308+
3309+
:type if_generation_not_match: long
3310+
:param if_generation_not_match:
3311+
(Optional) See :ref:`using-if-generation-not-match`
3312+
3313+
:type if_metageneration_match: long
3314+
:param if_metageneration_match:
3315+
(Optional) See :ref:`using-if-metageneration-match`
3316+
3317+
:type if_metageneration_not_match: long
3318+
:param if_metageneration_not_match:
3319+
(Optional) See :ref:`using-if-metageneration-not-match`
3320+
3321+
:type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
3322+
:param retry:
3323+
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
32583324
"""
32593325
self.acl.all().revoke_read()
3260-
self.acl.save(client=client, timeout=timeout)
3326+
self.acl.save(
3327+
client=client,
3328+
timeout=timeout,
3329+
if_generation_match=if_generation_match,
3330+
if_generation_not_match=if_generation_not_match,
3331+
if_metageneration_match=if_metageneration_match,
3332+
if_metageneration_not_match=if_metageneration_not_match,
3333+
retry=retry,
3334+
)
32613335

32623336
def compose(
32633337
self,

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.github.com/googleapis/python-storage/commit/4333caf3674d78b3dfbc161a796abac604d57953

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy