
    !                        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 creating security policies rules.    )absolute_import)division)unicode_literals)base_classes)org_security_policy_rule_utils)client)base)flags)org_security_policies_utilsNc                   *    e Zd ZdZdZed        Zd Zy)CreatezCreate a Compute Engine organizationsecurity policy rule.

  *{command}* is used to create organization security policy rules.
  Nc                    t        j                  dd      | _        | j                  j                  |d       t        j                  |       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                   |       |j#                  d	d
dd       |j$                  j'                  t         j(                         y NTcreate)required	operation)operation_typeinserted)r   F)r   z--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AddOrganization
rule_flags
AddMatcher
AddPreviewadd_argumentdisplay_infoAddCacheUpdaterOrgSecurityPoliciesCompleterclsparsers     9lib/surface/compute/org_security_policies/rules/create.pyArgszCreate.Args)   s   "'"E"E#+C++F8+L	OOF	f
;	&!	6"	v	6"	V$	""6*	 	&51&51&!
<	   ''(J(JK    c                 B   t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }g }g }g }g }g }	g }
d }d }|j                  d      r|j                  }|j                  d      r|j                  }| j                         t        j                  j                  k(  r|j                  d      r|j                   }|j                  d      r|j"                  }|j                  d      r|j$                  }	|j                  d	      r|j&                  }
|j                  d
      rd}|j                  d      rd}t)        j*                  ||j                  j,                        }t)        j.                  ||j                  j,                        }d }|j                  d      r|j                  d      rV|j                  j,                  j1                  |j                  j,                  j3                  |j4                              }ng|j                  j,                  j1                  |j                  j,                  j0                  j6                  j8                  |j                  j,                  j;                  |            }n| j                         t        j                  j                  k(  r|j                  j,                  j1                  |j                  j,                  j0                  j6                  j<                  |j                  j,                  j;                  ||||            }n|j                  j,                  j1                  |j                  j,                  j0                  j6                  j<                  |j                  j,                  j;                  |||            }|j                  j,                  j>                  j@                  jB                  }|j                  d      rx|jD                  dk(  r5|j                  j,                  j>                  j@                  jB                  }n4|j                  j,                  j>                  j@                  jF                  }|j                  j,                  j?                  t)        jH                  |jK                               t)        jL                  |jN                        |||	|
|jP                  ||	      }tS        jT                  ||jV                  |jX                        }|j[                  ||      S )NF)with_project)refcompute_client	resourcesversionsrc_ip_rangesdest_ip_ranges
dest_portslayer4_configstarget_resourcestarget_service_accountsenable_loggingTpreviewcloud_armor
expression)rB   )expr)srcIpRanges)versionedExprconfig)rD   destIpRanges	destPortslayer4Configs)rD   rG   rI   	directionINGRESS)	priorityr   matchrJ   targetResourcestargetServiceAccountsdescriptionenableLoggingr@   )organization)security_policysecurity_policy_rule).r   ComputeApiHolderReleaseTrackr   ResolveAsResourcer7   r   OrgSecurityPolicyRulesix	text_typelowerIsSpecifiedr9   r:   r	   ALPHAr;   r<   r=   r>   
rule_utilsParseDestPortsmessagesParseLayer4ConfigsSecurityPolicyRuleMatcherExprrB   VersionedExprValueValuesEnum
SRC_IPS_V1SecurityPolicyRuleMatcherConfigFIREWALLSecurityPolicyRuleDirectionValueValuesEnumrK   rJ   EGRESSConvertPriorityToIntNameConvertActionr   rP   r   GetSecurityPolicyIdrS   rR   r   )selfargsholderr5   security_policy_rule_clientr9   r:   r;   r<   r=   r>   r?   r@   dest_ports_listlayer4_config_listtraffic_directmatcherrT   security_policy_ids                      r0   Runz
Create.RunB   s   **4+<+<+>?F

&
&
8
8fU 9 4C"(">">}}""d//1288:	#<
 MNJN NG(((m()**nd//555$:J:J;??j()**n*+..12 $ < <()n	"g //
060F0FHO#66~7=}}7M7MON&			,	'--((BB'',,,H C 
 --((BB --00JJggrr==))II) J  C 
 
			 1 1 7 7	7--((BB --00JJggpp==))II)+)0	 J  C 
 --((BB --00JJggpp==))II)+0 J  C 
 --
 
 
3
3
L
L
T
T  
		+	&>>Y&mm$$77PPXX 
 mm$$77PPWW  "==11DD00<''4 (5$$$ E 	 5HH#&&( '--*1 . 3 3r2   )__name__
__module____qualname____doc__r   classmethodr1   rx    r2   r0   r   r      s)    
 !L L0f3r2   r   c                   $    e Zd ZdZdZed        Zy)CreateAlphazuCreate a Compute Engine security policy rule.

  *{command}* is used to create organization security policy rules.
  Nc                     t        j                  dd      | _        | j                  j                  |d       t        j                  |       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"                  |       |j%                  d	d
dd       |j&                  j)                  t         j*                         y r   )r
   r   r   r   r   r   r   AddDestPortsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   s     r0   r1   zCreateAlpha.Args   s(   "'"E"E#+C++F8+L	OOF	f
;	&!	v	6"	v	6"	V$	""6*	 	&51&51&!
<	   ''(J(JKr2   )ry   rz   r{   r|   r   r}   r1   r~   r2   r0   r   r      s#    
 !L Lr2   r   EXAMPLESz    To create a rule with priority ``10'' in an organization security policy with
    ID ``123456789'', run:

      $ {command} 10 --security-policy=123456789 --action=allow
      --description=example-rule --cloud-armor
    )r|   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r^   4googlecloudsdk.api_lib.compute.org_security_policiesr   googlecloudsdk.callioper	   8googlecloudsdk.command_lib.compute.org_security_policiesr
   r   :googlecloudsdk.command_lib.compute.security_policies.rulesr&   rY   UniverseCompatibleReleaseTracksrV   BETACreateCommandr   r]   r   detailed_helpr~   r2   r0   <module>r      s    4 &  ' 7 W G ( J ` Z 
 D%%**+G3T G3 , G3T D%%++, L&  L -  LH   r2   