o .&aT@sddlZddlZddlmZddlmZddlmZddddZd dd dZ d dd dZ d dZ ddZ GdddeZ GdddeZGdddeZdS)N) BasicCommand)s3_bucket_exists)find_bucket_keyz s3-bucketTzThe S3 bucket that the AWS Config delivery channel will use. If the bucket does not exist, it will be automatically created. The value for this argument should follow the form bucket/prefix. Note that the prefix is optional.)namerequired help_textz sns-topiczThe SNS topic that the AWS Config delivery channel will use. If the SNS topic does not exist, it will be automatically created. Value for this should be a valid SNS topic name or the ARN of an existing SNS topic.ziam-rolezThe IAM role that the AWS Config configuration recorder will use to record current resource configurations. Value for this should be the ARN of the desired IAM role.cCs|dtdS)Nz$building-command-table.configservice)register add_subscribe)clir O/usr/lib/python3/dist-packages/awscli/customizations/configservice/subscribe.pyregister_subscribe*r cKst||d<dS)N subscribe)SubscribeCommand) command_tablesessionkwargsr r r r .rr cs>eZdZdZdZeeegZfddZ ddZ ddZ Z S) rrzSubcribes user to AWS Config by creating an AWS Config delivery channel and configuration recorder to track AWS resource configurations. The names of the default channel and configuration recorder will be default.cs&d|_d|_d|_tt||dSN) _s3_client _sns_client_config_clientsuperr__init__)selfr __class__r r r:szSubscribeCommand.__init__c Cs||t|j}||j\}}t|j}||j}d}|j j ||j dd|||d} |r6|| d<|j j | d|j j |dtjdtjd |j } tjtj| d d d tjd tjd|j } tjtj| dd d tjddS)Ndefault)rroleARN)ConfigurationRecorder)r s3BucketName snsTopicARN s3KeyPrefix)DeliveryChannel)ConfigurationRecorderNamezSubscribe succeeded: zConfiguration Recorders: ConfigurationRecorders)indentz zDelivery Channels: DeliveryChannels r)_setup_clientsS3BucketHelperrprepare_bucket s3_bucketSNSTopicHelperr prepare_topic sns_topicrput_configuration_recorderiam_roleput_delivery_channelstart_configuration_recordersysstdoutwrite describe_configuration_recordersjsondumpsdescribe_delivery_channels) r parsed_argsparsed_globalss3_bucket_helperbucketprefixsns_topic_helper sns_topic_arnrdelivery_channelresponser r r _run_main@sF            zSubscribeCommand._run_maincCsX|j|jd}|jjdi||_|jjdi||_|j|d<|jjdi||_dS) N)verify region_names3sns endpoint_urlconfig)rH)rI)rK) verify_sslregion_session create_clientrrrJr)rr= client_argsr r r r*xs   zSubscribeCommand._setup_clients) __name__ __module__ __qualname__NAME DESCRIPTION S3_BUCKET SNS_TOPICIAM_ROLE ARG_TABLErrEr* __classcell__r r rr r2s  8rc@s,eZdZddZddZddZddZd S) r+cC ||_dSr)r)r s3_clientr r r r zS3BucketHelper.__init__cCsTt|\}}||}|s||tjd|||fStjd|||fS)NzUsing new S3 bucket: %s zUsing existing S3 bucket: %s )r_check_bucket_exists_create_bucketr5r6r7)rs3_pathr?key bucket_existsr r r r,s   zS3BucketHelper.prepare_bucketcCs t|j|Sr)rr)rr?r r r r^s z#S3BucketHelper._check_bucket_existscCs@|jjj}d|i}d|i}|dkr||d<|jjdi|dS)NBucketLocationConstraintz us-east-1CreateBucketConfigurationr )rmetarG create_bucket)rr?rGparams bucket_configr r r r_s zS3BucketHelper._create_bucketN)rQrRrSrr,r^r_r r r r r+s  r+c@s$eZdZddZddZddZdS)r.cCr[r)r)r sns_clientr r r rr]zSNSTopicHelper.__init__cCsL|}||s|jj|d}|d}tjd||Stjd||S)N)NameTopicArnzUsing new SNS topic: %s zUsing existing SNS topic: %s ) _check_is_arnr create_topicr5r6r7)rr0rBrDr r r r/s zSNSTopicHelper.prepare_topiccCsd|vS)N:r )rr0r r r rmszSNSTopicHelper._check_is_arnN)rQrRrSrr/rmr r r r r.s r.)r9r5awscli.customizations.commandsrawscli.customizations.utilsrawscli.customizations.s3.utilsrrVrWrXr r robjectr+r.r r r r s&    S