
                             S r SSKJr  SSKJr  SSKJr  SSKrSSK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
rS r SS jrS rS rS rg)zFCode that's shared between multiple org firewall policies subcommands.    )absolute_import)division)unicode_literalsN)network_security)
exceptions)reference_utils)logzorganizations/c                    U R                  USS9nSnUS   R                   H!  nUR                  U:X  d  M  UR                  n  O   Uc:  [        R
                  " SR                  U5      5        [        R                  " 5         U$ )a=  Returns the firewall policy id that matches the short_name in the org.

Args:
  firewall_policy: the organization firewall policy.
  short_name: the short name of the firewall policy to be resolved.
  organization_id: the organization ID which the firewall policy belongs to.

Returns:
  Firewall policy resource ID.
F)	parent_idonly_generate_requestNr   zHInvalid short name: {0}. No Security Policy with this short name exists.)	ListitemsdisplayNamenamer	   errorformatsysexit)firewall_policy
short_nameorganization_idresponsefp_idfps         Slib/googlecloudsdk/command_lib/compute/firewall_policies/firewall_policies_utils.pyResolveFirewallPolicyIdr   !   s     !!u " >(
%QKb	~~#gge  ]IIR	
	 HHJ	,    c                     [         R                  " SU5      (       dB  Uc,  [        R                  " SU5        [        R
                  " 5         [        X[        U-   5      $ U$ )aS  Returns the firewall policy id that matches the short_name in the org.

Args:
  firewall_policy_client: the organization firewall policy client.
  firewall_policy: the short name or ID of the firewall policy to be resolved.
  organization: the organization ID which the firewall policy belongs to.

Returns:
  Firewall policy resource ID.
\d{9,15}zAMust set --organization=ORGANIZATION when short name [%s]is used.)rematchr	   r   r   r   r   ORGANIZATION_PREFIX)firewall_policy_clientr   organizations      r   GetFirewallPolicyIdr%   <   sZ     
+	/	/	ii%' 
hhj"#9#6#EG G	r   c                 j   [         R                  " SU5      (       d)  Uc&  [        R                  " SSR	                  U5      5      eUnU(       dJ  U R                  US9nU(       d%  [        R                  " SR	                  U5      5      eUS   R                  nSU;   a  UR                  S5      S   nU$ )	aA  Returns ID of the organization the given firewall policy belongs to.

Args:
  firewall_policy_client: the organization firewall policy client.
  firewall_policy_id: the short name or ID of the firewall policy to be
    resolved.
  optional_organization: organization if provided.

Returns:
  Firewall policy resource ID.
r   z--organizationzBMust set --organization=ORGANIZATION when short name [{0}]is used.)r   z%Firewall Policy [{0}] does not exist.r   /   )
r    r!   r   RequiredArgumentExceptionr   Describecompute_exceptionsInvalidResourceErrorparentsplit)r#   firewall_policy_idoptional_organizationr$   fetched_policiess        r   GetFirewallPolicyOrganizationr2   V   s     
+$
& 
&*?*G

.
.	6,-/ / ',	-66=O6P33
1
8
89K
LN N#A&--LL%%c*1-L	r   c                     SU ;   a  U $ [        UUUS9n[        R                  " [        R                  " [        R
                  R                  R                  5      USU S9$ )au  Returns Full URL reference of Security Profile Group.

Args:
  security_profile_group: reference string provided by the user.
  optional_organization: organization if provided.
  firewall_policy_client: the organization firewall policy client.
  firewall_policy_id: the short name or ID of the firewall policy to be
    resolved.

Returns:
  URL to Security Profile Group.
r'   r#   r/   r0   securityProfileGroupsbase_uriorg_idcollection_nameresource_name)r2   r   'BuildFullResourceUrlForOrgBasedResourcer   GetApiBaseUrlbaseReleaseTrackGA)security_profile_groupr0   r#   r/   r$   s        r   BuildSecurityProfileGroupUrlrA   u   si      	""!!.3+13, 
	@	@--



,
,
/
/ -*
 r   c                 V    SU ;   a  U $ [        UUUS9n[        R                  " SUSU S9$ )ae  Returns partial URL reference of Address Group.

Args:
  address_group: reference string provided by the user.
  optional_organization: organization if provided.
  firewall_policy_client: the organization firewall policy client.
  firewall_policy_id: the short name or ID of the firewall policy to be
    resolved.

Returns:
  partial URL to Address Group.
r'   r4    addressGroupsr6   )r2   r   r;   )address_groupr0   r#   r/   r$   s        r   BuildAddressGroupUrlrF      sF      	M.3+13, 
	@	@%!	
# #r   )N)__doc__
__future__r   r   r   r    r   googlecloudsdk.api_libr   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer+   r   googlecloudsdk.corer	   r"   r   r%   r2   rA   rF    r   r   <module>rN      sN    M &  ' 	 
 3 . O > #& : &*4>B#r   