
                         ~   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 e	j                   e	j                   e	j"                  j$                  e	j"                  j&                  e	j"                  j(                         G d
 de	j*                  e	j,                                      Zddie_        y)zNCommand for get_effective_firewalls of network with network firewall policies.    )absolute_import)division)unicode_literals)base_classes)firewalls_utils)base)flags)
propertiesc                   &    e Zd ZdZed        Zd Zy)GetEffectiveFirewallsa   Get the effective firewalls for a network.

  *{command}* is used to get the effective firewalls applied to the network,
  including regional firewalls in a specified region.

  ## EXAMPLES

  To get the effective firewalls for a network, run:

    $ {command} --network=network-a --region=us-central1

  gets the effective firewalls applied on the network network-a, including
  organization firewall policies, global network firewall policies, and regional
  network firewall policies in region us-central1.
  c                     | j                  ddd       | j                  dd       | j                  j                  t        j                         y )Nz	--networkTz/The network to get the effective firewalls for.)requiredhelpz--regionz3The region to get the effective regional firewalls.)r   )add_argumentdisplay_info	AddFormatr   EFFECTIVE_FIREWALL_LIST_FORMAT)parsers    Hlib/surface/compute/network_firewall_policies/get_effective_firewalls.pyArgszGetEffectiveFirewalls.Args1   sX    
>  
 N   !!66    c                    t        j                  | j                               }|j                  }|j                  j                  }t        |d      r|j                  r|j                  }n2t        j                  j                  j                  j                         }t        |d      r|j                  r|j                  }n2t        j                  j                  j                  j                         }t        j                  d       j                  ||j                         }|r|j#                         nd }|j%                  |||      }	|j'                  |j(                  j*                  d|	fg      }
|
d   }g }g }t        |d      r t-        j.                  ||j0                        }t        |d      r|j2                  rg }|j2                  D ]  }t-        j4                  ||j6                        }t-        j4                  ||j8                        }|j                  j;                  |j<                  |||j>                  |j@                  	      }|jC                  |        t-        jD                  ||      }|jG                  d
      r,|jH                  dk(  r|j                  jK                  ||      S g }|D ]'  }|jM                  t-        jN                  ||             ) |jM                  t-        jP                  |             |S )Nprojectregion)
short_help)r   r   networkr   r   	firewallsfirewallPolicys)namerulespacketMirroringRulestypepriorityformatjson)r   r   ))r   ComputeApiHolderReleaseTrackclientmessageshasattrr   r
   VALUEScore	GetOrFailr   computenetwork_flagsNetworkArgumentForOtherResourceResolveAsResource	resourcesSelfLink@ComputeRegionNetworkFirewallPoliciesGetEffectiveFirewallsRequestMakeRequestsapitools_clientregionNetworkFirewallPoliciesr   SortNetworkFirewallRulesr   r   SortFirewallPolicyRulesr    r!   QRegionNetworkFirewallPoliciesGetEffectiveFirewallsResponseEffectiveFirewallPolicyr   r"   r#   appendSortFirewallPoliciesIsSpecifiedr$   :RegionNetworkFirewallPoliciesGetEffectiveFirewallsResponseextend,ConvertFirewallPolicyRulesToEffectiveFwRules-ConvertNetworkFirewallRulesToEffectiveFwRules)selfargsholderr(   r)   r   r   r   network_refrequest	responsesresnetwork_firewallall_firewall_policyall_unsorted_firewall_policyfpfirewall_policy_rulepacket_mirroring_rulesfp_responseresults                       r   RunzGetEffectiveFirewalls.Run?   s   **4+<+<+>?F]]F}}%%HtYDLLg!!&&..88:gtX4;;{{f  ((//99;f;;f../  )0'""$TKWW X G ##<<& % I
 A,CsK (AA
#-- s%&3+>+>%'"##".FFBHH 
 "1!H!HB++"
 ooww&!7[[ x 
 	%++K8 $ ,@@
. !dkkV&;__WW$6I X   F!mm

F
Fb " MMEE	

 Mr   N)__name__
__module____qualname____doc__staticmethodr   rQ    r   r   r   r      s!    
   Lr   r   EXAMPLESa      To get the effective firewalls of network with name ``example-network'',
    including effective regional firewalls for that network, in region
    ``region-a'', run:

      $ {command} --network=example-network --region=region-a

    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} --network=example-network --region=region-a --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)rU   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   +googlecloudsdk.command_lib.compute.networksr	   r/   googlecloudsdk.corer
   DefaultUniverseOnlyReleaseTracksr'   GABETAALPHADescribeCommandListCommandr   detailed_helprW   r   r   <module>rf      s    U &  ' 7 : ( N * $++00$2C2C2I2IkD00$2B2B k k^  5 '  #r   