
    R                         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  G d
 dej                        Zdddde_        y)zIImplements command to remove an SSH public key from the OS Login profile.    )absolute_import)division)unicode_literals)client)base)flags)oslogin_utils)
propertiesc                   8     e Zd ZdZ fdZed        Zd Z xZS )Updatez2Update an SSH public key from an OS Login profile.c                 ,    t        t        | 
  |i | y )N)superr   __init__)selfargskwargs	__class__s      /lib/surface/compute/os_login/ssh_keys/update.pyr   zUpdate.__init__    s    	&$ $1&1    c                 f    d}t        j                  | d|       t        j                  | d       y)z\Set up arguments for this command.

    Args:
      parser: An argparse.ArgumentParser.
    zL Key value can either be the SSH key or the OS Login fingerprint of the key.update)additional_helpT)requiredN)r   AddKeyFlags
AddTtlFlag)parserr   s     r   ArgszUpdate.Args#   s+    :O	fhH	Vd+r   c                 4   t        j                  |      }t        j                  | j	                               }t
        j                  j                  j                  j                         xs2 t
        j                  j                  j                  j                         }t        j                  ||      }t        j                  ||      }t        j                  |j                         }|r|j#                  ||||   d|      S t        j$                  d      )z$See ssh_utils.BaseSSHCLICommand.Run.expirationTimeUsec)expiration_timezCannot find requested SSH key.)r   GetKeyFromArgsr   OsloginClientReleaseTrackr
   VALUESauthimpersonate_service_accountGetcoreaccountr	   GetKeyDictionaryFromProfileFindKeyInKeyListConvertTtlArgToExpiryttlUpdateSshPublicKeyOsloginKeyNotFoundError)r   r   keyoslogin_client
user_emailkeysfingerprintexpirys           r   Runz
Update.Run/   s    


t
$C))$*;*;*=>N##((DDHHJ :&&++33779  44ZPD00d;K00:F..z;/3K/@/C?E / G G
 **+KLLr   )	__name__
__module____qualname____doc__r   staticmethodr   r6   __classcell__)r   s   @r   r   r      s%    :2 	, 	,Mr   r   z0Update an SSH public key in an OS Login profile.z      *{command}* accepts either a string containing an SSH public
      key or a filename for an SSH public key, and updates the key
      in the user's OS Login profile. Currently, only the expiration time,
      ``--ttl'', can be updated.
    a  
      To update the SSH public key found in `/home/user/.ssh/id_rsa.pub` with
      an expiration time of one week from now, run:

        $ {command} --ttl=7d --key-file=/home/user/.ssh/id_rsa.pub

      To update the SSH public key with a fingerprint of
      'e0d96d6fad35a61a0577f467940509b5aa08b6dea8d99456ec19a6e47126bc52' and
      an expiration time of five years from now, run:

        $ {command} --ttl=5y --key='e0d96d6fad35a61a0577f467940509b5aa08b6dea8d99456ec19a6e47126bc52'
    )briefDESCRIPTIONEXAMPLESN)r:   
__future__r   r   r   googlecloudsdk.api_lib.osloginr   googlecloudsdk.callioper   "googlecloudsdk.command_lib.osloginr   r	   googlecloudsdk.corer
   Commandr   detailed_help r   r   <module>rH      sP     P &  ' 1 ( 4 < *$MT\\ $MP @ r   