o .&a6 @ sL d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z d dlm Z d dlmZ d dlm Z d dlmZ d d lmZ d d lmZ d dlmZ d dlmZ d d lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ e eZdd Z dd Z!d!ddZ"dd Z#dd Z$G dd d e Z%dS )" N) xform_name)get_policy_arn_suffix)configutils)emrutils) exceptions)Command)EC2) EC2_ROLE_NAME)ROLE_ARN_PATTERN)EMR) EMR_ROLE_NAME)EMR_AUTOSCALING_ROLE_NAME)APPLICATION_AUTOSCALING)EC2_ROLE_POLICY_NAME)EMR_ROLE_POLICY_NAME) EMR_AUTOSCALING_ROLE_POLICY_NAME)EMR_AUTOSCALING_SERVICE_NAME)!EMR_AUTOSCALING_SERVICE_PRINCIPAL)ResolveServicePrincipalErrorc C s dddd| iddgdS )Nz 2008-10-17 AllowServicezsts:AssumeRole)SidEffect PrincipalAction)Version Statement )serviceprincipalr r N/usr/lib/python3/dist-packages/awscli/customizations/emr/createdefaultroles.pyassume_role_policy- s r! c C s$ t | }td|}|d|}|S )Nz{{region_suffix}}z{{policy_name}})r r replace)regionpolicy_name region_suffixrole_arnr r r get_role_policy_arn; s r' c C sF t |\}}|d u rtj }| tkr||ddvrtS | d | S )Nemrzaws-cn.))_get_suffix_and_region_from_endpoint_hostbotocoresessionSessionr get_available_regionsr )service endpoint_hostr, suffixr# r r r get_service_principalB s r2 c C s: t | }|d ur|jdkr|d}|d}||fS t)N )#_get_regex_match_from_endpoint_host lastindexgroupr )r0 suffix_matchr1 r# r r r r* N s r* c C s0 | d u rd S t d| }|d u rt d| }|S )Nz+(https?://)([^.]+).elasticmapreduce.([^/]*)z+(https?://elasticmapreduce).([^.]+).([^/]*))rematch)r0 regex_matchr r r r5 Z s r5 c @ s e Zd ZdZde d e d ZddddgZd d Zdd Z d d Z dd Zdd Zdd Z dd Zdd Zdd Zdd Zdd ZdS ) CreateDefaultRoleszcreate-default-roleszCreates the default IAM role z and a which can be used when creating the cluster using the create-cluster command. The default roles for EMR use managed policies, which are updated automatically to support future EMR functionality. If you do not have a Service Role and Instance Profile variable set for your create-cluster command in the AWS CLI config file, create-default-roles will automatically set the values for these variables with these default roles. If you have already set a value for Service Role or Instance Profile, create-default-roles will not automatically set the defaults for these variables in the AWS CLI config file. You can view settings for variables in the config file using the "aws configure get" command. ziam-endpointTz
The IAM endpoint to call for creating the roles. This is optional and should only be specified when a custom endpoint should be called for IAM operations.
)nameno_paramfile help_textc C s |j | _| | j| j | jjd| j|j|jdjj| _ t d| j | |t ttg\}}t }| ||rAt d| d nt d| d | | ||| | |tttg\}}| |ttttg\}} t| j t| jd| |||||| | dS ) Nr( region_nameendpoint_urlverifyz@elasticmapreduce endpoint used for resolving service principal: zInstance Profile exists.z2does not exist. Creating default Instance Profile create_roler )iam_endpointiam_endpoint_url_check_for_iam_endpointr# _session create_clientrB verify_sslmetaemr_endpoint_urlLOGdebug_create_role_if_not_existsr r r check_if_instance_profile_exists"_create_instance_profile_with_roler r r r r r r update_rolesr display_response_construct_result) selfparsed_argsparsed_globals ec2_result ec2_policyinstance_profile_name emr_result emr_policyemr_autoscaling_resultemr_autoscaling_policyr r r _run_main_command s` z$CreateDefaultRoles._run_main_commandc C st d }d }| ||rtd| d ||fS td| d | t| j|}| ||||}| ||}||fS )NzRole rD z( does not exist. Creating default role: )check_if_role_existsrN rO r' r# _create_role_with_role_policy_get_role_policy)rV rX role_namer$ service_namesresultpolicyr&