
                            d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
l
mZ  ej                  dddg      ZdZ ej"                  dez         Z ej"                  dez         Zd Zd Z	 ddZy)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                     t         j                  |       xs t        j                  |       }|rNt        j                  t        j
                  j                  |j                  d            |j                  d      fS y)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                     | j                   t        j                  j                  u r | j	                         s3| j                         s"t        j                  d| j                  z         yy)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   sZ    
**2266
6==?coo/

 
 	79<	HI I 0?r   c              #     K   t        j                  t        j                  j                        }| D ]%  }t        |      \  }}|r;|st        j                  d|z         |j                  ||      }t        ||       Ot        j                  |      }t        |       |j                         r/t        j                  t        j                  j                  d      }n|}t        j                  |j                   t"        j$                  j&                        D ]:  }|j)                  |j                        D ]  }t        |j                  |        < ( yw)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   s>    , {99==>&c3C8  J3$$BSHJ 	J $*#H#H
o$' &z3M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E)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3 <1M"NP  J '.8bjj!$JJ/L +)3	22*4 &	I 262Gr   