a 97a#@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 k/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/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@sfeZdZdZddZddZddd Zd d Zdd dZdddZ ddZ ddZ ddZ ddZ d S)EndpointResolverz7Resolves endpoints based on partition endpoint metadatacCsd|vrtd||_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}||vr2q||dD]}|sR||dvr>||q>q|S)Nrrservicesrregionsr)rrrrrrr endpoint_namer r r rhs z(EndpointResolver.get_available_endpointscCs,|jdD]}|d|kr |dSq dS)Nrr dnsSuffix)r)rrrr r r get_partition_dns_suffixvs z)EndpointResolver.get_partition_dns_suffixNcCsz|durLd}|jdD]}|d|kr|}q|durH||||d}|SdS|jdD]}||||}|rV|SqVdS)NrrT)r_endpoint_for_partition)rrr rZvalid_partitionrrr r r r |s" z#EndpointResolver.construct_endpointcCs|d|t}|dur0d|vr*|d}nt||dvrL|||||S|||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 Zforce_partition service_dataZpartition_endpointZis_regionalizedr r r r$s6    z(EndpointResolver._endpoint_for_partitioncCs0||dvrdSd|vr,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|vr|||d|||d<|d|d<|S)NrrZ endpointNamedefaultshostnameZ sslCommonNamer")r% _merge_keysDEFAULT_URI_TEMPLATE_expand_template)rrrr+r!rr0r r r r's      zEndpointResolver._resolvecCs"|D]}||vr||||<qdS)Nr )rZ from_datarkeyr r r r1szEndpointResolver._merge_keyscCs|j|||ddS)Nr")ZserviceZregionr")format)rrtemplaterr!r r r r3sz!EndpointResolver._expand_template)rF)NN)F)rrrrrr rr#r r$r(r'r1r3r r r r rXs   r) rloggingr,Zbotocore.exceptionsr getLoggerrr)r2r&objectrrr r r r  s  ;