
    ]$                        S 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  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  SSKr\R&                  \R(                  " \R*                  R,                  \R*                  R.                  5       " S S\R0                  5      5       5       r\R&                  \R(                  " \R*                  R4                  5       " S S\5      5       5       rSS0\l        g)z-Command for updating security policies rules.    )absolute_import)division)unicode_literals)base_classes)org_security_policy_rule_utils)client)base)flags)org_security_policies_utilsNc                   >    \ rS rSrSrSr\S 5       rS rS r	S r
Srg)	Update   qUpdate a Compute Engine security policy rule.

*{command}* is used to update organization security policy rules.
Nc                    [         R                  " SSS9U l        U R                  R                  U5        [         R                  " USS9  [         R
                  " USS9  [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " USS9  [         R                  " USS9  [        R                   " USS9  [        R"                  " USS9  UR%                  S	S
SSS9  g NTupdate)required	operationF)r   updated)r   )
for_updatez--cloud-armor
store_truez-Specified for Hierarchical Cloud Armor rules.)actiondefaulthelp)r
   OrgSecurityPolicyRuleArgumentORG_SECURITY_POLICY_ARGAddArgument	AddActionAddSecurityPolicyIdAddDestIpRangesAddLayer4ConfigsAddDirectionAddEnableLoggingAddTargetResourcesAddTargetServiceAccountsAddDescriptionAddNewPriorityAddOrganization
rule_flags
AddMatcher
AddPreviewadd_argumentclsparsers     9lib/surface/compute/org_security_policies/rules/update.pyArgsUpdate.Args)   s   "'"E"E#+C++F3	OOFU+	f	:	&!	6"	v	6"	V$	""6*	 	84	&51&51&T2
<	      c                    UR                  S5      (       aD  UR                  R                  R                  UR                  R                  R	                  US9S9$ UR                  R                  R                  UR                  R                  R                  R
                  R                  UR                  R                  R                  US9S9$ )N
expression)r5   )expr)srcIpRangesversionedExprconfig)IsSpecifiedr   messagesSecurityPolicyRuleMatcherExprVersionedExprValueValuesEnum
SRC_IPS_V1SecurityPolicyRuleMatcherConfig)selfargsholderr5   src_ip_rangess        r0   _SetupCloudArmorMatchUpdate._SetupCloudArmorMatchB   s    %%]]##==}}%%**j*A >   ]]##==..HHeepp''GG' H  >  r3   c           
      @   U R                  5       [        R                   R                  :X  az  UR                  R                  R                  UR                  R                  R
                  R                  R                  UR                  R                  R                  UUUUS9S9$ UR                  R                  R                  UR                  R                  R
                  R                  R                  UR                  R                  R                  UUUS9S9$ )N)r7   destIpRanges	destPortslayer4Configsr8   )r7   rI   rK   )	ReleaseTrackr	   ALPHAr   r<   r=   r?   FIREWALLrA   )rB   rD   rE   dest_ip_rangesdest_ports_listlayer4_config_lists         r0   _SetupFirewallMatchUpdate._SetupFirewallMatchO   s     d//555]]##==..HHeenn''GG')'.	 H  >   ]]##==..HHeenn''GG'). H  >  r3   c           	         [         R                  " U R                  5       5      nU R                  R	                  XR
                  SS9n[        R                  " UUR                  UR
                  [        R                  " U R                  5       5      R                  5       S9n[        R                  " UR                  5       5      nS n/ n/ n/ n	/ n
S nSnS nUR                  S5      (       a  UR                  nSnUR                  S5      (       a  UR                   nSnUR                  S5      (       a  UR"                  nSnU R                  5       [$        R                  R&                  :X  aM  UR                  S5      (       a7  Sn[        R(                  " UR*                  UR                  R,                  5      n	UR                  S	5      (       a7  Sn[        R.                  " UR0                  UR                  R,                  5      n
UR                  S
5      (       a  UR2                  nUR                  S5      (       a!  [        R                  " UR4                  5      nOUnU(       a>  UR                  S5      (       a  U R7                  XXg5      nOU R9                  UUUU	U
5      nUR                  R,                  R;                  U[        R<                  " UR>                  5      UUR@                  US9nU R                  5       [$        R                  RB                  :w  Ga  UR                  S5      (       a  URD                  Ul#        UR                  S5      (       a  URH                  Ul%        UR                  S5      (       a  SUl&        UR                  S5      (       a  URN                  S:X  a:  UR                  R,                  R:                  RP                  RR                  Ul'        O9UR                  R,                  R:                  RP                  RT                  Ul'        [V        RX                  " UURZ                  UR\                  S9nUR_                  UUUS9$ )NF)with_project)refcompute_client	resourcesversionr5   TrE   rO   
dest_portslayer4_configspreviewnew_prioritycloud_armor)priorityr   matchdescriptionr\   target_resourcestarget_service_accountsenable_logging	directionINGRESS)organization)r_   security_policysecurity_policy_rule)0r   ComputeApiHolderrL   r   ResolveAsResourcerX   r   OrgSecurityPolicyRulesix	text_typelower
rule_utilsConvertPriorityToIntNamer;   r5   rE   rO   r	   rM   ParseDestPortsrZ   r<   ParseLayer4Configsr[   r\   r]   rF   rR   SecurityPolicyRuleConvertActionr   ra   GArb   targetResourcesrc   targetServiceAccountsenableLoggingre   DirectionValueValuesEnumrf   EGRESSr   GetSecurityPolicyIdrh   rg   r   )rB   rC   rD   rV   security_policy_rule_clientr_   r5   rE   rO   rP   rQ   r\   should_setup_matchmatcherr]   ri   security_policy_ids                    r0   Run
Update.Runk   s   **4+<+<+>?F

&
&
8
8U 9 4C"(">">}}""d//1288:	#<
 ..sxxz:HJMNOGG%%??j((((m())**nd//555$:J:J; ;"11$//28--2H2HJo())%88


v}}557	""g''44T5F5FGll 			-	(	(,,*
 **
 "==11DD''4$$ E  d//222			,	-	-/3/D/D,			3	4	4(( 	2 
		*	+	+-1*			+	&	&>>Y&mm$$77PPXX 
(
 mm$$77PPWW 
( 5HH#&&(
 '--*1 . 3 3r3    )__name__
__module____qualname____firstlineno____doc__r   classmethodr1   rF   rR   r   __static_attributes__r   r3   r0   r   r      s1    
 ! 08^3r3   r   c                   ,    \ rS rSrSrSr\S 5       rSrg)UpdateAlpha   r   Nc                    [         R                  " SSS9U l        U R                  R                  U5        [         R                  " USS9  [         R
                  " USS9  [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " USS9  [         R                  " USS9  [         R"                  " USS9  [         R$                  " USS9  UR'                  S	S
SSS9  g r   )r
   r   r   r   r   r   r    AddDestPortsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   s     r0   r1   UpdateAlpha.Args   s   "'"E"E#+C++F3	OOFU+	f	:	&!	v	6"	v	6"	V$	""6*	 	84	&51&51&T2
<	  r3   r   )	r   r   r   r   r   r   r   r1   r   r   r3   r0   r   r      s!    
 ! r3   r   EXAMPLESa%      To update a rule with priority ``10'' in an organization security policy
    with ID ``123456789'' to change the action to ``allow'' and description to
    ``new-example-rule'', run:

      $ {command} 10 --security-policy=123456789 --action=allow
      --description=new-example-rule
    )r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   rp   4googlecloudsdk.api_lib.compute.org_security_policiesr   googlecloudsdk.callioper	   8googlecloudsdk.command_lib.compute.org_security_policiesr
   r   :googlecloudsdk.command_lib.compute.security_policies.rulesr)   rm   UniverseCompatibleReleaseTracksrL   BETArw   UpdateCommandr   rM   r   detailed_helpr   r3   r0   <module>r      s    4 &  ' 7 W G ( J ` Z 
 D%%**D,=,=,@,@Ah3T h3 B h3V D%%++, &   -  H 	
 r3   