
                             d Z ddlmZ ddlmZ ddlmZ ddlZddl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
 Zd Zd Zd Zd Zy)zUtil functions for DM commands.    )absolute_import)division)unicode_literalsN)
exceptions)log)resource_printer)http_encodingc                 n    t         j                  j                  dt        j                  |       z         y)z*Prints the fingerprint for user reference.z'The fingerprint of the deployment is %sN)r   statusPrintbase64urlsafe_b64encode)fingerprints    <lib/googlecloudsdk/command_lib/deployment_manager/dm_util.pyPrintFingerprintr       s,     **<..{;= >    c                     	 t        j                  t        j                  |             }|S # t        t
        j                  f$ r t        j                  dd      w xY w)z+Returns the base64 url decoded fingerprint.z--fingerprintzfingerprint cannot be decoded.)	r   urlsafe_b64decoder	   Encode	TypeErrorbinasciiErrorcalliope_exceptionsInvalidArgumentException)r   decoded_fingerprints     r   DecodeFingerprintr   '   sa    ; 22[)+
 
 X^^	$ ;

6
69; ;;s	   (, 0Ac                     |dk(  r| j                  d      S |j                  d      r0| j                  |t        d      d       }| j                  |      S t	        j
                  dd	      )
a?  Translates a dict of credential data into a message object.

  Args:
    message: The API message to use.
    principal: A string contains service account data.
  Returns:
    An ServiceAccount message object derived from credential_string.
  Raises:
    InvalidArgumentException: principal string unexpected format.
  PROJECT_DEFAULTT)useProjectDefaultzserviceAccount:N)email)serviceAccountz--credentialzBcredential must start with serviceAccount: or use PROJECT_DEFAULT.)
Credential
startswithServiceAccountlenr   r   )message	principalservice_accounts      r   CredentialFromr)   2   s     ##55+,,,-./0 - 2O_==44J	L Lr   c                 z    t        j                         }t        j                  | d|       |j	                         S )zReturns a ready-to-print string representation for the provided message.

  Args:
    message: message object

  Returns:
    A ready-to-print string representation of the message.
  yaml)out)ioStringIOr   r   getvalue)r&   output_messages     r   RenderMessageAsYamlr1   H   s0     ;;=.&n=		 	 	""r   c           	         | j                   rDt        j                  dj                  || j                  t        | j                                      yt        j                  j                  dj                  || j                               y)z'Log operation warnings if there is any.z.{0} operation {1} completed with warnings:
{2}z){0} operation {1} completed successfully.N)warningsr   warningformatnamer1   r   r   )	operationoperation_descriptions     r   LogOperationStatusr9   V   sg    KK9@@!9>>	 2 23	56 JJ@GGy~~/ 0r   )__doc__
__future__r   r   r   r   r   r-   googlecloudsdk.callioper   r   googlecloudsdk.corer   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr	   r   r   r)   r1   r9    r   r   <module>rA      sB     & &  '   	 E # 9 2>L,#
0r   