84
84
when sending metadata for ACLs to the API.
85
85
"""
86
86
87
+ from google .cloud .storage ._helpers import _add_generation_match_parameters
87
88
from google .cloud .storage .constants import _DEFAULT_TIMEOUT
88
89
from google .cloud .storage .retry import DEFAULT_RETRY
90
+ from google .cloud .storage .retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED
89
91
90
92
91
93
class _ACLEntity (object ):
@@ -465,7 +467,18 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
465
467
for entry in found .get ("items" , ()):
466
468
self .add_entity (self .entity_from_dict (entry ))
467
469
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
+ ):
469
482
"""Helper for :meth:`save` and :meth:`save_predefined`.
470
483
471
484
: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):
481
494
:param client: (Optional) The client to use. If not passed, falls back
482
495
to the ``client`` stored on the ACL's parent.
483
496
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
+
484
513
:type timeout: float or tuple
485
514
:param timeout:
486
515
(Optional) The amount of time, in seconds, to wait
487
516
for the server response. See: :ref:`configuring_timeouts`
488
517
489
- :type retry: :class:`~ google.api_core.retry.Retry`
518
+ :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
490
519
:param retry:
491
520
(Optional) How to retry the RPC. See: :ref:`configuring_retries`
492
521
"""
@@ -500,14 +529,22 @@ def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
500
529
if self .user_project is not None :
501
530
query_params ["userProject" ] = self .user_project
502
531
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
+
503
540
path = self .save_path
504
541
505
542
result = client ._patch_resource (
506
543
path ,
507
544
{self ._URL_PATH_ELEM : list (acl )},
508
545
query_params = query_params ,
509
546
timeout = timeout ,
510
- retry = None ,
547
+ retry = retry ,
511
548
)
512
549
513
550
self .entities .clear ()
@@ -517,7 +554,17 @@ def _save(self, acl, predefined, client, timeout=_DEFAULT_TIMEOUT):
517
554
518
555
self .loaded = True
519
556
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
+ ):
521
568
"""Save this ACL for the current bucket.
522
569
523
570
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):
531
578
:param client: (Optional) The client to use. If not passed, falls back
532
579
to the ``client`` stored on the ACL's parent.
533
580
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
+
534
597
:type timeout: float or tuple
535
598
:param timeout:
536
599
(Optional) The amount of time, in seconds, to wait
537
600
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`
538
605
"""
539
606
if acl is None :
540
607
acl = self
@@ -543,9 +610,29 @@ def save(self, acl=None, client=None, timeout=_DEFAULT_TIMEOUT):
543
610
save_to_backend = True
544
611
545
612
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
+ ):
549
636
"""Save this ACL for the current bucket using a predefined ACL.
550
637
551
638
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):
562
649
:param client: (Optional) The client to use. If not passed, falls back
563
650
to the ``client`` stored on the ACL's parent.
564
651
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
+
565
668
:type timeout: float or tuple
566
669
:param timeout:
567
670
(Optional) The amount of time, in seconds, to wait
568
671
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`
569
676
"""
570
677
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
+ )
572
689
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
+ ):
574
700
"""Remove all ACL entries.
575
701
576
702
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):
585
711
:param client: (Optional) The client to use. If not passed, falls back
586
712
to the ``client`` stored on the ACL's parent.
587
713
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
+
588
730
:type timeout: float or tuple
589
731
:param timeout:
590
732
(Optional) The amount of time, in seconds, to wait
591
733
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`
592
738
"""
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
+ )
594
749
595
750
596
751
class BucketACL (ACL ):
0 commit comments