
    A                     ,   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 dd	lmZ ddlmZ ddlmZ ddlmZ  ej8                  ej:                  j<                         G d dej>                               Z y)zImport ssl policy command.    )absolute_import)division)unicode_literals)
exceptions)base_classes)ssl_policies_utils)base)flags)scope)util)yaml_validator)
console_ioc                   L    e Zd ZdZdZed        Zedd       Zed        Zd Z	y)Importa  Import an SSL policy.

  If the specified SSL policy already exists, it will be overwritten.
  Otherwise, a new SSL policy will be created.
  To edit an SSL policy you can export the SSL policy to a file,
  edit its configuration, and then import the new configuration.
  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/ssl_policies/import.pyGetApiVersionzImport.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	SslPolicyfor_help)export_utilGetSchemaPathr   )r   r    s     r   r"   zImport.GetSchemaPath7   s+     $$3$$&hH Hr   c                     t        j                         | _        | j                  j                  |d       t	        j
                  || j                  d             y )Nimport)operation_typeTr   )r
   GetSslPolicyMultiScopeArgumentSSL_POLICY_ARGAddArgumentr!   AddImportFlagsr"   )r   parsers     r   ArgszImport.Args=   sJ    ==?C""6("Cvs'8'8$'8'GHr   c                 L   t        j                  | j                               }t        j                  |      }|j
                  }| j                  j                  ||j                  t        j                  |j
                        t        j                  j                        }t        j                  |j                   xs dd      }	 t#        j$                  |j&                  j(                  || j+                               }	 |j5                  |      }	|	|k(  ry t        j@                  djC                  |jE                               d	
       |	jF                  |_#        |	jH                  |_$        |jK                  ||d      }|j?                  ||d      S # t,        j.                  $ r#}t1        j.                  t3        |            d }~ww xY w# t6        j8                  $ r@}
|
j:                  dk7  r|
|j=                  ||      }|j?                  ||d      cY d }
~
S d }
~
ww xY w)N)scope_listerdefault_scope-F)binary)message_typestreamschema_pathi  zCreating SSL policyz%SSL Policy [{0}] will be overwritten.T)messagecancel_on_nozUpdating SSL policy)&r   ComputeApiHolderr   r   SslPolicyHelperclientr'   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListercompute_scope	ScopeEnumGLOBALr   ReadFromFileOrStdinsourcer!   r   messagesr   r"   r   ValidationErrorcompute_exceptionsstrDescribeapitools_exceptions	HttpErrorstatus_codeCreateWaitForOperationPromptContinueformatNameidfingerprintPatch)selfargsholderhelperr8   ssl_policy_refdata
ssl_policyessl_policy_olderroroperation_refs               r   Runz
Import.RunC   s   **4+<+<+>?F//7F]]F((::"88G#--44	 ; 6N ))$++*<UKD7%%00((*,j<~6n #8@@!# #%%JM+77JLLUCM"">=#8: :; )) 7..s1v667 (( <			c	!mmNJ?m$$^]%:< <<s6   	:F G G*GGH##5HH#H#)F)
__name__
__module____qualname____doc__r'   classmethodr   r"   r+   r]    r   r   r   r   "   sQ     .  H H
 I I
0:r   r   N)!ra   
__future__r   r   r   apitools.base.pyr   rG   googlecloudsdk.api_lib.computer   +googlecloudsdk.api_lib.compute.ssl_policiesr   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computerD   r
   r;   r   r=   /googlecloudsdk.command_lib.compute.ssl_policies!googlecloudsdk.command_lib.exportr   r!   googlecloudsdk.corer   googlecloudsdk.core.consoler   ReleaseTracksr   r   UpdateCommandr   rc   r   r   <module>rp      sq    ! &  ' > 7 J ( O E E A A . 2 D%%++,P:T P: -P:r   