
                            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 e
j"                   e
j$                  e
j&                  j(                  e
j&                  j*                  e
j&                  j,                         G d de
j.                  e
j0                                      Zddie_        y)z8Command for getting effective firewalls of GCP networks.    )absolute_import)division)unicode_literals)base_classes)firewalls_utils)lister)base)flags)logc                   ,    e Zd ZdZed        Zd Zd Zy)GetEffectiveFirewallsa9  Get the effective firewalls of a Compute Engine network.

  *{command}* is used to get the effective firewalls applied to the network.

  ## EXAMPLES

  To get the effective firewalls for a network, run:

    $ {command} example-network

  gets the effective firewalls applied on the network 'example-network'.
  c                     t        j                         j                  | d       | j                  j	                  t
        j                         t        j                  |        y )Nzget effective firewalls)operation_type)	r
   NetworkArgumentAddArgumentdisplay_info	AddFormatr   EFFECTIVE_FIREWALL_LIST_FORMATr   AddBaseListerArgs)parsers    7lib/surface/compute/networks/get_effective_firewalls.pyArgszGetEffectiveFirewalls.Args0   sS    	''8 (  !!66 V$    c                 :   t        j                  | j                               }|j                  }t	        j
                         j                  ||j                  t        j                  |            } |j                  j                  di |j                         }|j                  |j                  j                  d|fg      }|d   }g }g }	g }
t!        |d      r t#        j$                  ||j&                        }	t!        |d      r|j(                  rg }|j(                  D ]  }t#        j*                  ||j,                        }t#        j*                  ||j.                        }|j                  j1                  |j2                  |||j4                  |j6                        }|j9                  |        t#        j:                  ||      }
nst!        |d      rg|j<                  D ]X  }t#        j>                  ||j,                        }|j9                  |j                  jA                  |jB                  |             Z |jE                  d	      rL|jF                  d
k(  r=|r|j                  jI                  ||	|
      S |j                  jI                  |	|
      S g }|
D ]'  }|jK                  t#        jL                  ||             ) |D ]&  }|jK                  t#        jN                  |             ( |jK                  t#        jP                  |	             |S )N)scope_listerr   r   	firewallsfirewallPolicys)namerulespacketMirroringRulestypepriorityorganizationFirewalls)idr   formatjson)r#   r   r   )r   r    ))r   ComputeApiHolderReleaseTrackclientr
   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListermessages+ComputeNetworksGetEffectiveFirewallsRequestAsDictMakeRequestsapitools_clientnetworkshasattrr   SortNetworkFirewallRulesr   r   SortFirewallPolicyRulesr   r    <NetworksGetEffectiveFirewallsResponseEffectiveFirewallPolicyr   r!   r"   appendSortFirewallPoliciesr#   SortOrgFirewallRules?NetworksGetEffectiveFirewallsResponseOrganizationFirewallPolicyr$   IsSpecifiedr%   %NetworksGetEffectiveFirewallsResponseextend,ConvertFirewallPolicyRulesToEffectiveFwRules/ConvertOrgSecurityPolicyRulesToEffectiveFwRules-ConvertNetworkFirewallRulesToEffectiveFwRules)selfargsholderr*   network_refrequest	responsesresorg_firewallnetwork_firewallall_firewall_policyall_unsorted_firewall_policyfpfirewall_policy_rulepacket_mirroring_rulefp_responsesporg_firewall_ruleresults                      r   RunzGetEffectiveFirewalls.Run:   s   **4+<+<+>?F]]F'');;"88@ < K JfooII 



G ##

 
 
)
)+BG	LMI A,CLsK (AA
#-- s%&3+>+>%'"##".FFBHH 
 !0 G GB++!
 oobb&!6[[ c 
 	%++K8 $  ,@@
. 
-	.))"+@@BHH
 	OO[[55 1 \ 	
	 * !dkkV&;	DD".&/ E 
 	
 DD&8K E 
 	
 F!mm

F
Fb " mm

I
I"
M  MMEE	

 Mr   c                 f    ~t         j                  j                  dt        j                  z          y )N
)r   statusPrintr   LIST_NOTICE)rC   resources_were_displayeds     r   EpilogzGetEffectiveFirewalls.Epilog   s"     JJTO7778r   N)__name__
__module____qualname____doc__staticmethodr   rU   r\   r'   r   r   r   r      s'    
 % %Vp9r   r   EXAMPLESa      To get the effective firewalls of network with name example-network, run:

      $ {command} example-network

    To show all fields of the firewall rules, please show in JSON format with
    option --format=json

    To list more the fields of the rules of network example-network in table
    format, run:

      $ {command} example-network --format="table(
        type,
        firewall_policy_name,
        rule_type,
        priority,
        action,
        direction,
        ip_ranges.list():label=IP_RANGES,
        target_svc_acct,
        enableLogging,
        description,
        name,
        disabled,
        target_tags,
        src_svc_acct,
        src_tags,
        ruleTupleCount,
        targetResources:label=TARGET_RESOURCES)"
        N)r`   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r-   +googlecloudsdk.command_lib.compute.networksgooglecloudsdk.corer   DefaultUniverseOnlyReleaseTracksr)   GABETAALPHADescribeCommandListCommandr   detailed_helpr'   r   r   <module>rq      s    ? &  ' 7 : 1 ( E = # $++00$2C2C2I2Ir9D00$2B2B r9 r9l  '  #r   