o .&a=@sHddlZddlmZddlmZddlmZmZmZGdddeZ dS)N) ClientError) BasicCommand)validate_regionvalidate_instance_nameINSTANCE_NAME_ARGc@s^eZdZdZdZedddddgZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS) Deregister deregisterzRemoves any tags from the on-premises instance; deregisters the on-premises instance from AWS CodeDeploy; and, unless requested otherwise, deletes the IAM user for the on-premises instance.zno-delete-iam-user store_trueFzMOptional. Do not delete the IAM user for the registered on-premises instance.)nameactiondefault help_textc Cs|}|j|_t||t||jjd|j|j|jd|_|jjd|jd|_ z-| ||j r5| || ||jsL||||||tjdWdStyu}ztjtjd|WYd}~dSd}~ww)N codedeploy) region_name endpoint_urlverifyiam)rznRun the following command on the on-premises instance to uninstall the codedeploy-agent: aws deploy uninstall zERROR {0} Deregister the on-premises instance by following the instructions in "Configure Existing On-Premises Instances by Using AWS CodeDeploy" in the AWS CodeDeploy User Guide. )_sessionsessionrr create_clientregionr verify_sslrr_get_instance_infotags _remove_tags_deregister_instanceno_delete_iam_user_delete_user_policy_delete_access_key_delete_iam_usersysstdoutwrite Exceptionflushstderrformat)self parsed_argsparsed_globalsparamser,M/usr/lib/python3/dist-packages/awscli/customizations/codedeploy/deregister.py _run_main-sD         zDeregister._run_maincCstjd|jj|jd}|dd|_|jdd}|j|d|_|dd|_ tjd |j|j r[tjd |j D]}tjd |d |d qBtjd dSdS)Nz/Retrieving on-premises instance information...  instanceName instanceInfo iamUserArn/rzDONE IamUserArn: {0} zTags:z Key={0},Value={1}KeyValue ) r r!r"rget_on_premises_instance instance_name iam_user_arnrfind user_namerr&)r'r*responsestarttagr,r,r-rWs,   zDeregister._get_instance_infocCs2tjd|jj|j|jgdtjddS)Nz/Removing tags from the on-premises instance... )r instanceNamesDONE )r r!r"r&remove_tags_from_on_premises_instancesrr9r'r*r,r,r-rns zDeregister._remove_tagscCs,tjd|jj|jdtjddS)Nz*Deregistering the on-premises instance... r/rA)r r!r"rderegister_on_premises_instancer9rCr,r,r-rvs zDeregister._deregister_instancec Cstjd|jd}z|j|jdD]}|dD] }|jj|j|dqqWn tyH}z|j di ddkr>|WYd}~nd}~wwtjd dS) Nz"Deleting the IAM user policies... list_user_policiesUserName PolicyNames)rG PolicyNameErrorCode NoSuchEntityrA) r r!r"r get_paginatorpaginater<delete_user_policyrr=get)r'r*rEr= policy_namer+r,r,r-r}s(    zDeregister._delete_user_policyc Cstjd|jd}z|j|jdD]}|dD] }|jj|j|ddqqWn tyJ}z|j di dd kr@|WYd}~nd}~wwtjd dS) Nz%Deleting the IAM user access keys... list_access_keysrFAccessKeyMetadata AccessKeyId)rGrTrJrKrLrA) r r!r"rrMrNr<delete_access_keyrr=rP)r'r*rRr= access_keyr+r,r,r-rs(    zDeregister._delete_access_keyc Csztjd|jz |jj|jdWn ty4}z|j di ddkr*|WYd}~nd}~wwtjddS)NzDeleting the IAM user ({0})... rFrJrKrLrA) r r!r"r&r<r delete_userrr=rP)r'r*r+r,r,r-rs  zDeregister._delete_iam_userN)__name__ __module__ __qualname__NAME DESCRIPTIONr ARG_TABLEr.rrrrrrr,r,r,r-rs$ * r) r botocore.exceptionsrawscli.customizations.commandsr&awscli.customizations.codedeploy.utilsrrrrr,r,r,r-s