
    v                     V    d Z ddlmZ ddlmZ ddlmZ dZdZdZd Zd	 Z	d
 Z
d Zd Zy)zDCommon command-agnostic utility functions for server-certs commands.    )absolute_import)division)unicode_literalsActiveNextPreviousc                     | j                   j                  |j                  |j                  |j                              S )z>Calls the list server certs endpoint and returns the response.)projectinstance)	instancesListServerCertificates)SqlInstancesListServerCertificatesRequestr
   r   )
sql_clientsql_messagesinstance_refs      2lib/googlecloudsdk/api_lib/sql/ssl/server_certs.pyr   r      s?    				4	4<<&&1F1F = 
     c                    i }| j                   }| j                  }d}|D ]  }|j                  |k(  s|} n |s|S ||t        <   |D cg c]  }|j                  |k7  s| }}t	        |      dk(  r4|d   }|j
                  |j
                  kD  r||t        <   |S ||t        <   |S t	        |      dkD  r&t        |d       }|d   |t        <   |d   |t        <   |S c c}w )aO  Gets a dictionary mapping Server Cert types to certs.

  The keys to the dictionary returned will be some combinatiaon of 'Current',
  'Next', and 'Previous'.

  Args:
    list_server_certs_response: InstancesListServerCertificatesResponse
      instance.

  Returns:
    A dictionary mapping Server Cert types to SslCert instances.
  N   r   c                     | j                   S )N)
createTime)certs    r   <lambda>z.GetServerCertificateTypeDict.<locals>.<lambda>L   s    T__r   )key)	activeVersionserverCertssha1FingerprintACTIVE_CERT_LABELlenr   NEXT_CERT_LABELPREVIOUS_CERT_LABELsorted)list_server_certs_responseserver_cert_types	active_idcertsactive_certr   inactive_certsinactive_certs           r   GetServerCertificateTypeDictr+   #   s    (66) %
0
0%+dy(k  
)4%& &+PUTd.B.Bi.ODU.PA"1%M+"8"88+8( 
 0=+, 
 >QN0LMN-;A->)*)7);o&	 Qs   CCc                 X    t        t        | ||            }|j                  t              S )z)Returns the currently active Server Cert.)r+   r   getr   r   r   r   r%   s       r   GetCurrentServerCertificater/   S   s-    2Z|D 
		0	11r   c                 X    t        t        | ||            }|j                  t              S )z!Returns the upcoming Server Cert.)r+   r   r-   r!   r.   s       r   GetNextServerCertificater1   [   s,    2Z|D 
			//r   c                 X    t        t        | ||            }|j                  t              S )z*Returns the previously active Server Cert.)r+   r   r-   r"   r.   s       r   GetPreviousServerCertificater3   c   s-    2Z|D 
		2	33r   N)__doc__
__future__r   r   r   r   r!   r"   r   r+   r/   r1   r3    r   r   <module>r7      s?    K &  '   -`204r   