Inheritance: IConfigureThisEndpoint
Example #1
0
        private static X509Certificate2 LoadCertificate(EndpointConfig config, IHostingEnvironment environment)
        {
            if (config.StoreName != null && config.StoreLocation != null)
            {
                using (var store = new X509Store(config.StoreName, Enum.Parse <StoreLocation>(config.StoreLocation)))
                {
                    store.Open(OpenFlags.ReadOnly);
                    var certificate = store.Certificates.Find(
                        X509FindType.FindBySubjectName,
                        config.CrtSubject,
                        validOnly: !environment.IsDevelopment());

                    if (certificate.Count == 0)
                    {
                        throw new InvalidOperationException($"Certificate not found for {config.Host}.");
                    }

                    return(certificate[0]);
                }
            }

            if (config.FilePath != null && config.Password != null)
            {
                var fullPath = CommonHelper.MapPath(config.FilePath);
                return(new X509Certificate2(fullPath, config.Password));
            }

            throw new InvalidOperationException("No valid certificate configuration found for the current endpoint.");
        }
        public void EmptyEndpointConfigurationNameRegistrationShouldThrowsAnArgumentException()
        {
            Endpoint       endpoint = new Endpoint("");
            EndpointConfig ec       = new EndpointConfig("");

            endpoint.SetConfiguration("", ec);             //Should throws an ArgumentException
        }
Example #3
0
        private static void AddRequestHeaders(EndpointConfig config, RequestSettings settings, HttpClient client, params object[] obj)
        {
            var requestHeaders = new HeaderCollection();

            if (settings.GlobalHeaders != null && settings.GlobalHeaders.Count > 1)
            {
                requestHeaders.Add(settings.GlobalHeaders);
            }

            if (settings.AuthenticationProvider != null)
            {
                var authHeaderTask = settings.AuthenticationProvider.GetAuthorizationHeader();
                Task.WhenAll(authHeaderTask);

                if (authHeaderTask.Result != null)
                {
                    requestHeaders.Add(authHeaderTask.Result.Item1, authHeaderTask.Result.Item2);
                }
            }

            requestHeaders.Add(config.GetRequestHeaders(obj));

            foreach (var h in requestHeaders.GetHeaders())
            {
                client.DefaultRequestHeaders.Add(h.Item1, h.Item2);
            }
        }
        public void EmptyAddressInEndpointConfigurationRegistrationShouldThrowsAnArgumentException()
        {
            Endpoint       endpoint = new Endpoint("");
            EndpointConfig ec       = new EndpointConfig("");

            endpoint.SetConfiguration("Network", ec);
        }
Example #5
0
        private void Acknowledgment(EndpointConfig epConf, BasicDeliverEventArgs args, bool ack, bool requeue, bool order)
        {
            if (epConf.AutoAck)
            {
                throw new NotSupportedException("Ручное подтверждение не доступно т.к. выбран режим AutoAck = true");
            }

            if (order)
            {
                if (ack)
                {
                    Model.BasicAck(args.DeliveryTag, true);
                }
                else
                {
                    Model.BasicNack(args.DeliveryTag, false, requeue);
                }
            }
            else
            {
                if (!ack)
                {
                    Model.BasicAck(args.DeliveryTag, false);
                }
                else
                {
                    Model.BasicNack(args.DeliveryTag, false, requeue);
                }
            }
        }
Example #6
0
        private void StartBus()
        {
            if (started)
            {
                return;
            }

            endpointConfig = cfgMgr.GetEndpointConfig(Username, Password);
            if (endpointConfig.Error)
            {
                throw new ApplicationException(endpointConfig.ErrorMessage);
            }
            sh       = new ServiceHost(typeof(OrderService));
            endpoint = sh.AddServiceEndpoint(
                typeof(IOrderService),
                new NetTcpRelayBinding(),
                ServiceBusEnvironment.CreateServiceUri("sb", endpointConfig.ServiceBusNamespace, "order"));

            endpoint.Behaviors.Add(new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
                    endpointConfig.Issuer,
                    endpointConfig.SecretKey)
            });
            sh.Open();
            started = true;
        }
Example #7
0
        /// <summary>
        /// Load <see cref="IEndpoint">
        /// </summary>
        /// <param name="services"></param>
        public override void Load(IServiceCollection services)
        {
            var config = new ConfigurationBuilder()
                         .AddEnvironmentVariables("hukRestClient")
                         .Build();
            var endpointConfig = config.Get <EndpointConfig>();

            if (endpointConfig == null)
            {
                endpointConfig = new EndpointConfig();
            }

            if (string.IsNullOrEmpty(endpointConfig?.EndpointType))
            {
                endpointConfig.EndpointType = "test";
            }


            services.AddSingleton <EndpointConfig>();
            services.AddSingleton <IEndpoint>(endpoint => {
                IEndpointFactory factory = new EndpointFactory();
                return(factory.Create(endpointConfig.EndpointType));
            }
                                              );
            services.AddTransient <IEndpointFactory, EndpointFactory>();
        }
Example #8
0
 public RemovePaymentLinkInDotpayCommand(ILogger logger, BaseDbContext dbContext,
                                         EndpointConfig endpointConfig,
                                         PaymentConfiguration paymentConfiguration) : base(logger, dbContext)
 {
     _endpointConfig       = endpointConfig;
     _paymentConfiguration = paymentConfiguration;
 }
 public CreatePaymentLinkCommand(ILogger logger, BaseDbContext dbContext, EndpointConfig endpointConfig,
                                 GetExistingPaymentLinkQuery getExistingPaymentLinkQuery,
                                 PaymentConfiguration paymentConfiguration) : base(logger, dbContext)
 {
     _endpointConfig              = endpointConfig;
     _paymentConfiguration        = paymentConfiguration;
     _getExistingPaymentLinkQuery = getExistingPaymentLinkQuery;
 }
Example #10
0
        public void PassesPlaceholderValuesWithoutMatches()
        {
            EndpointConfig.GenerateUriTemplate(ResourceMock.Object, "~/Glimpse.axd", LoggerMock.Object);

            EndpointConfigMock.Protected().Verify <string>("GenerateUriTemplate", Times.Once(), "resourceName", "~/Glimpse.axd",
                                                           ItExpr.IsAny <IEnumerable <ResourceParameterMetadata> >(),
                                                           ItExpr.IsAny <ILogger>());
        }
 private static object CreateGetCall(RequestSettings settings, EndpointConfig endpoint)
 {
     //using (var client = new HttpClient())
     //{
     //    var baseUrl = $"{settings.BaseUrl}{endpoint.Route}";
     //}
     return(null);
 }
        public void GetAddressForNetworkThrowsWhenNetworkNameIsEmpty()
        {
            Endpoint       endpoint = new Endpoint("MyIsp");
            EndpointConfig ec       = new EndpointConfig("", new NetworkCredential("user", "pass"));

            endpoint.Default = ec;

            string address = endpoint.GetAddressForNetwork(String.Empty);
        }
Example #13
0
 public GetCandidateIdCardQuery(ILogger logger, BaseDbContext dbContext,
                                EndpointConfig endpointConfig,
                                IFileRepository fileRepository,
                                BusinessConfiguration businessConfiguration) : base(logger, dbContext)
 {
     _fileRepository        = fileRepository;
     _endpointConfig        = endpointConfig;
     _businessConfiguration = businessConfiguration;
 }
Example #14
0
        public void ReturnEmptyStringWithNullChildResult()
        {
            EndpointConfigMock.Protected().Setup <string>("GenerateUriTemplate", "resourceName", "~/Glimpse.axd",
                                                          ItExpr.IsAny <IEnumerable <ResourceParameterMetadata> >(),
                                                          ItExpr.IsAny <ILogger>()).Returns <string>(null);

            Assert.Equal("",
                         EndpointConfig.GenerateUriTemplate(ResourceMock.Object, "", LoggerMock.Object));
        }
Example #15
0
        private async Task AsyncStart()
        {
            var endpointConfiguration = new EndpointConfiguration(EndpointConfig.EndpointName);

            EndpointConfig.Customize(endpointConfiguration);
            _endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

            Ioc.Container.Configure(x => x.For <IEndpointInstance>().Use(_endpointInstance));
        }
Example #16
0
 public UsersController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache,
                        IOptions <EndpointConfig> endpointConfig, ILogger <UsersController> logger)
 {
     _eventStore     = eventStore;
     _db             = db;
     _entityIndex    = cache.Index <EntityIndex>();
     _userIndex      = cache.Index <UserIndex>();
     _endpointConfig = endpointConfig.Value;
     _logger         = logger;
 }
        public void ModifyDefaultCredentialReplacesPreviousDefaultCredential()
        {
            Endpoint          ep            = new Endpoint("Endpoint");
            EndpointConfig    ec            = new EndpointConfig("Address", new NetworkCredential("U", "P", "D"));
            NetworkCredential expectedCreds = new NetworkCredential("A", "B", "C");

            ep.Default            = ec;
            ep.Default.Credential = expectedCreds;
            Assert.AreEqual(expectedCreds, ep.GetCredentialForNetwork(null));
        }
Example #18
0
        /// <summary>
        /// Добавить конфигурацию для конечной точки
        /// </summary>
        /// <param name="ep">Конечная точка</param>
        public void AppendEndpoint(EndpointConfig ep)
        {
            var eps    = Configuration.Endpoints;
            var newEps = new List <EndpointConfig>(eps ?? new EndpointConfig[0])
            {
                ep,
            };

            Configuration.Endpoints = newEps.ToArray();
        }
 public ActionResult CreateEndpoint(string id, EndpointConfig model)
 {
     ViewBag.Id = id;
     var item = GetConfigurationReader().GetConfiguration(id);
     model.Endpoints = new List<Endpoint>();
     model.Id = item.Endpoints.Count;
     item.Endpoints.Add(model);
     GetConfigurationReader().WriteConfigurationSet(item, id);
     return RedirectToAction("EndpointIndex", new { id });
 }
Example #20
0
        public ActionResult CreateEndpoint(string id, EndpointConfig model)
        {
            ViewBag.Id = id;
            var item = GetConfigurationReader().GetConfiguration(id);

            model.Endpoints = new List <Endpoint>();
            model.Id        = item.Endpoints.Count;
            item.Endpoints.Add(model);
            GetConfigurationReader().WriteConfigurationSet(item, id);
            return(RedirectToAction("EndpointIndex", new { id }));
        }
Example #21
0
        public void Load(IServiceCollection services, IConfiguration configuration)
        {
            var conf = new EndpointConfig();

            configuration.GetSection(EndpointConfig.Section).Bind(conf);

            services.AddHttpClient <IUsersClient, UsersClient>(client => { client.BaseAddress = new Uri(conf.Authentication); });
            services.AddHttpClient <IAuthenticationClient, AuthenticationClient>(client => { client.BaseAddress = new Uri(conf.Authentication); });
            services.AddHttpClient <IAuthenticationAppClient, AuthenticationAppClient>(client => { client.BaseAddress = new Uri(conf.Authentication); });
            services.AddHttpClient <ICredentialsUsersClient, CredentialsUsersClient>(client => { client.BaseAddress = new Uri(conf.Authentication); });
        }
        private static object CreateClientCall(RequestSettings settings, EndpointConfig endpoint)
        {
            switch (endpoint.Method)
            {
            case HttpRequestMethod.GET:
                return(CreateGetCall(settings, endpoint));

            default:
                throw new InvalidOperationException("I only support GET right now");
            }
        }
Example #23
0
        public void Login(string nickname, string serverIP)
        {
            Instance.nickname = nickname;
            Endpoint.openEngine();
            EndpointConfig config = Endpoint.createEndpointConfigBuilder(
                serverIP, 30000, LoginConfig.plainLogin(nickname, "123456", "test"))
                                    .staticViewClasses(ViewManager.createInstance(providerId))
                                    .build();

            Endpoint.start(config, new MyListener());
        }
        public void GetAddressForNetworkReturnsDefaultWhenNetworkNameIsNull()
        {
            Endpoint       endpoint = new Endpoint("MyIsp");
            EndpointConfig ec       = new EndpointConfig("", new NetworkCredential("user", "pass"));

            endpoint.Default = ec;

            string address = endpoint.GetAddressForNetwork(null);

            Assert.IsNotNull(address);
            Assert.AreEqual(ec.Address, address);
        }
Example #25
0
    private IEnumerable <EndpointConfig> ReadEndpoints()
    {
        var endpoints = new List <EndpointConfig>();

        var endpointsConfig = _configuration.GetSection(EndpointsKey).GetChildren();

        foreach (var endpointConfig in endpointsConfig)
        {
            // "EndpointName": {
            //     "Url": "https://*:5463",
            //     "Protocols": "Http1AndHttp2",
            //     "SslProtocols": [ "Tls11", "Tls12", "Tls13"],
            //     "Certificate": {
            //         "Path": "testCert.pfx",
            //         "Password": "******"
            //     },
            //     "ClientCertificateMode" : "NoCertificate",
            //     "Sni": {
            //         "a.example.org": {
            //             "Certificate": {
            //                 "Path": "testCertA.pfx",
            //                 "Password": "******"
            //             }
            //         },
            //         "*.example.org": {
            //             "Protocols": "Http1",
            //         }
            //     }
            // }

            var url = endpointConfig[UrlKey];
            if (string.IsNullOrEmpty(url))
            {
                throw new InvalidOperationException(CoreStrings.FormatEndpointMissingUrl(endpointConfig.Key));
            }

            var endpoint = new EndpointConfig(
                endpointConfig.Key,
                url,
                ReadSni(endpointConfig.GetSection(SniKey), endpointConfig.Key),
                endpointConfig)
            {
                Protocols             = ParseProtocols(endpointConfig[ProtocolsKey]),
                SslProtocols          = ParseSslProcotols(endpointConfig.GetSection(SslProtocolsKey)),
                ClientCertificateMode = ParseClientCertificateMode(endpointConfig[ClientCertificateModeKey]),
                Certificate           = new CertificateConfig(endpointConfig.GetSection(CertificateKey))
            };

            endpoints.Add(endpoint);
        }

        return(endpoints);
    }
        public void GetCredentialForNetworkReturnsDefaultWhenNetworkNameIsNull()
        {
            Endpoint       endpoint = new Endpoint("MyIsp");
            EndpointConfig ec       = new EndpointConfig("", new NetworkCredential("user", "pass"));

            endpoint.Default = ec;

            NetworkCredential cred = endpoint.GetCredentialForNetwork(null);

            Assert.IsNotNull(cred);
            Assert.AreEqual(ec.Credential, cred);
        }
 public RegisterUserCommand(ILogger logger,
                            RegisterRequestValidator validator,
                            BaseDbContext dbContext,
                            PasswordHasher passwordHasher,
                            SendEmailCommand sendEmailCommand,
                            EndpointConfig endpointConfig,
                            BusinessConfiguration businessConfiguration) : base(logger, validator, dbContext)
 {
     _passwordHasher        = passwordHasher;
     _sendEmailCommand      = sendEmailCommand;
     _endpointConfig        = endpointConfig;
     _businessConfiguration = businessConfiguration;
 }
 public MediaController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache,
                        IOptions <UploadFilesConfig> uploadConfig, IOptions <EndpointConfig> endpointConfig,
                        ILogger <MediaController> logger)
 {
     _logger          = logger;
     _eventStore      = eventStore;
     _db              = db;
     _entityIndex     = cache.Index <EntityIndex>();
     _mediaIndex      = cache.Index <MediaIndex>();
     _referencesIndex = cache.Index <ReferencesIndex>();
     _uploadConfig    = uploadConfig.Value;
     _endpointConfig  = endpointConfig.Value;
 }
Example #29
0
        public void ReturnEmptyStringWithChildGenerateUriException()
        {
            EndpointConfigMock.Protected().Setup <string>("GenerateUriTemplate", ItExpr.IsAny <string>(), "~/Glimpse.axd",
                                                          ItExpr.IsAny <IEnumerable <ResourceParameterMetadata> >(),
                                                          ItExpr.IsAny <ILogger>()).Throws <DummyException>();

            var result = EndpointConfig.GenerateUriTemplate(ResourceMock.Object, "~/Glimpse.axd", LoggerMock.Object);

            EndpointConfigMock.Protected().Verify <string>("GenerateUriTemplate", Times.Once(), "resourceName", "~/Glimpse.axd", ItExpr.IsAny <IEnumerable <ResourceParameterMetadata> >(),
                                                           ItExpr.IsAny <ILogger>());
            LoggerMock.Verify(l => l.Error(It.IsAny <string>(), It.IsAny <DummyException>(), It.IsAny <object[]>()));
            Assert.Equal("", result);
        }
Example #30
0
        public ActionResult EditEndpoint(string id, int eid, EndpointConfig model)
        {
            var item = GetConfigurationReader().GetConfiguration(id);

            ViewBag.Id  = id;
            ViewBag.Eid = eid;
            var endpoint = GetEndpoint(item, id, eid);

            endpoint.ServiceName    = model.ServiceName;
            endpoint.Deleted        = model.Deleted;
            endpoint.ActiveEndpoint = model.ActiveEndpoint;
            GetConfigurationReader().WriteConfigurationSet(item, id);
            return(RedirectToAction("EndpointIndex", new { id }));
        }
        public void ModifyingEndpointConfigReplacePreviousConfig()
        {
            Endpoint       ep  = new Endpoint("Endpoint");
            EndpointConfig ec1 = new EndpointConfig("URL1");

            ep.SetConfiguration("Network1", ec1);

            EndpointConfig ec2 = new EndpointConfig("URL2");

            ep.SetConfiguration("Network1", ec2);

            Assert.AreEqual(ec2.Address, ep.GetAddressForNetwork("Network1"));
            Assert.AreEqual(ec2.Credential, ep.GetCredentialForNetwork("Network1"));
            Assert.AreEqual(1, ep.NetworkNames.Count);
        }
 public ActionResult EditEndpoint(string id, int eid, EndpointConfig model)
 {
     var item = GetConfigurationReader().GetConfiguration(id);
     ViewBag.Id = id;
     ViewBag.Eid = eid;
     var endpoint = GetEndpoint(item, id, eid);
     endpoint.ServiceName = model.ServiceName;
     endpoint.Deleted = model.Deleted;
     endpoint.ActiveEndpoint = model.ActiveEndpoint;
     GetConfigurationReader().WriteConfigurationSet(item, id);
     return RedirectToAction("EndpointIndex", new { id });
 }