
    h                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr	  SSKJ
r
  SSKJr  SS	KJr  \	R                  R                   S
\	R                  R"                  S\	R                  R$                  S0rS r " S S\R*                  5      rg)zIFunctions for creating a client to talk to the App Engine Admin SSL APIs.    )absolute_import)division)unicode_literals)appengine_api_client_base)base)
exceptions)	resources)filesv1v1alphav1betac                 >    [         U    n[        R                  U5      $ )a  Retrieves a client based on the release track.

The API clients override the base class for each track so that methods with
functional differences can be overridden. The ssl-certificates api does not
have API changes for alpha, but output is formatted differently, so the alpha
override simply calls the new API.

Args:
  release_track: calliope_base.ReleaseTrack, the release track of the command

Returns:
  A client that calls appengine using the v1beta or v1alpha API.
)SSL_VERSIONS_MAPAppengineSslApiClientGetApiClient)release_trackapi_versions     >lib/googlecloudsdk/api_lib/app/api/appengine_ssl_api_client.pyGetApiClientForTrackr   "   s     !/+		+	+K	88    c                   L    \ rS rSrSrS rS rS rS rS r	   SS	 jr
S
 rSrg)r   4   zBClient used by gcloud to communicate with the App Engine SSL APIs.c                     [         R                  R                  X5        [        R                  R                  5       U l        U R                  R                  SUR                  5        g )N	appengine)	r   AppengineApiClientBase__init__r	   REGISTRYClone	_registryRegisterApiByName_VERSION)selfclients     r   r   AppengineSslApiClient.__init__7   sD    ((6''--/DNNN$$[&//Br   c                 X   [         R                  " U5      n[         R                  " U5      nU R                  R                  XTS9nU R                  R	                  XS9nU R                  R                  U R                  5       US9nU R                  R                  R                  U5      $ )am  Creates a certificate for the given application.

Args:
  display_name: str, the display name for the new certificate.
  cert_path: str, location on disk to a certificate file.
  private_key_path: str, location on disk to a private key file.

Returns:
  The created AuthorizedCertificate object.

Raises:
  Error if the file does not exist or can't be opened/read.

privateKeypublicCertificatedisplayNamecertificateRawData)parentauthorizedCertificate)
r
   ReadFileContentsmessagesCertificateRawDataAuthorizedCertificate0AppengineAppsAuthorizedCertificatesCreateRequest
_FormatAppr#   apps_authorizedCertificatesCreate)	r"   display_name	cert_pathprivate_key_pathcertificate_dataprivate_key_datacert	auth_certrequests	            r   CreateSslCertificate*AppengineSslApiClient.CreateSslCertificate>   s     --i8--.>?==++# , ID 33  4 ;I mmLL 	 M CG ;;2299'BBr   c                     U R                   R                  U R                  U5      S9nU R                  R                  R                  U5        g)zyDeletes an authorized certificate for the given application.

Args:
  cert_id: str, the id of the certificate to delete.
)nameN)r/   0AppengineAppsAuthorizedCertificatesDeleteRequest_FormatSslCertr#   r4   Deleter"   cert_idr=   s      r   DeleteSslCertificate*AppengineSslApiClient.DeleteSslCertificateZ   sF     mmLL  ) M +G 	KK++227;r   c                     U R                   R                  U R                  U5      U R                   R                  R                  R                  S9nU R
                  R                  R                  U5      $ )zGets a certificate for the given application.

Args:
  cert_id: str, the id of the certificate to retrieve.

Returns:
  The retrieved AuthorizedCertificate object.
)rA   view)r/   -AppengineAppsAuthorizedCertificatesGetRequestrC   ViewValueValuesEnumFULL_CERTIFICATEr#   r4   GetrE   s      r   GetSslCertificate'AppengineSslApiClient.GetSslCertificatee   sb     mmII  )mmII!!"2"2 J 5G
 ;;2266w??r   c                     U R                   R                  U R                  5       S9nU R                  R                  R                  U5      nUR                  $ )zrLists all authorized certificates for the given application.

Returns:
  A list of AuthorizedCertificate objects.
)r,   )r/   .AppengineAppsAuthorizedCertificatesListRequestr3   r#   r4   Listcertificates)r"   r=   responses      r   ListSslCertificates)AppengineSslApiClient.ListSslCertificatesu   sP     mmJJ  K "G {{66;;GDH   r   Nc                    [        U5      [        U5      -  (       a"  U(       d  SOSn[        R                  " US5      e/ nU(       a  UR                  S5        SnU(       a]  U(       aV  [        R
                  " U5      n[        R
                  " U5      n	U R                  R                  XS9nUR                  S5        U R                  R                  X'S9n
U(       d  [        R                  " / S	QS
5      eU R                  R                  U R                  U5      U
SR                  U5      S9nU R                  R                  R                  U5      $ )a[  Updates a certificate for the given application.

One of display_name, cert_path, or private_key_path should be set. Omitted
fields will not be updated from their current value. Any invalid arguments
will fail the entire command.

Args:
  cert_id: str, the id of the certificate to update.
  display_name: str, the display name for a new certificate.
  cert_path: str, location on disk to a certificate file.
  private_key_path: str, location on disk to a private key file.

Returns:
  The created AuthorizedCertificate object.

Raises: InvalidInputError if the user does not specify both cert and key.
--certificate--private-keyzBThe certificate and the private key must both be updated together.r*   Nr&   r+   r)   )rY   rZ   z--display-namez@Please specify at least one attribute to the certificate update.,)rA   r-   
updateMask)boolr   RequiredArgumentExceptionappendr
   r.   r/   r0   r1   MinimumArgumentException/AppengineAppsAuthorizedCertificatesPatchRequestrC   joinr#   r4   Patch)r"   rF   r6   r7   r8   missing_argmask_fields	cert_datacertificateprivate_keyr<   r=   s               r   UpdateSslCertificate*AppengineSslApiClient.UpdateSslCertificate   s?   , I.//+4O/k00

NP P K'I%**95k**+;<k--22  3 Ai-.33  4 @I // 1	KM M mmKK  )'88K( L *G
 ;;2288AAr   c                 p    U R                   R                  USU R                  0SS9nUR                  5       $ )NappsIdz%appengine.apps.authorizedCertificates)params
collection)r   ParseprojectRelativeName)r"   rF   ress      r   rC   $AppengineSslApiClient._FormatSslCert   s>    
..

$,,':  <C r   )r   )NNN)__name__
__module____qualname____firstlineno____doc__r   r>   rG   rO   rV   ri   rC   __static_attributes__ r   r   r   r   4   s8    JCC8	<@ ! )-%),0	6Bpr   r   N)rx   
__future__r   r   r   googlecloudsdk.api_lib.app.apir   r   googlecloudsdk.calliopecalliope_baser   googlecloudsdk.corer	   googlecloudsdk.core.utilr
   ReleaseTrackGAALPHABETAr   r   r   r   rz   r   r   <module>r      sy    P &  ' L 9 . ) * !!4$$i##X 9$KD77 Kr   