
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
K
Jr  \R                  " SSS/5      rSr\R"                  " S\-   5      r\R"                  " S\-   5      rS rS r SS jrg)zEUtilities for expanding and matching GCS notification configurations.    )absolute_import)division)unicode_literalsN)api_factory)	cloud_api)errors)storage_url)wildcard_iteratorNotificationIteratorResult
bucket_urlnotification_configurationzC/(?P<bucket_name>[^/]+)/notificationConfigs/(?P<notification_id>.+)z/?(projects/[^/]+/)?bucketsz/?bc                    [         R                  U 5      =(       d    [        R                  U 5      nU(       aO  [        R                  " [        R
                  R                  UR                  S5      5      UR                  S5      4$ g)z?Extracts bucket StorageUrl and notification_id string from URL.bucket_namenotification_id)NN)+_CANONICAL_NOTIFICATION_CONFIGURATION_REGEXmatch&_JSON_NOTIFICATION_CONFIGURATION_REGEXr	   CloudUrlProviderPrefixGCSgroup)
url_stringr   s     Mlib/googlecloudsdk/command_lib/storage/notification_configuration_iterator.py+get_bucket_url_and_notification_id_from_urlr   -   ss     277
C ?,22:>    !;!;!?!?!&]!;=KK)*, , 
    c                     U R                   [        R                  R                  L a*  U R	                  5       (       d9  U R                  5       (       d#  [        R                  " SU R                  -   5      egg)z7Raises error if URL is not supported for notifications.zYNotification configurations available on only Google Cloud Storage buckets. Invalid URL: N)	schemer	   r   r   	is_bucketis_providerr   InvalidUrlErrorr   )urls    r   *raise_error_if_not_gcs_bucket_matching_urlr"   9   s_    
**2266
6==??coo//

 
 	79<	HI I 0?r   c              #     #    [         R                  " [        R                  R                  5      nU  GH8  n[        U5      u  pEU(       a@  U(       d  [        R                  " SU-   5      eUR                  XE5      n[        XF5      v   MX  [        R                  " U5      n[        U5        UR                  5       (       a0  [        R                  " [        R                  R                  S5      nOUn[        R                  " UR                   ["        R$                  R&                  S9 H=  nUR)                  UR                  5       H  n[        UR                  U5      v   M     M?     GM;     g7f)a  Yields bucket/notification tuples from command-line args.

Given a list of strings that are bucket URLs ("gs://foo") or notification
configuration URLs ("b/bucket/notificationConfigs/5"), yield tuples of
bucket names and their associated notifications.

Args:
  urls (list[str]): Bucket and notification configuration URLs to pull
    notification configurations from.
  accept_notification_configuration_urls (bool): Whether to raise an an error
    if a notification configuration URL is in `urls`.

Yields:
  NotificationIteratorResult

Raises:
  InvalidUrlError: Received notification configuration URL, but
    accept_notification_configuration_urls was False. Or received non-GCS
    bucket URL.
z4Received disallowed notification configuration URL: *)fields_scopeN)r   get_apir	   r   r   r   r   r    get_notification_configurationr   storage_url_from_stringr"   r   r   r
   get_wildcard_iteratorr   r   FieldsScopeSHORT list_notification_configurations)	urls&accept_notification_configuration_urlsclientr!   r   r   r   	cloud_urlbucket_resources	            r   'get_notification_configuration_iteratorr2   B   s9    , {99==>&c3C8  J3$$BSHJ 	J $*#H#H
$' &zNN 55c:i0;				 	  ))+*D*D*H*H#N

.DD


i.C.C.I.IK/ 33++- ' +?+F+F+EG G-K) s   E/E1)T)__doc__
__future__r   r   r   collectionsregooglecloudsdk.api_lib.storager   r   "googlecloudsdk.command_lib.storager   r	   r
   
namedtupler   &_NOTIFICATION_CONFIGURATION_REGEX_TAILcompiler   r   r   r"   r2    r   r   <module>r=      s    L &  '  	 6 4 5 : @(33 <1M"NP  J '.0jj!$JJ/L +)+	22*4 &	I 262Gr   