|
| 1 | +#parse("com/amazonaws/util/awsclientgenerator/velocity/cfamily/Attribution.vm") |
| 2 | + |
| 3 | +#set($metadata = $serviceModel.metadata) |
| 4 | +#set($rootNamespace = $serviceModel.namespace) |
| 5 | +#set($serviceNamespace = $metadata.namespace) |
| 6 | +#set($endpointPrefix = $metadata.endpointPrefix) |
| 7 | +\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}Endpoint.h> |
| 8 | +\#include <aws/core/Region.h> |
| 9 | +\#include <aws/core/utils/logging/LogMacros.h> |
| 10 | +\#include <aws/core/utils/memory/stl/AWSSet.h> |
| 11 | +\#include <aws/core/utils/memory/stl/AWSStringStream.h> |
| 12 | +\#include <aws/core/utils/HashingUtils.h> |
| 13 | + |
| 14 | +using namespace Aws; |
| 15 | +using namespace ${rootNamespace}::${serviceNamespace}; |
| 16 | + |
| 17 | +namespace ${rootNamespace} |
| 18 | +{ |
| 19 | +namespace ${serviceNamespace} |
| 20 | +{ |
| 21 | +namespace ${metadata.classNamePrefix}Endpoint |
| 22 | +{ |
| 23 | +#if(!$metadata.globalEndpoint) |
| 24 | + static const int CN_NORTH_1_HASH = Aws::Utils::HashingUtils::HashString("cn-north-1"); |
| 25 | + static const int CN_NORTHWEST_1_HASH = Aws::Utils::HashingUtils::HashString("cn-northwest-1"); |
| 26 | + static const int US_ISO_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-iso-east-1"); |
| 27 | + static const int US_ISOB_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-isob-east-1"); |
| 28 | +#end |
| 29 | + |
| 30 | +#foreach($regionEndpointPair in $endpointMapping.entrySet()) |
| 31 | +#set($customizedRegion = $regionEndpointPair.key) |
| 32 | +#if ($metadata.globalEndpoint || !($customizedRegion.equals("cn-north-1") || $customizedRegion.equals("cn-northwest-1") || $customizedRegion.equals("us-iso-east-1") || $customizedRegion.equals("us-isob-east-1"))) |
| 33 | + static const int ${regionEndpointPair.key.toUpperCase().replace("-", "_")}_HASH = Aws::Utils::HashingUtils::HashString("${regionEndpointPair.key}"); |
| 34 | +#end |
| 35 | +#end |
| 36 | + // https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Using_Endpoints.html#ipv6 |
| 37 | + static const Aws::UnorderedSet<Aws::String> ${serviceModel.serviceName.toUpperCase()}_DUALSTACK_REGIONS { |
| 38 | + Aws::Region::US_EAST_1, Aws::Region::US_EAST_2, Aws::Region::US_WEST_2, Aws::Region::US_WEST_1, |
| 39 | + Aws::Region::AP_SOUTH_1, Aws::Region::SA_EAST_1}; |
| 40 | + static const char* ${serviceModel.serviceName.toUpperCase()}_ENDPOINT_TAG = "${serviceModel.serviceName.toUpperCase()}Endpoint"; |
| 41 | + |
| 42 | + Aws::String ForRegion(const Aws::String& regionName, bool useDualStack) |
| 43 | + { |
| 44 | +#if($metadata.globalEndpoint) |
| 45 | +#if($endpointMapping.isEmpty()) |
| 46 | + AWS_UNREFERENCED_PARAM(regionName); |
| 47 | + AWS_UNREFERENCED_PARAM(useDualStack); |
| 48 | + return "${metadata.globalEndpoint}"; |
| 49 | +#else |
| 50 | + auto hash = Aws::Utils::HashingUtils::HashString(regionName.c_str()); |
| 51 | + |
| 52 | + if(!useDualStack) |
| 53 | + { |
| 54 | +#foreach($regionEndpointPair in $endpointMapping.entrySet()) |
| 55 | + if(hash == ${regionEndpointPair.key.toUpperCase().replace("-", "_")}_HASH) |
| 56 | + { |
| 57 | + return "${regionEndpointPair.value}"; |
| 58 | + } |
| 59 | +#end |
| 60 | + } |
| 61 | + return "${metadata.globalEndpoint}"; |
| 62 | +#end##end if endpoint mapping |
| 63 | +#else##no global endpoint means standard endpoints calculation except for special regions |
| 64 | + // Fallback to us-east-1 if global endpoint does not exists. |
| 65 | + Aws::String region = regionName == Aws::Region::AWS_GLOBAL ? Aws::Region::US_EAST_1 : regionName; |
| 66 | + auto hash = Aws::Utils::HashingUtils::HashString(region.c_str()); |
| 67 | + |
| 68 | +#if(!$endpointMapping.isEmpty()) |
| 69 | + if(!useDualStack) |
| 70 | + { |
| 71 | +#foreach($regionEndpointPair in $endpointMapping.entrySet()) |
| 72 | + if(hash == ${regionEndpointPair.key.toUpperCase().replace("-", "_")}_HASH) |
| 73 | + { |
| 74 | + return "${regionEndpointPair.value}"; |
| 75 | + } |
| 76 | +#end |
| 77 | + } |
| 78 | +#end |
| 79 | + Aws::StringStream ss; |
| 80 | + if(useDualStack) |
| 81 | + { |
| 82 | + if ((${serviceModel.serviceName.toUpperCase()}_DUALSTACK_REGIONS.find(regionName)) == ${serviceModel.serviceName.toUpperCase()}_DUALSTACK_REGIONS.end()) |
| 83 | + { |
| 84 | + AWS_LOGSTREAM_WARN(${serviceModel.serviceName.toUpperCase()}_ENDPOINT_TAG, |
| 85 | + "${serviceModel.serviceName.toUpperCase()} service does not support dualstack endpoint in the region: " << regionName); |
| 86 | + } |
| 87 | + ss << "api."; |
| 88 | + } |
| 89 | + ss << "${endpointPrefix}." << region; |
| 90 | + |
| 91 | + if (hash == CN_NORTH_1_HASH || hash == CN_NORTHWEST_1_HASH) |
| 92 | + { |
| 93 | + ss << ".amazonaws.com.cn"; |
| 94 | + } |
| 95 | + else if (hash == US_ISO_EAST_1_HASH) |
| 96 | + { |
| 97 | + ss << ".c2s.ic.gov"; |
| 98 | + } |
| 99 | + else if (hash == US_ISOB_EAST_1_HASH) |
| 100 | + { |
| 101 | + ss << ".sc2s.sgov.gov"; |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + if(useDualStack) |
| 106 | + { |
| 107 | + ss << ".aws"; |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + ss << ".amazonaws.com"; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + return ss.str(); |
| 116 | +#end |
| 117 | + } |
| 118 | + |
| 119 | +} // namespace ${metadata.classNamePrefix}Endpoint |
| 120 | +} // namespace ${serviceNamespace} |
| 121 | +} // namespace ${rootNamespace} |
| 122 | + |
0 commit comments