B \ @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 N)NotImplementedError)self service_name region_namer 4/tmp/pip-build-uw_ogi45/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"]). N)r)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"]). N)r)rrpartition_nameallow_non_regionalr r r get_available_endpointsCsz,BaseEndpointResolver.get_available_endpoints)N)r F)__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}x |jdD]}||dqW|S)Nr partition)rappend)rresultrr r r r bsz)EndpointResolver.get_available_partitionsr FcCslg}xb|jdD]T}|d|kr"q|d}||kr4qx.||dD]}|sV||dkrB||qBWqW|S)Nrrservicesrregions)rr)rrrrrrr endpoint_namer r r rhs z(EndpointResolver.get_available_endpointsNcCs.x(|jdD]}||||}|r |Sq WdS)Nr)r_endpoint_for_partition)rrrrrr r r r vs  z#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 ~s*        z(EndpointResolver._endpoint_for_partitioncCs0||dkrdSd|kr,t|d|SdS)NrTZ regionRegexF)recompilematch)rrrr 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'rrr,r r r r#s     zEndpointResolver._resolvecCs&x |D]}||kr||||<qWdS)Nr )rZ from_datarkeyr r r r.s zEndpointResolver._merge_keyscCs|j|||ddS)Nr-)ZserviceZregionr-)format)rrtemplaterrr r r r0sz!EndpointResolver._expand_template)r F)N) rrrrrr rr r r$r#r.r0r r r r rXs r) rloggingr(Zbotocore.exceptionsr getLoggerrr%r/r"objectrrr r r r s  ;