o .&a@sTddlZddlmZddlmZddlmZmZmZm Z m Z m Z GdddeZ dS)N) BasicCommand)DEFAULT_CONFIG_FILE)validate_regionvalidate_instance_name validate_tagsvalidate_iam_user_arnINSTANCE_NAME_ARGIAM_USER_ARN_ARGc@seZdZdZdZddddddd dddd d d Zed dddeddegZddZ ddZ ddZ ddZ ddZ ddZdd Zd!S)"RegisterregisteraCreates an IAM user for the on-premises instance, if not provided, and saves the user's credentials to an on-premises instance configuration file; registers the on-premises instance with AWS CodeDeploy; and optionally adds tags to the on-premises instance.arrayobjectz The tag key.stringT) descriptiontyperequiredzThe tag value.)KeyValue)r properties)ritemstagsz--tags F+zFOptional. The list of key/value pairs to tag the on-premises instance.)namesynopsisrnargsschema help_textc Cs|}|j|_t||t|t|t||jjd|j|j|j d|_ |jjd|jd|_ z0|j sG| ||||||||||jrT||tjdtWdSty}ztjtjd|WYd}~dSd}~ww)N codedeploy) region_name endpoint_urlverifyiam)rzCopy the on-premises configuration file named {0} to the on-premises instance, and run the following command on the on-premises instance to install and configure the AWS CodeDeploy Agent: aws deploy install --config-file {0} zERROR {0} Register the on-premises instance by following the instructions in "Configure Existing On-Premises Instances by Using AWS CodeDeploy" in the AWS CodeDeploy User Guide. )_sessionsessionrrrr create_clientregionr verify_sslrr! iam_user_arn_create_iam_user_create_access_key_create_user_policy_create_config_register_instancer _add_tagssysstdoutwriteformatr Exceptionflushstderr)self parsed_argsparsed_globalsparamser:K/usr/lib/python3/dist-packages/awscli/customizations/codedeploy/register.py _run_mainDsN         zRegister._run_maincCsLtjd|j|_|jjd|jd}|dd|_tjd|jdS)NzCreating the IAM user... z/AWS/CodeDeploy/)PathUserNameUserArnzDONE IamUserArn: {0} ) r.r/r0 instance_name user_namer! create_userr'r1r5r8responser:r:r;r(ts zRegister._create_iam_usercCsTtjd|jj|jd}|dd|_|dd|_tjd|j|jdS)Nz$Creating the IAM user access key... )r> AccessKey AccessKeyIdSecretAccessKeyz+DONE AccessKeyId: {0} SecretAccessKey: {1} ) r.r/r0r!create_access_keyrB access_key_idsecret_access_keyr1rDr:r:r;r)s zRegister._create_access_keycCsLtjdd|_d|_|jj|j|j|jdtjd|j|jdS)Nz Creating the IAM user policy... zcodedeploy-agentz{ "Version": "2012-10-17", "Statement": [ { "Action": [ "s3:Get*", "s3:List*" ], "Effect": "Allow", "Resource": "*" } ] })r> PolicyNamePolicyDocumentz)DONE PolicyName: {0} PolicyDocument: {1} ) r.r/r0 policy_namepolicy_documentr!put_user_policyrBr1r5r8r:r:r;r*s  zRegister._create_user_policyc Csjtjdtttd}|d|j|j|j|j Wdn1s(wYtjddS)NzACreating the on-premises instance configuration file named {0}...wzT--- region: {0} iam_user_arn: {1} aws_access_key_id: {2} aws_secret_access_key: {3} DONE ) r.r/r0r1ropenr%r'rJrK)r5r8fr:r:r;r+s   zRegister._create_configcCs0tjd|jj|j|jdtjddS)Nz(Registering the on-premises instance... ) instanceName iamUserArnrS)r.r/r0rregister_on_premises_instancerAr'rQr:r:r;r,s zRegister._register_instancecCs2tjd|jj|j|jgdtjddS)Nz+Adding tags to the on-premises instance... )r instanceNamesrS)r.r/r0r!add_tags_to_on_premises_instancesrrArQr:r:r;r-s zRegister._add_tagsN)__name__ __module__ __qualname__NAME DESCRIPTION TAGS_SCHEMArr ARG_TABLEr<r(r)r*r+r,r-r:r:r:r;r sD 0 r ) r.awscli.customizations.commandsr(awscli.customizations.codedeploy.systemsr&awscli.customizations.codedeploy.utilsrrrrrr r r:r:r:r;s