o ckF[ @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@s0eZdZdZd ddZddZ  d d d ZdS) BaseEndpointResolverz3Resolves regions and endpoints. Must be subclassed.NcCt)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 NotImplementedError)self service_name region_namer ?/usr/lib/python3/dist-packages/boto/vendored/regions/regions.pyconstruct_endpointsz'BaseEndpointResolver.construct_endpointcCr)zLists the partitions available to the endpoint resolver. :return: Returns a list of partition names (e.g., ["aws", "aws-cn"]). r)rr r r get_available_partitions<sz-BaseEndpointResolver.get_available_partitionsawsFcCr)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"]). r)rr partition_nameallow_non_regionalr r r get_available_endpointsCsz,BaseEndpointResolver.get_available_endpointsNrF)__name__ __module__ __qualname____doc__r rrr r r r rs rc@s`eZdZdZddZddZ  ddd Zdd d Zd dZddZ 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)r endpoint_datar r r __init__Zs zEndpointResolver.__init__cCs&g}|jdD] }||dq|S)Nr partitionrappend)rresultrr r r rbsz)EndpointResolver.get_available_partitionsrFcCsdg}|jdD](}|d|krq|d}||vrq||dD]}|s)||dvr.||qq|S)Nrrservicesrregionsr )rr rrr"rr# endpoint_namer r r rhs  z(EndpointResolver.get_available_endpointsNcCs.|jdD]}||||}|r|SqdS)Nr)r_endpoint_for_partition)rr r rr"r r r r vsz#EndpointResolver.construct_endpointcCs|d|t}|durd|vr|d}nt||dvr&|||||S|||rZ|d}|dd}|rK|sKtd||||||||Std|||||||SdS)Nr#partitionEndpointrisRegionalizedTz'Using partition endpoint for %s, %s: %sz*Creating a regex based endpoint for %s, %s)getDEFAULT_SERVICE_DATAr_resolve _region_matchLOGdebug)rrr r service_datapartition_endpointis_regionalizedr r r r&~s8     z(EndpointResolver._endpoint_for_partitioncCs0||dvrdSd|vrt|d|SdS)Nr$T regionRegexF)recompilematch)rrr r r r r,s zEndpointResolver._region_matchcCs|d|i}|d|d<||d<||di|||di||dt}|||d|||d<d|vrH|||d|||d<|d|d<|S)Nrr endpointNamedefaultshostname sslCommonName dnsSuffix)r) _merge_keysDEFAULT_URI_TEMPLATE_expand_template)rrr r/r%r"r8r r r r+s      zEndpointResolver._resolvecCs"|D] }||vr||||<qdSrr )r from_datar"keyr r r r;s  zEndpointResolver._merge_keyscCs|j|||ddS)Nr:)serviceregionr:)format)rrtemplater r%r r r r=sz!EndpointResolver._expand_templaterr) rrrrrrrr r&r,r+r;r=r r r r rXs  r) rloggingr3 boto.vendored.regions.exceptionsr getLoggerrr-r<r*objectrrr r r r s   ;