示例#1
0
        public RegionEndpoint.Endpoint GetEndpointForService(string serviceName, bool dualStack)
        {
            RegionEndpoint.Endpoint endpointObject = null;

            lock (_serviceMap)
            {
                if (!_servicesLoaded)
                {
                    ParseAllServices();
                    _servicesLoaded = true;
                }

                if (!_serviceMap.TryGetEndpoint(serviceName, dualStack, out endpointObject))
                {
                    // Do a fallback of creating an unknown endpoint based on the
                    // current region's hostname template.
                    endpointObject = CreateUnknownEndpoint(serviceName, dualStack);
                }
            }
            return(endpointObject);
        }
示例#2
0
        private void AddNormalEndpointToServiceMap(JsonData mergedEndpoint, string regionName, string serviceName)
        {
            string template = (string)mergedEndpoint["hostname"];
            string hostname = template.Replace("{service}", serviceName)
                              .Replace("{region}", regionName)
                              .Replace("{dnsSuffix}", (string)_partitionJsonData["dnsSuffix"]);


            string   authRegion      = null;
            JsonData credentialScope = mergedEndpoint["credentialScope"];

            if (credentialScope != null)
            {
                authRegion = DetermineAuthRegion(credentialScope);
            }

            JsonData deprecatedJson = mergedEndpoint["deprecated"];
            var      deprecated     = deprecatedJson?.IsBoolean == true ? (bool)deprecatedJson : false;

            var signatureOverride = DetermineSignatureOverride(mergedEndpoint, serviceName);

            RegionEndpoint.Endpoint endpoint = new RegionEndpoint.Endpoint(hostname, authRegion, signatureOverride, deprecated);
            _serviceMap.Add(serviceName, endpoint);
        }
        private void CreateEndpointAndAddToServiceMap(JsonData result, string regionName, string serviceName, bool dualStack)
        {
            string template = (string)result["hostname"];
            string hostname = template.Replace("{service}", serviceName)
                                 .Replace("{region}", regionName)
                                 .Replace("{dnsSuffix}", (string)_partitionJsonData["dnsSuffix"]);

            if (dualStack)
            {
                // We need special handling for S3's s3.amazonaws.com endpoint, which doesn't
                // support dualstack (need to transform to s3.dualstack.us-east-1.amazonaws.com).
                // Other endpoints that begin s3-* need to transform to s3.* for dualstack support.
                // S3's 'external' endpoints do not support dualstack and should not be transformed.
                if (serviceName.Equals("s3", StringComparison.OrdinalIgnoreCase))
                {
                    if (hostname.Equals("s3.amazonaws.com", StringComparison.OrdinalIgnoreCase))
                    {
                        hostname = "s3.dualstack.us-east-1.amazonaws.com";
                    }
                    else
                    {
                        var isExternalEndpoint = hostname.StartsWith("s3-external-", StringComparison.OrdinalIgnoreCase);
                        if (!isExternalEndpoint)
                        {
                            // transform fixed s3-<region> to s3.<region> and then onto s3.dualstack.<region>,
                            // bypassing endpoints that do not start with the expected tags.
                            if (hostname.StartsWith("s3-", StringComparison.OrdinalIgnoreCase))
                                hostname = "s3." + hostname.Substring(3);

                            if (hostname.StartsWith("s3.", StringComparison.OrdinalIgnoreCase))
                                hostname = hostname.Replace("s3.", "s3.dualstack.");
                        }
                    }
                }
                else
                {
                    // For certain region and endpoint combination, we actually get an explicit endpoint as "hostname" property
                    // (e.g. sts.ap-northeast-2.amazon.com). We can't assume that the template variable will be {service}.{region}.{dnsSuffix},
                    // so just construct a brand new endpoint.
                    hostname = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}", serviceName,
                                                            "dualstack." + regionName,
                                                            (string)_partitionJsonData["dnsSuffix"]);
                }
            }

            string authRegion = null;
            string customService = null;
            JsonData credentialScope = result["credentialScope"];
            if (credentialScope != null)
            {
                authRegion = DetermineAuthRegion(credentialScope);
                // This is a workaround until we overhaul how the SDK consumes the v3 endpoint structure
                // and customize the signing based on the metadata in the endpoint structure.
                // There are points in SDK where we retrieve endpoints via service name such as "execute-api".
                // Since we are building a cache, just add the custom service entry.
                if (credentialScope["service"] != null && string.Compare((string)credentialScope["service"], serviceName, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    customService = (string)credentialScope["service"];
                }
            }

            string signatureOverride = DetermineSignatureOverride(result, serviceName);

            RegionEndpoint.Endpoint endpoint = new RegionEndpoint.Endpoint(hostname, authRegion, signatureOverride);

            _serviceMap.Add(serviceName, dualStack, endpoint);
            if (!string.IsNullOrEmpty(customService) && !_serviceMap.ContainsKey(customService))
            {
                _serviceMap.Add(customService, dualStack, endpoint);
            }
        }
示例#4
0
 public bool TryGetEndpoint(string serviceName, HashSet <string> variants, out RegionEndpoint.Endpoint endpoint)
 {
     if (variants == null || variants.Count == 0)
     {
         return(_serviceMap.TryGetValue(serviceName, out endpoint));
     }
     else
     {
         if (!_variantMap.ContainsKey(serviceName))
         {
             endpoint = default(RegionEndpoint.Endpoint);
             return(false);
         }
         else
         {
             return(_variantMap[serviceName].TryGetValue(variants, out endpoint));
         }
     }
 }
示例#5
0
 public bool TryGetEndpoint(string serviceName, bool dualStack, out RegionEndpoint.Endpoint endpoint)
 {
     return(this.GetMap(dualStack).TryGetValue(serviceName, out endpoint));
 }
示例#6
0
            public void Add(string serviceName, bool dualStack, RegionEndpoint.Endpoint endpoint)
            {
                var map = dualStack ? _dualServiceMap : _serviceMap;

                GetMap(dualStack).Add(serviceName, endpoint);
            }
示例#7
0
        private void CreateEndpointAndAddToServiceMap(JsonData result, string regionName, string serviceName, bool dualStack)
        {
            string template = (string)result["hostname"];
            string hostname = template.Replace("{service}", serviceName)
                              .Replace("{region}", regionName)
                              .Replace("{dnsSuffix}", (string)_partitionJsonData["dnsSuffix"]);

            if (dualStack)
            {
                // We need special handling for S3's s3.amazonaws.com endpoint, which doesn't
                // support dualstack (need to transform to s3.dualstack.us-east-1.amazonaws.com).
                // Other endpoints that begin s3-* need to transform to s3.* for dualstack support.
                // S3's 'external' endpoints do not support dualstack and should not be transformed.
                if (serviceName.Equals("s3", StringComparison.OrdinalIgnoreCase))
                {
                    if (hostname.Equals("s3.amazonaws.com", StringComparison.OrdinalIgnoreCase))
                    {
                        hostname = "s3.dualstack.us-east-1.amazonaws.com";
                    }
                    else
                    {
                        var isExternalEndpoint = hostname.StartsWith("s3-external-", StringComparison.OrdinalIgnoreCase);
                        if (!isExternalEndpoint)
                        {
                            // transform fixed s3-<region> to s3.<region> and then onto s3.dualstack.<region>,
                            // bypassing endpoints that do not start with the expected tags.
                            if (hostname.StartsWith("s3-", StringComparison.OrdinalIgnoreCase))
                            {
                                hostname = "s3." + hostname.Substring(3);
                            }

                            if (hostname.StartsWith("s3.", StringComparison.OrdinalIgnoreCase))
                            {
                                hostname = hostname.Replace("s3.", "s3.dualstack.");
                            }
                        }
                    }
                }
                else if (serviceName.Equals("s3-control", StringComparison.OrdinalIgnoreCase))
                {
                    // transform s3-control.<region>.amazonaws.com or s3-control-fips.<region>.amazonaws.com into
                    // s3-control.dualstack.<region>.amazonaws.com and s3-control-fips.dualstack.<region>.amazonaws.com
                    if (hostname.StartsWith("s3-control", StringComparison.OrdinalIgnoreCase))
                    {
                        int firstDot = hostname.IndexOf('.');
                        if (firstDot >= 0)
                        {
                            hostname = hostname.Substring(0, firstDot) + ".dualstack." + hostname.Substring(firstDot + 1);
                        }
                    }
                }
                else
                {
                    // For certain region and endpoint combination, we actually get an explicit endpoint as "hostname" property
                    // (e.g. sts.ap-northeast-2.amazon.com). We can't assume that the template variable will be {service}.{region}.{dnsSuffix},
                    // so just construct a brand new endpoint.
                    hostname = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}", serviceName,
                                             "dualstack." + regionName,
                                             (string)_partitionJsonData["dnsSuffix"]);
                }
            }

            string   authRegion      = null;
            string   customService   = null;
            JsonData credentialScope = result["credentialScope"];

            if (credentialScope != null)
            {
                authRegion = DetermineAuthRegion(credentialScope);
                // This is a workaround until we overhaul how the SDK consumes the v3 endpoint structure
                // and customize the signing based on the metadata in the endpoint structure.
                // There are points in SDK where we retrieve endpoints via service name such as "execute-api".
                // Since we are building a cache, just add the custom service entry.
                if (credentialScope["service"] != null && string.Compare((string)credentialScope["service"], serviceName, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    customService = (string)credentialScope["service"];
                }
            }

            string signatureOverride = DetermineSignatureOverride(result, serviceName);

            RegionEndpoint.Endpoint endpoint = new RegionEndpoint.Endpoint(hostname, authRegion, signatureOverride);

            _serviceMap.Add(serviceName, dualStack, endpoint);
            if (!string.IsNullOrEmpty(customService) && !_serviceMap.ContainsKey(customService))
            {
                _serviceMap.Add(customService, dualStack, endpoint);
            }
        }
示例#8
0
 internal static string GetUrl(RegionEndpoint regionEndpoint, string regionEndpointServiceName, bool useHttp, bool useDualStack)
 {
     RegionEndpoint.Endpoint endpointForService = regionEndpoint.GetEndpointForService(regionEndpointServiceName, useDualStack);
     return(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}", useHttp ? "http://" : "https://", endpointForService.Hostname)).AbsoluteUri);
 }