
    &                     R    S r SSKJr  SSKJr  S rS rS rS r  SS	 jr	S
 r
S rg)z@Code that's shared between multiple backend-buckets subcommands.    )encoding)iam_utilc                 >   SnUR                   (       aO  / nUR                   R                  5        H-  u  pEUR                  U R                  R	                  XES95        M/     U$ UR
                  b-  UR
                  R                  b  UR
                  R                  nU$ )ac  Returns the negative caching policy.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_bucket: The backend bucket object. If the backend bucket object
    contains a negative caching policy already, it is used as the base to
    apply changes based on args.

Returns:
  The negative caching policy.
N)codettl)negative_caching_policyitemsappendmessages+BackendBucketCdnPolicyNegativeCachingPolicy	cdnPolicynegativeCachingPolicy)clientargsbackend_bucketr   r   r   s         Olib/googlecloudsdk/command_lib/compute/backend_buckets/backend_buckets_utils.pyGetNegativeCachingPolicyr      s     !	!! 11779	$$
//
E
E F "# : 
! 	 	  ,  66B . 8 8 N N	      c                     SnUR                   (       a=  / nUR                    H+  nUR                  U R                  R                  US95        M-     U$ )zReturns bypass cache on request headers.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.

Returns:
  The bypass cache on request headers.
N)
headerName)bypass_cache_on_request_headersr
   r   0BackendBucketCdnPolicyBypassCacheOnRequestHeader)r   r   r   headers       r   GetBypassCacheOnRequestHeadersr   2   sZ     %)!	))&(#66%,,
//
J
J K !" 7
 
)(r   c                 T    U R                  S5      =(       d    U R                  S5      $ )zReturns true if the request requires a CacheKeyPolicy message.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if there are cache key policy related arguments which require adding
  a CacheKeyPolicy message in the request.
 cache_key_query_string_whitelistcache_key_include_http_header)IsSpecified)r   s    r   HasCacheKeyPolicyArgsr   G   s,     

=
> <


:
;=r   c                 &   U R                   R                  5       nUR                  b-  UR                  R                  b  UR                  R                  nUR                  b  UR                  Ul        UR                  b  UR                  Ul        U$ )aN  Returns the cache key policy.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_bucket: The backend bucket object. If the backend bucket object
    contains a cache key policy already, it is used as the base to apply
    changes based on args.

Returns:
  The cache key policy.
)r   $BackendBucketCdnPolicyCacheKeyPolicyr   cacheKeyPolicyr   includeHttpHeadersr   queryStringWhitelist)r   r   r   cache_key_policys       r   GetCacheKeyPolicyr&   U   s     __IIK*--9%//>>	''3*.*L*L'	**6-- ) 
r   Nc                 b   UR                   b!  [        R                  " UR                   5      nOU R                  R	                  5       nUR                  S5      (       a  UR                  Ul        UR                  b  UR                  Ul	        UR                  (       a4  U R                  R                  R                  UR                  5      Ul        UR                  b  UR                  Ul        UR                  b  UR                  Ul        UR"                  b  UR"                  Ul        U(       Ga  UR                  S:H  =(       a    UR                  SL nUR&                  (       d  U(       a  UR)                  S5        SUl        UR                  S:H  =(       a    UR                  SL nUR*                  (       d  U(       a  UR)                  S5        SUl        UR                  S:H  =(       d    UR                  S:H  =(       a    UR"                  SL nUR,                  (       d  U(       a  UR)                  S5        SUl        UR.                  b  UR.                  Ul        [3        XU5      n	U	b  Xl        UR6                  (       a  SUl        U(       aG  UR8                  (       d  UR.                  b)  UR.                  (       d  UR)                  S	5        / Ul        UR:                  b  UR:                  Ul        [?        X5      n
U
b  Xl         U(       aR  URB                  (       a  UR)                  S
5        SUl        URD                  (       a  UR)                  S5        / Ul         [G        U5      (       a  [I        XU5      Ul%        XPR                  R	                  5       :w  a  XRl         gg)a  Applies the CdnPolicy arguments to the specified backend bucket.

If there are no arguments related to CdnPolicy, the backend bucket remains
unmodified.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_bucket: The backend bucket object.
  is_update: True if this is called on behalf of an update command instead of
    a create command, False otherwise.
  cleared_fields: Reference to list with fields that should be cleared. Valid
    only for update command.
Nsigned_url_cache_max_ageUSE_ORIGIN_HEADERSzcdnPolicy.clientTtlzcdnPolicy.defaultTtlFORCE_CACHE_ALLzcdnPolicy.maxTtlTzcdnPolicy.negativeCachingPolicyzcdnPolicy.serveWhileStalez%cdnPolicy.bypassCacheOnRequestHeaders)&r   r   CopyProtoMessager   BackendBucketCdnPolicyr   r(   signedUrlCacheMaxAgeSecrequest_coalescingrequestCoalescing
cache_modeCacheModeValueValuesEnum	cacheMode
client_ttl	clientTtldefault_ttl
defaultTtlmax_ttlmaxTtlno_client_ttlr
   no_default_ttl
no_max_ttlnegative_cachingnegativeCachingr   r   r   no_negative_caching_policiesserve_while_staleserveWhileStaler   bypassCacheOnRequestHeadersno_serve_while_stale"no_bypass_cache_on_request_headersr   r&   r"   )r   r   r   	is_updatecleared_fields
cdn_policyshould_clean_client_ttlshould_clean_default_ttlshould_clean_max_ttlr   r   s              r   ApplyCdnPolicyArgsrJ   p   s   & )**>+C+CDJ779J	011)-)F)FJ&	(#'#:#:J 	__!??AAt/ 	__ ??J	! ,,J	\\J 	//KDOOt4K 412!j 	//LD4D4D4L 623"j OO/CC 1 OO01K6:lld6J  ../j	&!%!6!6J4V5CE('>$	!!!%J))				*43H3H=>)+j&	'!%!7!7J$B6$P!$0-L*  78#'j ..CD/1j,4   1& OJ??99;;) <r   c                    U R                  5       S:X  ak  UR                  R                  nUR                  R	                  U R                  5       U R                  U R                  S9nUR                  USU4/5      S   $ UR                  R                  nUR                  R                  U R                  5       U R                  S9nUR                  USU4/5      S   $ )zGets the IAM policy for a backend bucket.

Args:
  backend_bucket_ref: The backend bucket reference.
  client: The client.

Returns:
  The IAM policy.
compute.regionBackendBuckets)resourceregionprojectGetIamPolicyr   )rM   rO   )
Collectionapitools_clientregionBackendBucketsr   .ComputeRegionBackendBucketsGetIamPolicyRequestNamerN   rO   MakeRequestsbackendBuckets(ComputeBackendBucketsGetIamPolicyRequest)backend_bucket_refr   servicerequests       r   rP   rP      s     ""$(FF$$99GooLL#((*!(("** M ,G .' BCDQGG""11'OODD!&&(2D2L2L E ' 
		w@A	B1	EEr   c           	         SnU R                  5       S:X  ay  UR                  R                  nUR                  R	                  U R                  5       U R                  UR                  R                  US9S9nUR                  USU4/5      S   nOU R                  5       S:X  a  UR                  R                  nUR                  R                  U R                  5       U R                  U R                  UR                  R                  US9S9nUR                  USU4/5      S   n[        R                  " U R                  5       S	5        U$ )
zSets the IAM policy for a backend bucket.

Args:
  backend_bucket_ref: The backend bucket reference.
  client: The client.
  policy: The IAM policy.

Returns:
  The set IAM policy.
Nzcompute.backendBuckets)policy)rM   rO   globalSetPolicyRequestSetIamPolicyr   rL   )rM   rN   rO   regionSetPolicyRequestzbackend bucket)rQ   rR   rW   r   (ComputeBackendBucketsSetIamPolicyRequestrU   rO   GlobalSetPolicyRequestrV   rS   .ComputeRegionBackendBucketsSetIamPolicyRequestrN   RegionSetPolicyRequestr   LogSetIamPolicy)rY   r   r]   resultrZ   r[   s         r   r_   r_      sN    &""$(@@$$33GooFF#((*"**%EE  F  
 G G   7NG"D!EFqIF$$&*HH$$99GooLL#((*!(("**%EE  F  
	 M G   7NG"D!EFqIF
-2246FG	-r   )FN)__doc__apitools.base.pyr   googlecloudsdk.command_lib.iamr   r   r   r   r&   rJ   rP   r_    r   r   <module>rk      sA    G & 3!8)*=< "'&*	_*DF0"r   