Пример #1
0
        public Endpoint GetEndpoint(string region, string product)
        {
            List <Product> allProducts = GetProducts();

            ISet <String>        regionSet      = new HashSet <String>();
            List <ProductDomain> productDomains = new List <ProductDomain>();

            foreach (Product p in allProducts)
            {
                if (!string.Equals(product, p.Code, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                foreach (var e in p.RegionalEndpoints)
                {
                    if (!string.Equals(region, e.Key, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    regionSet.Add(region);

                    ProductDomain productDomain = new ProductDomain();
                    productDomain.ProductName = product;
                    productDomain.DomianName  = e.Value;
                    productDomains.Add(productDomain);
                }

                if (regionSet.Count == 0)
                {
                    if (string.IsNullOrEmpty(p.GlobalEndpoint))
                    {
                        return(null);
                    }

                    regionSet.Add(region);

                    ProductDomain productDomain = new ProductDomain();
                    productDomain.ProductName = product;
                    productDomain.DomianName  = p.GlobalEndpoint;
                    productDomains.Add(productDomain);
                }

                break;
            }

            return(new Endpoint(region, regionSet, productDomains));
        }
Пример #2
0
        public DescribeEndpointResponse DescribeEndpoint(string regionId, string serviceCode, string endpointType, Credential credential, LocationConfig locationConfig)
        {
            if (string.IsNullOrEmpty(serviceCode))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(endpointType))
            {
                endpointType = DEFAULT_ENDPOINT_TYPE;
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest
            {
                AcceptFormat    = Http.FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = serviceCode,
                SecurityToken   = credential.SecurityToken,
                EndpointType    = endpointType
            };

            Signer        signer = Signer.GetSigner(new LegacyCredentials(credential));
            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
            HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);

            if (httpResponse.isSuccess())
            {
                String data = Encoding.UTF8.GetString(httpResponse.Content);
                DescribeEndpointResponse response = GetEndpointResponse(data, endpointType);
                if (response == null || string.IsNullOrEmpty(response.Endpoint))
                {
                    return(null);
                }

                return(response);
            }
            AcsError error = ReadError(httpResponse, FormatType.JSON);

            if (500 <= httpResponse.Status)
            {
                return(null);
            }
            return(null);
        }
Пример #3
0
 public static ProductDomain FindProductDomain(String regionId, String product,
                                               List <Endpoint> endpoints)
 {
     if (null == regionId || null == product || null == endpoints)
     {
         return(null);
     }
     foreach (Endpoint endpoint in endpoints)
     {
         if (endpoint.RegionIds.Contains(regionId))
         {
             ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
             return(domain);
         }
     }
     return(null);
 }