
    h$                        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Zej&                   ej(                  ej*                  j,                         G d dej.                                      Zej&                   ej(                  ej*                  j2                         G d de                    Zddie_        y)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                   6    e Zd ZdZdZed        Zd Zd Zd Z	y)UpdateuUpdate a Compute Engine security policy rule.

  *{command}* is used to update organization security policy rules.
  Nc                    t        j                  dd      | _        | j                  j                  |       t        j                  |d       t        j
                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |d       t        j                  |d       t        j                   |d       t        j"                  |d       |j%                  d	d
dd       y 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ArgszUpdate.Args)   s   "'"E"E#+C++F3	OOFU+	f	:	&!	6"	v	6"	V$	""6*	 	84	&51&51&T2
<	      c                    |j                  d      rJ|j                  j                  j                  |j                  j                  j	                  |            S |j                  j                  j                  |j                  j                  j                  j
                  j                  |j                  j                  j                  |            S )N
expression)r3   )expr)srcIpRangesversionedExprconfig)IsSpecifiedr   messagesSecurityPolicyRuleMatcherExprVersionedExprValueValuesEnum
SRC_IPS_V1SecurityPolicyRuleMatcherConfig)selfargsholderr3   src_ip_rangess        r/   _SetupCloudArmorMatchzUpdate._SetupCloudArmorMatchB   s    %]]##==}}%%**j*A >   ]]##==..HHeepp''GG' H  >  r1   c           	      V   | j                         t        j                   j                  k(  r|j                  j                  j                  |j                  j                  j
                  j                  j                  |j                  j                  j                  ||||            S |j                  j                  j                  |j                  j                  j
                  j                  j                  |j                  j                  j                  |||            S )N)r5   destIpRanges	destPortslayer4Configsr6   )r5   rF   rH   )	ReleaseTrackr	   ALPHAr   r:   r;   r=   FIREWALLr?   )r@   rB   rC   dest_ip_rangesdest_ports_listlayer4_config_lists         r/   _SetupFirewallMatchz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  >  r1   c                    t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }t        j                  |j                               }d }g }g }g }	g }
g }g }d }d }d}d }d }|j                  d      r|j                  }d}|j                  d      r|j                   }d}|j                  d      r|j"                  }d}| j                         t$        j                  j&                  k(  rG|j                  d      r6d}t        j(                  |j*                  |j                  j,                        }	|j                  d	      r6d}t        j.                  |j0                  |j                  j,                        }
|j                  d
      r|j2                  }|j                  d      r|j4                  }|j                  d      rd}|j                  d      r|j6                  }|j                  d      r t        j                  |j8                        }n|}|r;|j                  d      r| j;                  ||||      }n| j=                  ||||	|
      }|j                  d      rx|j>                  dk(  r5|j                  j,                  j@                  jB                  jD                  }n4|j                  j,                  j@                  jB                  jF                  }|j                  j,                  jA                  |t        jH                  |jJ                        |||||jL                  ||	      }tO        jP                  ||jR                  |jT                        }|jW                  |||      S )NF)with_project)refcompute_client	resourcesversionr3   TrC   rL   
dest_portslayer4_configstarget_resourcestarget_service_accountsenable_loggingpreviewnew_prioritycloud_armor	directionINGRESS)	priorityr   matchr^   targetResourcestargetServiceAccountsdescriptionenableLoggingr[   )organization)r`   security_policysecurity_policy_rule),r   ComputeApiHolderrI   r   ResolveAsResourcerT   r   OrgSecurityPolicyRulesix	text_typelower
rule_utilsConvertPriorityToIntNamer9   r3   rC   rL   r	   rJ   ParseDestPortsrV   r:   ParseLayer4ConfigsrW   rX   rY   r[   r\   rD   rO   r^   SecurityPolicyRuleDirectionValueValuesEnumr_   EGRESSConvertActionr   rd   r   GetSecurityPolicyIdrg   rf   r   )r@   rA   rB   rR   security_policy_rule_clientr`   r3   rC   rL   rM   rN   rX   rY   rZ   r[   should_setup_matchtraffic_directmatcherr\   rh   security_policy_ids                        r/   Runz
Update.Runk   s   **4+<+<+>?F

&
&
8
8fU 9 4C"(">">}}""d//1288:	#<
 ..sxxz:HJMNO NGNG%??j(((m()**nd//555$:J:J;"11$//28--2H2HJo()%88


v}}557*+..12 $ < <()n	"g'44T5F5FGll 			-	(,,&*m
 **
 $	9	$MM""55NNVV 	
 MM""55NNUU 	 "==11DD''4 (5$$$ E 
 5HH#&&(
 '--*1 . 3 3r1   )
__name__
__module____qualname____doc__r   classmethodr0   rD   rO   r~    r1   r/   r   r      s1    
 ! 08a3r1   r   c                   $    e Zd ZdZdZed        Zy)UpdateAlphar   Nc                     t        j                  dd      | _        | j                  j                  |       t        j                  |d       t        j
                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |d       t        j                  |d       t!        j"                  |d       t!        j$                  |d       |j'                  d	d
dd       y r   )r
   r   r   r   r   r   r   AddDestPortsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   s     r/   r0   zUpdateAlpha.Args   s   "'"E"E#+C++F3	OOFU+	f	:	&!	v	6"	v	6"	V$	""6*	 	84	&51&51&T2
<	  r1   )r   r   r   r   r   r   r0   r   r1   r/   r   r      s!    
 ! r1   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   ro   4googlecloudsdk.api_lib.compute.org_security_policiesr   googlecloudsdk.callioper	   8googlecloudsdk.command_lib.compute.org_security_policiesr
   r   :googlecloudsdk.command_lib.compute.security_policies.rulesr(   rl   UniverseCompatibleReleaseTracksrI   BETAUpdateCommandr   rJ   r   detailed_helpr   r1   r/   <module>r      s    4 &  ' 7 W G ( J ` Z 
 D%%**+k3T k3 , k3\ D%%++, &   -  H 	
 r1   