o ckF[&@sNddlmmmZGdddejZGdddeZGdddeZdS)NcseZdZdZddddddZdfd d Z dfd d ZddZdfdd ZddZ dddZ ddZ ddZ ddZ ZS) _CompatEndpointResolverzyEndpoint resolver which handles boto2 compatibility concerns. This is NOT intended for external use whatsoever. lambda monitoringemailecsconfig) awslambda cloudwatchsesec2containerservice configserviceNcs@tt|||dur|j}||_tdd|D|_dS). :type endpoint_data: dict :param endpoint_data: Regions and endpoints data in the same format as is used by botocore / boto3. :type service_rename_map: dict :param service_rename_map: A mapping of boto2 service name to endpoint prefix. Ncss|] \}}||fVqdSN).0kvrr0/usr/lib/python3/dist-packages/boto/endpoints.py 2s  z3_CompatEndpointResolver.__init__..)superr__init___DEFAULT_SERVICE_RENAMES_endpoint_prefix_mapdictitems_service_name_mapself endpoint_dataservice_rename_map __class__rrr"s z _CompatEndpointResolver.__init__awsFcs||}tt||||Sr)_endpoint_prefixrrget_available_endpoints)r service_namepartition_nameallow_non_regionalendpoint_prefixr rrr$5s  z/_CompatEndpointResolver.get_available_endpointscCsbt}||}|D] }|||r#||}||dq ||||q t|S)z6Retrieve every region across partitions for a service.regions) setr#get_available_partitions_is_global_service_get_partition_dataupdatekeysr$list)rr%r)r(r& partitionrrrget_all_available_regions;s    z1_CompatEndpointResolver.get_all_available_regionscs||}tt|||Sr)r#rrconstruct_endpoint)rr% region_namer(r rrr3Ps  z*_CompatEndpointResolver.construct_endpointcs:t}jdD] }||dqfdd|DS)zAGet a list of all the available services in the endpoints file(s) partitionsservicescsg|]}|qSr) _service_name)rsrrr \szB_CompatEndpointResolver.get_available_services..)r*_endpoint_datar.r/)rr6r1rr9rget_available_servicesUsz._CompatEndpointResolver.get_available_servicescCs,||}||}|d|i}d|vS)zDetermines whether a service uses a global endpoint. In theory a service can be 'global' in one partition but regional in another. In practice, each service is all global or all regional. r6partitionEndpoint)r#r-get)rr%r&r(r1servicerrrr,^s  z*_CompatEndpointResolver._is_global_servicecCs0|jdD] }|d|kr|Sqtd|)aGet partition information for a particular partition. This should NOT be used to get service endpoint data because it only loads from the new endpoint format. It should only be used for partition metadata and partition specific service metadata. :type partition_name: str :param partition_name: The name of the partition to search for. :returns: Partition info from the new endpoints format. :rtype: dict or None r5r1z%Could not find partition data for: %s)r; ValueError)rr&r1rrrr-is z+_CompatEndpointResolver._get_partition_datacC|j||S)z4Given a boto2 service name, get the endpoint prefix.)rr>rr%rrrr#|z(_CompatEndpointResolver._endpoint_prefixcCrA)z5Given an endpoint prefix, get the boto2 service name.)rr>)rr(rrrr7rCz%_CompatEndpointResolver._service_namer)r"F)r")__name__ __module__ __qualname____doc__rrr$r2r3r<r,r-r#r7 __classcell__rrr rrs&    rc@s2eZdZdZd ddZddZddZd d ZdS) BotoEndpointResolverz^Resolves endpoint hostnames for AWS services. This is NOT intended for external use. NcCst|||_dS)r N)r _resolverrrrrrs  zBotoEndpointResolver.__init__cCs*|j||}|dur dS|d|dS)aDResolve the hostname for a service in a particular region. :type service_name: str :param service_name: The service to look up. :type region_name: str :param region_name: The region to find the endpoint for. :return: The hostname for the given service in the given region. N sslCommonNamehostname)rJr3r>)rr%r4endpointrrrresolve_hostnames z%BotoEndpointResolver.resolve_hostnamecCs |j|S)zGet all the regions a service is available in. :type service_name: str :param service_name: The service to look up. :rtype: list of str :return: A list of all the regions the given service is available in. )rJr2rBrrrr2s z.BotoEndpointResolver.get_all_available_regionscCs |jS)zGet all the services supported by the endpoint data. :rtype: list of str :return: A list of all the services explicitly contained within the endpoint data provided during instantiation. )rJr<r9rrrr<s z+BotoEndpointResolver.get_available_servicesr)rDrErFrGrrNr2r<rrrrrIs    rIc@s2eZdZdZddZd ddZddZd d ZdS) StaticEndpointBuilderz:Builds a static mapping of endpoints in the legacy format.cCs ||_dS)ze :type resolver: BotoEndpointResolver :param resolver: An endpoint resolver. N)rJ)rresolverrrrrs zStaticEndpointBuilder.__init__NcCsD|dur |j}i}|D] }||}|r|||<q |||S)aBuild a set of static endpoints in the legacy boto2 format. :param service_names: The names of the services to build. They must use the names that boto2 uses, not boto3, e.g "ec2containerservice" and not "ecs". If no service names are provided, all available services will be built. :return: A dict consisting of:: {"service": {"region": "full.host.name"}} N)rJr<_build_endpoints_for_service_handle_special_cases)r service_namesstatic_endpointsnameendpoints_for_servicerrrbuild_static_endpointss   z,StaticEndpointBuilder.build_static_endpointscCs0i}|j|}|D] }|j||||<q |Sr)rJr2rN)rr% endpointsr)r4rrrrQs  z2StaticEndpointBuilder._build_endpoints_for_servicecCs d|vr|d}||d<dSdS)N cloudsearchcloudsearchdomainr)rrTcloudsearch_endpointsrrrrRs z+StaticEndpointBuilder._handle_special_casesr)rDrErFrGrrWrQrRrrrrrOs   rO) boto.vendored.regions.regionsvendoredr)_regionsEndpointResolverrobjectrIrOrrrrs u8