
    F                     V   d 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 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 ddlmZ ddlmZ d Zd Zd Zd Ze
j2                   e
j4                  e
j6                  j8                         G d de
j:                                      Ze
j2                   e
j4                  e
j6                  j>                         G d de                    Z e
j2                   e
j4                  e
j6                  jB                         G d de                     Z"y)zCommand for cache invalidation.    )absolute_import)division)unicode_literals)base_classes)batch_helper)utils)base)
exceptions)scope)flags)url_maps_utils)logc                      dddS )N?Invalidate specified objects for a URL map in Cloud CDN caches.z      *{command}* requests that Cloud CDN stop using cached content for
      resources at a particular URL path or set of URL paths.

      *{command}* may succeed even if no content is cached for some or all
      URLs with the given path.
      )briefDESCRIPTION r       4lib/surface/compute/url_maps/invalidate_cdn_cache.py_DetailedHelpr       s     L
	
 r   c                     | j                  ddd       | j                  dddd       | j                  d	ddd
       t        j                  j                  |        y)z1Add invalidate-cdn-cache arguments to the parser.z--pathFa        A path specifying which objects to invalidate. PATH must start with
      ``/'' and the only place a ``*'' is allowed is at the end following a
      ``/''. It will be matched against URL paths, which do not include
      scheme, host, or any text after the first ``?'' or ``#'' (and those
      characters are not allowed here). For example, for the URL
      ``https://example.com/whatever/x.html?a=b'', the path is
      ``/whatever/x.html''.

      If PATH ends with ``*'', the preceding string is a prefix, and all URLs
      whose paths begin with it will be invalidated. If PATH doesn't end with
      ``*'', then only URLs with exactly that path will be invalidated.

      Examples:
      - ``'', ``*'', anything that doesn't start with ``/'': error
      - ``/'': just the root URL
      - ``/*'': everything
      - ``/x/y'': ``/x/y'' only (and not ``/x/y/'')
      - ``/x/y/'': ``/x/y/'' only (and not ``/x/y'')
      - ``/x/y/*'': ``/x/y/'' and everything under it
      )requiredhelpz--hostNz_      If set, this invalidation will apply only to requests to the
      specified host.
      )r   defaultr   z--tagsz      A single tag or a comma-delimited list of tags. When multiple tags are
      specified, the invalidation applies them using boolean OR logic.

      Example:
      - ``--tags=abcd,user123''
      )add_argumentr	   
ASYNC_FLAGAddToParser)parsers    r   _Argsr   /   s|     	
  2 	
	   	
	  
 //f%r   c                    |j                  || j                  t        j                  j                        }t        j                  |      rt        j                  d      | j                  j                  j                  |j                        }|j                  |j                  |_        t        |d      r\|j                  P|j                   j#                  |j                  j%                  d      D cg c]  }|j'                          c}       | j                  j                  }|j)                  |j*                  |j-                         |      }| j                  j.                  j0                  }|d|fgS c c}w )z=Returns a list of requests necessary for cache invalidations.)default_scopezLInvalid flag [--region]: Regional URL maps do not support Cloud CDN caching.)pathtags,)projecturlMapcacheInvalidationRuleInvalidateCache)ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalUrlMapRefcompute_exceptionsArgumentErrorclientmessagesCacheInvalidationRuler"   hosthasattrr#   	cacheTagsextendsplitstrip$ComputeUrlMapsInvalidateCacheRequestr%   Nameapitools_clienturlMaps)	holderargsurl_map_argurl_map_refcache_invalidation_ruletagr2   request
collections	            r   _CreateRequestsrF   c   sQ   --
FM,C,C,J,J . L+''4

*
*	? 
 #MM22HH99 I 	YY#'99 T6tyy4%%,, $		 45 4 457 ]]##(99!!3 : 5' }},,44*('
2	33 	6s   8E>c                    |j                   }t        || |      }| j                  rt        j                  ||j
                  j                  |j                        \  }}|sy|D ]r  }t        j                  j                  dj                  |j                               t        j                  j                  dj                  |j                               t |S t        j                  |       |S |j	                  |      }|S )z<Issues requests necessary to invalidate a URL map cdn cache.)requestshttp	batch_urlzInvalidation pending for [{0}]
zMonitor its progress at [{0}]
)r1   rF   async_r   MakeRequestsr<   rI   rJ   r   statuswriteformat
targetLinkselfLinkr   RaiseToolException)r?   r>   r@   r1   rH   r*   errorsinvalidation_operations           r   _RunrU      s    ==&VT;7(	[[$11##((""$Iv $-
 

;BB"--/ 	0

:AA"++- 	. %. 
 v& 
 ##H-I	r   c                   8    e Zd ZdZ e       ZdZed        Zd Z	y)InvalidateCdnCacher   Nc                     t        j                         | _        | j                  j                  |d       t	        |       y )NURLMAP)cust_metavar)r   GlobalUrlMapArgumentURL_MAP_ARGAddArgumentr   )clsr   s     r   ArgszInvalidateCdnCache.Args   s0    002COOOX>	&Mr   c                 v    t        j                  | j                               }t        ||| j                        S )N)r   ComputeApiHolderReleaseTrackrU   r\   )selfr?   r>   s      r   RunzInvalidateCdnCache.Run   s0    **4+<+<+>?Ffd..//r   )
__name__
__module____qualname____doc__r   detailed_helpr\   classmethodr_   rd   r   r   r   rW   rW      s+     H/-+ 
0r   rW   c                       e Zd Zy)InvalidateCdnCacheBetaNre   rf   rg   r   r   r   rl   rl           r   rl   c                       e Zd Zy)InvalidateCdnCacheAlphaNrm   r   r   r   rp   rp      rn   r   rp   N)#rh   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r/   r   r+   +googlecloudsdk.command_lib.compute.url_mapsr   r   googlecloudsdk.corer   r   r   rF   rU   DefaultUniverseOnlyReleaseTracksrb   GASilentCommandrW   BETArl   ALPHArp   r   r   r   <module>r}      s   & &  ' 7 7 0 ( O E = F #1&h4:4 D%%(()0++ 0 * 0" D%%**+/  ,  D%%++,4  - r   