
                         |   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Z ej0                  ej2                  j4                  ej2                  j6                  ej2                  j8                         G d dej:                               Zy)z1Retrieves information about a Cloud SQL instance.    )absolute_import)division)unicode_literals)
exceptions)api_util)	instances)validate)base)core)flags)
propertiesNc                   &    e Zd ZdZed        Zd Zy)Geta  Displays configuration and metadata about a Cloud SQL instance.

  Displays configuration and metadata about a Cloud SQL instance.

  Information such as instance name, IP address, region, the CA certificate
  and configuration settings will be displayed.
  c                     | j                  dt        j                  d       | j                  j	                  dj                  t        j                               y)zArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use it to add arguments that go on
        the command line after this command. Positional arguments are allowed.
    instancezCloud SQL instance ID.)	completerhelpz{0} defaultN)add_argumentr   InstanceCompleterdisplay_info	AddFormatformatINSTANCES_USERLABELS_FORMAT)parsers    %lib/surface/sql/instances/describe.pyArgszGet.Args.   sR     ))%  ' !!-"6"6))#+ ,    c                    t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }	 |j                  j!                  |j#                  |j                  |j                              }t%        j&                  |      }t        j(                  j*                  j-                  |      }d|j/                         v rzd|d   j/                         v red}	d|d   d   j/                         v r|d   d   d   }	g }
d	|d   d   j/                         v r|d   d   d	   }
|	rt1        |
      d
k(  rd|d   d   d<   |S # t2        j4                  $ r}}|j6                  t8        j:                  j<                  j>                  k(  r2tA        jB                  djE                  |jG                                     tI        jJ                  |      d}~ww xY w)a\  Displays configuration and metadata about a Cloud SQL instance.

    Information such as instance name, IP address, region, the CA certificate
    and configuration settings will be displayed.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.

    Returns:
      A DatabaseInstancePresentation object representing the instance resource
      if fetching the instance was successful.
    Raises:
      HttpException: A http error response was received while executing api
          request.
    ResourceNotFoundError: The SQL instance was not found.
    projectzsql.instances)params
collection)r   r   settingsipConfigurationFipv4EnabledauthorizedNetworksr   zConfiguring authorized network or using CloudSQL auth proxy or language connectors is a prerequisite for connecting to Public IP. Please refer to the documentation for more details https://cloud.google.com/sql/docs/mysql/authorize-networks.messagezIThere was no instance found at {} or you are not authorized to access it.N)&r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr	   ValidateInstanceNamer   resource_parserParser   VALUESr   r   	GetOrFailr   r   SqlInstancesGetRequestinstance_api_utilDatabaseInstancePresentationresourceresource_projectorMakeSerializablekeyslenapitools_exceptions	HttpErrorstatus_codesixmoveshttp_client	FORBIDDENr   ResourceNotFoundErrorr   RelativeNamecalliope_exceptionsHttpException)selfargsclientr)   r*   instance_refr   instance_presentation serialized_instance_presentationr$   r%   errors               r   RunzGet.Run=   sP   $  < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L
5%%))

-
-"**\5J5J . LMh 0LLXV)-)I)I)Z)Z[p)q&	7<<>	>CTXx  zD  YE  YJ  YJ  YL  DL<ZHIZ[``bb8DEVWXef+#CJ#OPa#b#g#g#ii?
KL]^_st
312a7K +:
67H
I)
T .-(( 5			cii33==	=.. 9 9 ;<> 	>  --e445s   2DF> >IA8I		IN)__name__
__module____qualname____doc__staticmethodr   rJ    r   r   r   r   #   s      , ,65r   r   )rN   
__future__r   r   r   apitools.base.pyr   r8   googlecloudsdk.api_lib.sqlr   r   r1   r	   googlecloudsdk.callioper
   googlecloudsdkr   rA   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   six.moves.http_clientr;   ReleaseTracksReleaseTrackGABETAALPHADescribeCommandr   rP   r   r   <module>r_      s    8 &  ' > / 1 E / (  E 0 *  D%%(($*;*;*@*@%%++-N5$

 N5-N5r   