
    *                        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dlmZ  G d de      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
j:                                      Z e
j2                   e
j4                  e
j6                  jB                         G d de
j:                                      Z"y)z-Command for updating security policies rules.    )absolute_import)division)unicode_literals)base_classes)client)base)
exceptions)scope)flags)security_policies_utils)
properties)	resourcesc                   6    e Zd ZdZe	 	 dd       Zed        Zy)UpdateHelperN  Update a Compute Engine security policy rule.

  *{command}* is used to update security policy rules.

  ## EXAMPLES

  To update the description and IP ranges of a rule at priority
  1000, run:

    $ {command} 1000 \
       --security-policy=my-policy \
       --description="block 1.2.3.4/32" \
       --src-ip-ranges=1.2.3.4/32
  c                 j   t        j                  d      | _        | j                  j                  |dd       t        j                  |d       t        j                         | _        | j                  j                  |       t        j                  |d       t        j                  |d|       t        j                  |       t        j                  |d       t        j                  |       t        j                  ||	       t        j                  |       t        j                  |       y
)z,Generates the flagset for an Update command.updatePRIORITY)operation_typecust_metavarF)required)r   support_fairshareT)
for_updatesupport_rpc_statusN)r   PriorityArgumentNAME_ARGAddArgumentAddRegionFlagsecurity_policy_flags(SecurityPolicyMultiScopeArgumentForRulesSECURITY_POLICY_ARGAddMatcherAndNetworkMatcher	AddActionAddDescription
AddPreviewAddRedirectOptionsAddRateLimitOptionsAddRequestHeadersToAddAddRecaptchaOptions)clsparserr   r   s       5lib/surface/compute/security_policies/rules/update.pyArgszUpdateHelper.Args1   s     **84CLLLxj  B	)FFH  ''/	%%fu=	OO+- 
 	V-	V$	- 
  (	f%    c                    |j                   |j                  |j                  |j                  du|j                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  |j0                  |j2                  g}g d}|r:|j5                  |j6                  |j8                  g       |j5                  ddg       t;        |D cg c]&  }|j=                  |dd j?                  dd            ( c}      stA        jB                  |d      tE        jF                  |      }|jH                  r| jJ                  jM                  ||jN                  tP        jR                  jT                  	      }tW        |d
d      m|jN                  jY                  |jZ                  dt\        j^                  j`                  jb                  jd                  |jf                  |jH                  d      }	n|jN                  jY                  |jZ                  dt\        j^                  j`                  jb                  jd                  |jH                  d      }	nc	 |jN                  jY                  |jZ                  dt\        j^                  j`                  jb                  jd                  tW        |d
d      d      }	tm        jn                  |	|jl                        }
tq        jr                  |jl                  |      }tq        jt                  |jl                  ||      }|j                  }tq        jv                  |jl                  |      }tq        jx                  |jl                  |      }|d   }|d   }|j=                  d      r|j                  dvr|j{                  d       |j=                  d      r |j                  dvr|j{                  d       n0|j=                  d      r|j$                  dvr|j{                  d       dj}                  |      }|
j                  |j                  |j                  |||j                  |j                   |j                  ||||r|      S d      S c c}w # tN        jh                  tN        jj                  f$ rZ |jN                  jY                  |jZ                  ddt\        j^                  j`                  jb                  jd                  i      }	Y 2w xY w)z7Validates arguments and patches a security policy rule.N)z--descriptionz--src-ip-rangesz--expressionz--actionz	--previewz--network-user-defined-fieldsz--network-src-ip-rangesz--network-dest-ip-rangesz--network-ip-protocolsz--network-src-portsz--network-dest-portsz--network-src-region-codesz--redirect-typez--redirect-targetz--request-headers-to-addz--rate-limit-threshold-countz#--rate-limit-threshold-interval-secz--conform-actionz--exceed-actionz--enforce-on-keyz--enforce-on-key-namez--ban-threshold-countz--ban-threshold-interval-secz--ban-duration-secz--recaptcha_action_site_keysz--recaptcha_session_site_keysz--exceed-action-rpc-status-codez"--exceed-action-rpc-status-message   -_z'At least one property must be modified.)default_scoperegionz!compute.regionSecurityPolicyRules)projectr5   securityPolicy)
collectionparamszcompute.securityPolicyRules)r6   r7   )r6   r5   r6   )compute_clientr      action)redirectredirect_options)throttlezrate-based-ban	fairsharerate_limit_optionsexceed_actionz*rate_limit_options.exceed_redirect_options,)src_ip_ranges
expressionexpression_optionsnetwork_matcherr<   descriptionpreviewr>   rA   request_headers_to_addupdate_mask)ArH   rD   r<   rI   network_user_defined_fieldsnetwork_src_ip_rangesnetwork_dest_ip_rangesnetwork_ip_protocolsnetwork_src_portsnetwork_dest_portsnetwork_src_region_codesnetwork_src_asnsredirect_typeredirect_targetrJ   rate_limit_threshold_count!rate_limit_threshold_interval_secconform_actionrB   enforce_on_keyenforce_on_key_nameban_threshold_countban_threshold_interval_secban_duration_secrecaptcha_action_site_keysrecaptcha_session_site_keysextendexceed_action_rpc_status_code exceed_action_rpc_status_messageanyIsSpecifiedreplacer	   MinimumArgumentExceptionr   ComputeApiHoldersecurity_policyr"   ResolveAsResourcer   compute_scope	ScopeEnumGLOBALgetattrParsenamer   VALUEScorer6   	GetOrFailr5   RequiredFieldOmittedException WrongResourceCollectionExceptionr   SecurityPolicyRuler   CreateRedirectOptionsCreateRateLimitOptionsCreateExpressionOptionsCreateNetworkMatcherappendjoinPatchrE   )r+   release_trackargsr   modified_fieldsmin_argsfieldholdersecurity_policy_refrefsecurity_policy_ruler>   rA   rJ   rF   resultrG   rK   update_mask_strs                      r-   RunzUpdateHelper.RunP   s    	D ((""##!!%%##''..    ''''((5O8H8 

,
,

/
/ 	 oo
+
. 	 DLMH5		%)++C5	6HMO//
=? ? **=9F33EE



%//66 F 8 
$h	5	A$$II:%,,1199CC-44"&"6"6 %  $$II4%,,1199CC"&"6"6 % 

$$II:%,,1199CC!$$7 % 
& "44FMM+ /DDt 1GGt/ "880HHt %99tF QiO)K!dkk&E+,!dkk : '
 -.			/	*t/A/A J 0 EFhh{+O%%((??-'{{$$)-5'6O &   =A &  o 	NN 
1
1

4
4 

 $$II4:,,1199CC % 
	

s   ,+T3A"T A9VVN)FF)__name__
__module____qualname____doc__classmethodr.   r    r/   r-   r   r   !   s9      	& &< l lr/   r   c                   2    e Zd ZdZdZdZdZed        Zd Z	y)UpdateGAr   NFc                 F    t         j                  || j                         y )Nr   r   r.   _support_rpc_statusr+   r,   s     r-   r.   zUpdateGA.Args  s!    22  r/   c                 `    t         j                  | j                         || j                        S Nr   r   ReleaseTrackr   selfr~   s     r-   r   zUpdateGA.Run  -       r/   )
r   r   r   r   r"   r   r   r   r.   r   r   r/   r-   r   r      s1     ( r/   r   c                   .    e Zd ZdZdZdZed        Zd Zy)
UpdateBetar   NFc                 H    t         j                  |d| j                         y NT)r   r   r   r   s     r-   r.   zUpdateBeta.Args<  $    22  r/   c                 `    t         j                  | j                         || j                        S r   r   r   s     r-   r   zUpdateBeta.RunD  r   r/   	r   r   r   r   r"   r   r   r.   r   r   r/   r-   r   r   &  s,      r/   r   c                   .    e Zd ZdZdZdZed        Zd Zy)UpdateAlphar   NTc                 H    t         j                  |d| j                         y r   r   r   s     r-   r.   zUpdateAlpha.Argsb  r   r/   c                 `    t         j                  | j                         || j                        S r   r   r   s     r-   r   zUpdateAlpha.Runj  r   r/   r   r   r/   r-   r   r   L  s,      r/   r   N)#r   
__future__r   r   r   googlecloudsdk.api_lib.computer   0googlecloudsdk.api_lib.compute.security_policiesr   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   rj   4googlecloudsdk.command_lib.compute.security_policiesr   r    r   :googlecloudsdk.command_lib.compute.security_policies.rulesgooglecloudsdk.corer   r   objectr   UniverseCompatibleReleaseTracksr   GAUpdateCommandr   BETAr   ALPHAr   r   r/   r-   <module>r      s   4 &  ' 7 C ( . E _ X L * )\6 \~ D%%(()!t!! ! * !H D%%**+!## ! , !H D%%++,!$$$ ! - !r/   