예제 #1
0
        public Endpoint GetEndpoint(String regionId, String product, String serviceCode, String endpointType,
                                    Credential credential, LocationConfig locationConfig)
        {
            if (serviceCode == null)
            {
                return(null);
            }
            Endpoint endpoint = null;

            DescribeEndpointResponse response = describeEndpointService.DescribeEndpoint(regionId, serviceCode,
                                                                                         endpointType, credential, locationConfig);

            if (response == null)
            {
                return(endpoint);
            }
            ISet <String> regionIds = new HashSet <String>();

            regionIds.Add(regionId);

            List <ProductDomain> productDomainList = new List <ProductDomain>();

            productDomainList.Add(new ProductDomain(product, response.Endpoint));

            endpoint = new Endpoint(response.RegionId, regionIds, productDomainList);
            return(endpoint);
        }
예제 #2
0
        public void GetEndpointWhenResponseIsNotNull()
        {
            DescribeEndpointResponse response = new DescribeEndpointResponse();

            response.RegionId = "RegionId";
            response.Endpoint = "Endpoint";

            var mock = new Mock <DescribeEndpointService>();

            mock.Setup(foo => foo.DescribeEndpoint(
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <Credential>(),
                           It.IsAny <LocationConfig>()
                           )).Returns(response);

            DescribeEndpointService describeEndpointService = mock.Object;
            RemoteEndpointsParser   instance = new RemoteEndpointsParser();

            instance.SetDescribeEndpointService(describeEndpointService);

            Credential     credential     = new Credential();
            LocationConfig locationConfig = new LocationConfig();
            var            result         = instance.GetEndpoint("regionId", "product", "serviceCode", "endpointType", credential, locationConfig);

            Assert.IsType <Endpoint>(result);
            Assert.NotNull(result);
            Assert.Equal("RegionId", result.Name);
            Assert.NotEmpty(result.ProductDomains);
            Assert.NotEmpty(result.RegionIds);
        }
예제 #3
0
        private DescribeEndpointResponse getEndpointResponse(String data, String endpointType)
        {
            IReader             reader  = ReaderFactory.CreateInstance(FormatType.JSON);
            UnmarshallerContext context = new UnmarshallerContext();

            context.ResponseDictionary = reader.Read(data, "DescribeEndpointsResponse");

            int endpointsLength = context.Length("DescribeEndpointsResponse.Endpoints.Length");

            for (int i = 0; i < endpointsLength; i++)
            {
                if (endpointType.Equals(context
                                        .StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Type")))
                {
                    DescribeEndpointResponse response = new DescribeEndpointResponse();

                    response.RequestId = context.StringValue("DescribeEndpointsResponse.RequestId");
                    response.Product   = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].SerivceCode");
                    response.Endpoint  = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Endpoint");
                    response.RegionId  = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Id");
                    return(response);
                }
            }
            return(null);
        }
예제 #4
0
        private DescribeEndpointResponse GetEndpointResponse(string data, string endpointType)
        {
            var reader  = ReaderFactory.CreateInstance(FormatType.JSON);
            var context = new UnmarshallerContext();

            context.ResponseDictionary = reader.Read(data, "DescribeEndpoints");

            var endpointsLength = context.Length("DescribeEndpoints.Endpoints.Length");

            for (var i = 0; i < endpointsLength; i++)
            {
                if (string.Equals(endpointType, context.StringValue("DescribeEndpoints.Endpoints[" + i + "].Type"),
                                  StringComparison.InvariantCultureIgnoreCase))
                {
                    var response = new DescribeEndpointResponse();
                    response.RequestId = context.StringValue("DescribeEndpoints.RequestId");
                    response.Product   = context.StringValue("DescribeEndpoints.Endpoints[" + i + "].SerivceCode");
                    response.Endpoint  = context.StringValue("DescribeEndpoints.Endpoints[" + i + "].Endpoint");
                    response.RegionId  = context.StringValue("DescribeEndpoints.Endpoints[" + i + "].Id");
                    return(response);
                }
            }

            return(null);
        }
예제 #5
0
        public void GetEndpointWhenResponseIsNull()
        {
            DescribeEndpointResponse response = null;

            var mock = new Mock <DescribeEndpointService>();

            //String regionId, String serviceCode, String endpointType,Credential credential,LocationConfig locationConfig
            mock.Setup(foo => foo.DescribeEndpoint(
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <Credential>(),
                           It.IsAny <LocationConfig>()
                           )).Returns(response);

            DescribeEndpointService describeEndpointService = mock.Object;
            RemoteEndpointsParser   instance = new RemoteEndpointsParser();

            instance.SetDescribeEndpointService(describeEndpointService);

            Credential     credential     = new Credential();
            LocationConfig locationConfig = new LocationConfig();
            var            result         = instance.GetEndpoint("regionId", "product", "serviceCode", "endpointType", credential, locationConfig);

            Assert.Null(result);
        }
        public void GetEndpointWhenResponseIsNotNull()
        {
            var response = new DescribeEndpointResponse();

            response.RegionId = "RegionId";
            response.Endpoint = "Endpoint";

            var mock = new Mock <DescribeEndpointService>();

            mock.Setup(foo => foo.DescribeEndpoint(
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.IsAny <Credential>(),
                           It.IsAny <LocationConfig>()
                           )).Returns(response);

            var instance = new RemoteEndpointsParser();

            var credential     = new Credential();
            var locationConfig = new LocationConfig();
            var result         = instance.GetEndpoint("regionId", "product", "serviceCode", "endpointType", credential,
                                                      locationConfig);

            Assert.Null(result);
        }
        public DescribeEndpointResponse DescribeEndpoint(String regionId, String locationProduct,
                                                         Credential credential, LocationConfig locationConfig, String locationEndpointType)
        {
            if (isEmpty(locationProduct))
            {
                return(null);
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest();

            request.AcceptFormat    = FormatType.JSON;
            request.Id              = regionId;
            request.RegionId        = locationConfig.RegionId;
            request.LocationProduct = locationProduct;
            if (isEmpty(locationEndpointType))
            {
                request.EndpointType = DEFAULT_ENDPOINT_TYPE;
            }
            else
            {
                request.EndpointType = locationEndpointType;
            }


            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);
                if (httpResponse.isSuccess())
                {
                    String data = System.Text.Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = getEndpointResponse(data, request.EndpointType);
                    if (null == response || isEmpty(response.Endpoint))
                    {
                        return(null);
                    }
                    return(response);
                }
                AcsError error = readError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                      + "; Msg: " + error.ErrorMessage);
                    return(null);
                }
                Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                  + "; Msg: " + error.ErrorMessage);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }
예제 #8
0
        public async Task <DescribeEndpointResponse> DescribeEndpointAsync(String regionId, String locationProduct,
                                                                           Credential credential, LocationConfig locationConfig)
        {
            if (IsEmpty(locationProduct))
            {
                return(null);
            }

            var request = new DescribeEndpointRequest
            {
                AcceptFormat    = FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = locationProduct,
                EndpointType    = DEFAULT_ENDPOINT_TYPE
            };

            var domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                var httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                var httpResponse = await HttpResponse.GetResponseAsync(httpRequest);

                if (httpResponse.IsSuccess())
                {
                    var data = Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = GetEndpointResponse(data, DEFAULT_ENDPOINT_TYPE);
                    if (null == response || IsEmpty(response.Endpoint))
                    {
                        return(null);
                    }

                    return(response);
                }

                var error = ReadError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                      + "; Msg" + error.ErrorMessage);
                    return(null);
                }

                Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                  + "; Msg" + error.ErrorMessage);

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }
        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);
        }
        public static DescribeEndpointResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeEndpointResponse describeEndpointResponse = new DescribeEndpointResponse();

            describeEndpointResponse.RequestId = context.StringValue("DescribeEndpointResponse.RequestId");
            describeEndpointResponse.Endpoint  = context.StringValue("DescribeEndpointResponse.Endpoint");

            List <String> protocols = new List <String>();

            for (int i = 0; i < context.Length("DescribeEndpointResponse.Protocols.Length"); i++)
            {
                protocols.Add(context.StringValue("DescribeEndpointResponse.Protocols[" + i + "]"));
            }
            describeEndpointResponse.Protocols = protocols;

            return(describeEndpointResponse);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeEndpointResponse response = new DescribeEndpointResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("EndpointProperties", targetDepth))
                {
                    var unmarshaller = EndpointPropertiesUnmarshaller.Instance;
                    response.EndpointProperties = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public static DescribeEndpointResponse Unmarshall(UnmarshallerContext context)
        {
            var describeEndpointResponse = new DescribeEndpointResponse
            {
                RequestId = context.StringValue("DescribeEndpointResponse.RequestId"),
                Endpoint  = context.StringValue("DescribeEndpointResponse.Endpoint")
            };


            var protocols = new List <string>();

            for (var i = 0; i < context.Length("DescribeEndpointResponse.Protocols.Length"); i++)
            {
                protocols.Add(context.StringValue($"DescribeEndpointResponse.Protocols[{i}]"));
            }
            describeEndpointResponse.Protocols = protocols;

            return(describeEndpointResponse);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeEndpointResponse response = new DescribeEndpointResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("CreationTime", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.CreationTime = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointConfigName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointConfigName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointStatus", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointStatus = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("FailureReason", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.FailureReason = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("LastModifiedTime", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.LastModifiedTime = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ProductionVariants", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ProductionVariantSummary, ProductionVariantSummaryUnmarshaller>(ProductionVariantSummaryUnmarshaller.Instance);
                    response.ProductionVariants = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #14
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeEndpointResponse response = new DescribeEndpointResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Arn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Arn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("CreationTime", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.CreationTime = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Description", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Description = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndpointUrl", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.EndpointUrl = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EventBuses", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <EndpointEventBus, EndpointEventBusUnmarshaller>(EndpointEventBusUnmarshaller.Instance);
                    response.EventBuses = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("LastModifiedTime", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.LastModifiedTime = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Name", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Name = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ReplicationConfig", targetDepth))
                {
                    var unmarshaller = ReplicationConfigUnmarshaller.Instance;
                    response.ReplicationConfig = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("RoleArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.RoleArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("RoutingConfig", targetDepth))
                {
                    var unmarshaller = RoutingConfigUnmarshaller.Instance;
                    response.RoutingConfig = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("State", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.State = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StateReason", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.StateReason = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }