
    9                        d Z ddlmZ ddlmZ ddlm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d
lmZ ddlmZ ddlmZ dddZej.                   ej0                  ej2                  j4                  ej2                  j6                  ej2                  j8                         G d dej:                                      Zy)z-Export network firewall policy rules command.    )absolute_import)division)unicode_literalsN)base_classes)client)region_client)base)flags)util)fileszG        Exports Firewall Policy rules configuration to a file.
        z        Firewall Policy rules can be exported by running:

          $ {command} FIREWALL_POLICY --destination=<path-to-file> --global
        )DESCRIPTIONEXAMPLESc                   P    e Zd ZdZdZeZed        Zedd       Z	ed        Z
d Zy)ExportzExport Compute Engine network firewall policy rules.

  Exports network firewall policy rules configuration to a file.
  This configuration can be imported at a later time.
  Nc                     | j                         t        j                   j                  k(  ry| j                         t        j                   j                  k(  ryy)z3Returns the API version based on the release track.alphabetav1)ReleaseTrackr	   ALPHABETA)clss    =lib/surface/compute/network_firewall_policies/export_rules.pyGetApiVersionzExport.GetApiVersion:   sG     T..444				t0055	5    c                 P    t        j                  d| j                         d|      S )z!Returns the resource schema path.computeFirewallPolicyfor_help)export_utilGetSchemaPathr   )r   r    s     r   r"   zExport.GetSchemaPathC   s,     $$	 r   c                     t        j                  dd      | _        | j                  j                  |d       t	        j
                  || j                  d             y )NTzexport rules from)required	operationzexport-rules)operation_typer   )r
   NetworkFirewallPolicyArgumentNETWORK_FIREWALL_POLICY_ARGAddArgumentr!   AddExportFlagsr"   )r   parsers     r   ArgszExport.ArgsM   s[    &+&I&I!4'C# ##//~ 0  vs'8'8$'8'GHr   c                 $   t        j                  | j                               }| j                  j	                  ||j
                  t        j                  t                    }t        j                  ||j                        }t        |d      r!t        j                  ||j                        }|j                  d      d   }|j                  j                  j                  |j                         }|j"                  rOt%        j&                  |j"                        5 }t)        j*                  ||| j-                                d d d        y t)        j*                  |t.        j0                  | j-                                y # 1 sw Y   y xY w)	N)scope_lister)compute_clientregionF)only_generate_requestr   )rules)messagestreamschema_path)r   ComputeApiHolderr   r(   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr   NetworkFirewallPolicyhasattrr   RegionNetworkFirewallPolicyDescribemessagesr   r2   destinationr   
FileWriterr!   r   r"   sysstdout)selfargsholderfirewall_policy_refnetwork_firewall_policy_clientfirewall_policyfirewall_policy_rulesr4   s           r   Runz
Export.RunW   s]   **4+<+<+>?F::LL"88@ M 
 &,%A%AFMM&" "H-

3
3!&-- % 5==# > 	O
 #MM22AA## B  D,,-)**,	
 .- '((* .-s   !'FF)F)__name__
__module____qualname____doc__r(   DETAILED_HELPdetailed_helpclassmethodr   r"   r,   rK    r   r   r   r   ,   sU    
 !%-    I I&r   r   )rO   
__future__r   r   r   rB   googlecloudsdk.api_lib.computer   8googlecloudsdk.api_lib.compute.network_firewall_policiesr   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r9   <googlecloudsdk.command_lib.compute.network_firewall_policies!googlecloudsdk.command_lib.exportr   r!   googlecloudsdk.core.utilr   rP   DefaultUniverseOnlyReleaseTracksr   r   r   GACommandr   rS   r   r   <module>r`      s    4 &  ' 
 7 K R ( E N A *		 T..33T5F5F5I5IMT\\ M Mr   