U C^ @sZdZddlZddlZddlmZeeZdZdiiZ Gddde Z Gdd d e Z dS) zResolves regions and endpoints. This module implements endpoint resolution, including resolving endpoints for a given service and region and resolving the available endpoints for a service in a specific AWS partition. N) NoRegionErrorz{service}.{region}.{dnsSuffix} endpointsc@s,eZdZdZd ddZddZd d d ZdS) BaseEndpointResolverz3Resolves regions and endpoints. Must be subclassed.NcCstdS)a7Resolves an endpoint for a service and region combination. :type service_name: string :param service_name: Name of the service to resolve an endpoint for (e.g., s3) :type region_name: string :param region_name: Region/endpoint name to resolve (e.g., us-east-1) if no region is provided, the first found partition-wide endpoint will be used if available. :rtype: dict :return: Returns a dict containing the following keys: - partition: (string, required) Resolved partition name - endpointName: (string, required) Resolved endpoint name - hostname: (string, required) Hostname to use for this endpoint - sslCommonName: (string) sslCommonName to use for this endpoint. - credentialScope: (dict) Signature version 4 credential scope - region: (string) region name override when signing. - service: (string) service name override when signing. - signatureVersions: (list) A list of possible signature versions, including s3, v4, v2, and s3v4 - protocols: (list) A list of supported protocols (e.g., http, https) - ...: Other keys may be included as well based on the metadata NNotImplementedError)self service_name region_namer 6/tmp/pip-install-6_kvzl1k/botocore/botocore/regions.pyconstruct_endpointsz'BaseEndpointResolver.construct_endpointcCstdS)zLists the partitions available to the endpoint resolver. :return: Returns a list of partition names (e.g., ["aws", "aws-cn"]). Nr)rr r r get_available_partitions<sz-BaseEndpointResolver.get_available_partitionsawsFcCstdS)aLists the endpoint names of a particular partition. :type service_name: string :param service_name: Name of a service to list endpoint for (e.g., s3) :type partition_name: string :param partition_name: Name of the partition to limit endpoints to. (e.g., aws for the public AWS endpoints, aws-cn for AWS China endpoints, aws-us-gov for AWS GovCloud (US) Endpoints, etc. :type allow_non_regional: bool :param allow_non_regional: Set to True to include endpoints that are not regional endpoints (e.g., s3-external-1, fips-us-gov-west-1, etc). :return: Returns a list of endpoint names (e.g., ["us-east-1"]). Nr)rrpartition_nameallow_non_regionalr r r get_available_endpointsCsz,BaseEndpointResolver.get_available_endpoints)N)rF)__name__ __module__ __qualname____doc__r r rr r r r rs  rc@s\eZdZdZddZddZddd Zdd d Zd dZddZ ddZ ddZ ddZ d S)EndpointResolverz7Resolves endpoints based on partition endpoint metadatacCsd|krtd||_dS)zA :param endpoint_data: A dict of partition data. partitionsz%Missing "partitions" in endpoint dataN) ValueError_endpoint_data)rZ endpoint_datar r r __init__ZszEndpointResolver.__init__cCs&g}|jdD]}||dq|S)Nr partitionrappend)rresultrr r r r bsz)EndpointResolver.get_available_partitionsrFcCsdg}|jdD]P}|d|kr q|d}||kr2q||dD]}|sR||dkr>||q>q|S)Nrrservicesrregionsr)rrrrrrr endpoint_namer r r rhs z(EndpointResolver.get_available_endpointsNcCs.|jdD]}||||}|r |Sq dS)Nr)r_endpoint_for_partition)rrr rrr r r r vsz#EndpointResolver.construct_endpointcCs|d|t}|dkr0d|kr*|d}nt||dkrL|||||S|||r|d}|dd}|r|std||||||||Std|||||||SdS)NrZpartitionEndpointrZisRegionalizedTz'Using partition endpoint for %s, %s: %sz*Creating a regex based endpoint for %s, %s)getDEFAULT_SERVICE_DATAr_resolve _region_matchLOGdebug)rrrr service_dataZpartition_endpointZis_regionalizedr r r r"~sP     z(EndpointResolver._endpoint_for_partitioncCs0||dkrdSd|kr,t|d|SdS)Nr TZ regionRegexF)recompilematch)rrr r r r r&s  zEndpointResolver._region_matchcCs|d|i}|d|d<||d<||di|||di||dt}|||d|||d<d|kr|||d|||d<|d|d<|S)NrrZ endpointNamedefaultshostnameZ sslCommonName dnsSuffix)r# _merge_keysDEFAULT_URI_TEMPLATE_expand_template)rrrr)r!rr.r r r r%s*   zEndpointResolver._resolvecCs"|D]}||kr||||<qdS)Nr )rZ from_datarkeyr r r r0szEndpointResolver._merge_keyscCs|j|||ddS)Nr/)ZserviceZregionr/)format)rrtemplaterr!r r r r2s z!EndpointResolver._expand_template)rF)N) rrrrrr rr r"r&r%r0r2r r r r rXs  r) rloggingr*Zbotocore.exceptionsr getLoggerrr'r1r$objectrrr r r r  s  ;