
                             d Z ddlmZ ddlmZ ddlmZ ddlZddl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
Zd Z	 ddZd Zd Zd Zy)zFCode that's shared between multiple org firewall policies subcommands.    )absolute_import)division)unicode_literalsN)network_security)
exceptions)reference_utils)logzorganizations/c                    | j                  |d      }d}|d   j                  D ]  }|j                  |k(  s|j                  } n |8t	        j
                  dj                  |             t        j                          |S )aK  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                     t        j                  d|      s@|*t        j                  d|       t	        j
                          t        | |t        |z         S |S )aa  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%   <   sY     
+	/	ii%' 
hhj"#9?#6#EG G	r   c                 F   t        j                  d|      s'|%t        j                  ddj	                  |            |}|sG| j                  |      }|s$t        j                  dj	                  |            |d   j                  }d|v r|j                  d      d   }|S )	aQ  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                     d| v r| S t        |||      }t        j                  t        j                  t        j
                  j                  j                        |d|       S )a  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                 \    d| v r| S t        |||      }t        j                  d|d|       S )aw  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   