1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/managedblockchain/ManagedBlockchainEndpoint.h>
7 #include <aws/core/utils/memory/stl/AWSStringStream.h>
8 #include <aws/core/utils/HashingUtils.h>
9 
10 using namespace Aws;
11 using namespace Aws::ManagedBlockchain;
12 
13 namespace Aws
14 {
15 namespace ManagedBlockchain
16 {
17 namespace ManagedBlockchainEndpoint
18 {
19   static const int CN_NORTH_1_HASH = Aws::Utils::HashingUtils::HashString("cn-north-1");
20   static const int CN_NORTHWEST_1_HASH = Aws::Utils::HashingUtils::HashString("cn-northwest-1");
21   static const int US_ISO_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-iso-east-1");
22   static const int US_ISOB_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-isob-east-1");
23 
24 
ForRegion(const Aws::String & regionName,bool useDualStack)25   Aws::String ForRegion(const Aws::String& regionName, bool useDualStack)
26   {
27     // Fallback to us-east-1 if global endpoint does not exists.
28     Aws::String region = regionName == Aws::Region::AWS_GLOBAL ? Aws::Region::US_EAST_1 : regionName;
29     auto hash = Aws::Utils::HashingUtils::HashString(region.c_str());
30 
31     Aws::StringStream ss;
32     ss << "managedblockchain" << ".";
33 
34     if(useDualStack)
35     {
36       ss << "dualstack.";
37     }
38 
39     ss << region;
40 
41     if (hash == CN_NORTH_1_HASH || hash == CN_NORTHWEST_1_HASH)
42     {
43       ss << ".amazonaws.com.cn";
44     }
45     else if (hash == US_ISO_EAST_1_HASH)
46     {
47       ss << ".c2s.ic.gov";
48     }
49     else if (hash == US_ISOB_EAST_1_HASH)
50     {
51       ss << ".sc2s.sgov.gov";
52     }
53     else
54     {
55       ss << ".amazonaws.com";
56     }
57 
58     return ss.str();
59   }
60 
61 } // namespace ManagedBlockchainEndpoint
62 } // namespace ManagedBlockchain
63 } // namespace Aws
64 
65