8484when sending metadata for ACLs to the API.
8585"""
8686
87+ from google .cloud .storage ._helpers import _add_generation_match_parameters
8788from google .cloud .storage .constants import _DEFAULT_TIMEOUT
8889from google .cloud .storage .retry import DEFAULT_RETRY
90+ from google .cloud .storage .retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED
8991
9092
9193class _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
596751class BucketACL (ACL ):
0 commit comments