o .&a@snddlZddlZddlZddlZddlmZddlmZddlm Z e e Z dZ ddZGdd d e ZdS) N)six)model)BaseCLIArgumentz

The file that contains the private key used to launch the instance (e.g. windows-keypair.pem). If this is supplied, the password data sent from EC2 will be decrypted before display.

cKst||d|d<dS)z This handler gets called after the argument table for the operation has been created. It's job is to add the ``priv-launch-key`` parameter. zpriv-launch-keyN)LaunchKeyArgument)argument_tableoperation_modelsessionkwargsr K/usr/lib/python3/dist-packages/awscli/customizations/ec2/decryptpassword.pyec2_add_priv_launch_key s r c@s^eZdZddZeddZeddZejddZedd Zd d Z d d Z ddZ dS)rcCs4||_tdddi|_||_||_d|_d|_dS)NrtypestringF)_sessionrShapeargument_model_operation_model_name _key_path _required)selfrrnamer r r __init__-s  zLaunchKeyArgument.__init__cCsdS)Nrr rr r r cli_type_name5zLaunchKeyArgument.cli_type_namecCs|jSNrrr r r required9szLaunchKeyArgument.requiredcCs ||_dSrr)rvaluer r r r=s cCstSr)HELPrr r r documentationArzLaunchKeyArgument.documentationcCs|j|j|jdddS)NzSSH Private Key file)desthelp) add_argumentcli_namepy_name)rparserr r r add_to_parserEs  zLaunchKeyArgument.add_to_parsercCsl|r4tj|}tj|}tj|r.||_|jjj}d||jj f}|j ||j dSd}t |dS)a This gets called with the value of our ``--priv-launch-key`` if it is specified. It needs to determine if the path provided is valid and, if it is, it stores it in the instance variable ``_key_path`` for use by the decrypt routine. zafter-call.%s.%sz_priv-launch-key should be a path to the local SSH private key file used to launch the instance.N)ospath expandvars expanduserisfilerr service_modelendpoint_prefixrrregister_decrypt_password_data ValueError)r parametersrr*r/eventmsgr r r add_to_paramsIs   zLaunchKeyArgument.add_to_paramscKs|jdurmtd|j|d}|sdSzCt|j3}|}tjt |}t |}t ||}t||d|d<t|WdWdS1sQwYWdStyltjdddd}t|wdS) aq This handler gets called after the GetPasswordData command has been executed. It is called with the and the ``parsed`` data. It checks to see if a private launch key was specified on the command. If it was, it tries to use that private key to decrypt the password data and replace it in the returned data dictionary. Nz"Decrypting password data using: %s PasswordDatazutf-8zUnable to decrypt PasswordDataT)exc_infoz@Unable to decrypt password data using provided private key file.)rloggerdebuggetopenreadrsa PrivateKey load_pkcs1rbbase64 b64decodedecryptdecode Exceptionr2)rparsedr rpk_file pk_contents private_keyr5r r r r1`s*       & z(LaunchKeyArgument._decrypt_password_dataN) __name__ __module__ __qualname__rpropertyrrsetterr!r(r6r1r r r r r+s     r)loggingr)rBr> awscli.compatrbotocorerawscli.argumentsr getLoggerrKr9r r rr r r r s