Inheritance: IHostConfig
Ejemplo n.º 1
0
        public void TestJsonCreationForHost()
        {
            var config = new HostConfig
            {
                Runtime =
                {
                    Audit = new AuditElement {Enabled = true},
                    LogInfo = new LogElement
                    {
                        ProviderType = "KonfDB.Infrastructure.Logging.Logger, KonfDBC",
                        Parameters = @"-path:konfdb\log.txt"
                    },
                    ServiceSecurity = ServiceSecurityMode.None
                }
            };
            config.Runtime.Server.Add(new ServiceTypeConfiguration {Port = 8885, Type = EndPointType.TCP});
            config.Runtime.Server.Add(new ServiceTypeConfiguration {Port = 8880, Type = EndPointType.HTTP});
            config.Runtime.Server.Add(new ServiceTypeConfiguration {Port = 8890, Type = EndPointType.WSHTTP});
            config.Runtime.Server.Add(new ServiceTypeConfiguration {Port = 8882, Type = EndPointType.REST});
            config.Runtime.SuperUser.Username = "******";
            config.Runtime.SuperUser.Password = "******";

            config.Caching.Enabled = false;
            config.Caching.ProviderType = typeof (InMemoryCacheStore).AssemblyQualifiedName;
            config.Caching.Parameters = "-duration:30 -mode:Absolute";

            config.Certificate.DefaultKey = "testCert";
            config.Certificate.Certificates.Add(new CertificateProviderConfiguration
            {
                CertificateKey = "testCert",
                StoreLocation = StoreLocation.LocalMachine,
                StoreName = StoreName.My,
                FindBy = X509FindType.FindBySubjectName,
                Value = "localhost"
            });

            config.Database.DefaultKey = "localsql";
            config.Database.Databases.Add(new DatabaseProviderConfiguration
            {
                Key = "localsql",
                Host = @"localhost\sqlexpress",
                Port = 8080,
                InstanceName = "konf",
                Username = "******",
                Password = "******",
                Location = @"c:\temp",
                ProviderType = "MsSql"
            });
            config.Database.Databases.Add(new DatabaseProviderConfiguration
            {
                Key = "azure",
                Host = @"tcp:lbxcft14aq.database.windows.net",
                Port = 1433,
                InstanceName = "dbName",
                Username = "******",
                Password = "******",
                ProviderType = "AzureSql"
            });

            var configJson = config.ToJson();
            var readBack = configJson.FromJsonToObject<HostConfig>();
            Assert.IsNotNull(readBack);
        }
Ejemplo n.º 2
0
        private IHostConfig LoadConfigurationFromAzureUI()
        {
            var userConnectionString = RoleEnvironment.GetConfigurationSettingValue("konfdb.runtime.superuser");
            var databaseConnectionString = RoleEnvironment.GetConfigurationSettingValue("konfdb.database");
            var defaultCertificateSettings = RoleEnvironment.GetConfigurationSettingValue("konfdb.certificate.default");
            var encryptionCertificateSettings =
                RoleEnvironment.GetConfigurationSettingValue("konfdb.certificate.encryption");

            var superuserArgs = new CommandArgs(userConnectionString);
            var databaseArgs = new CommandArgs(databaseConnectionString);
            var defaultCertificateArgs = new CommandArgs(defaultCertificateSettings);
            var encryptionCertificateArgs = new CommandArgs(encryptionCertificateSettings);


            IHostConfig hostConfig = new HostConfig();
            hostConfig.Caching.ProviderType = typeof (InRoleCacheStore).AssemblyQualifiedName;
            hostConfig.Caching.Enabled = true;

            hostConfig.Runtime.Audit = new AuditElement {Enabled = true};
            hostConfig.Runtime.LogInfo = new LogElement
            {
                ProviderType = typeof (AzureLogger).AssemblyQualifiedName
            };

            if (string.IsNullOrEmpty(defaultCertificateSettings))
            {
                hostConfig.Runtime.ServiceSecurity = ServiceSecurityMode.None;
            }
            else
            {
                hostConfig.Runtime.ServiceSecurity = ServiceSecurityMode.BasicSSL;
                hostConfig.Certificate.DefaultKey = "default";
                var certificateConfig = new CertificateProviderConfiguration
                {
                    CertificateKey = "default",
                    FindBy =
                        defaultCertificateArgs.GetValue("findBy", X509FindType.FindByThumbprint.ToString())
                            .FromJsonToObject<X509FindType>(),
                    StoreLocation =
                        defaultCertificateArgs.GetValue("storeLocation", StoreLocation.CurrentUser.ToString())
                            .FromJsonToObject<StoreLocation>(),
                    StoreName =
                        defaultCertificateArgs.GetValue("storeName", StoreName.My.ToString())
                            .FromJsonToObject<StoreName>(),
                    Value = defaultCertificateArgs.GetValue("value", string.Empty)
                };
                hostConfig.Certificate.Certificates.Add(certificateConfig);
            }

            if (string.IsNullOrEmpty(encryptionCertificateSettings))
            {
                hostConfig.Certificate.EncryptionKey = "default";
            }
            else
            {
                hostConfig.Certificate.EncryptionKey = "encryption";
                var certificateConfig = new CertificateProviderConfiguration
                {
                    CertificateKey = "encryption",
                    FindBy =
                        encryptionCertificateArgs.GetValue("findBy", X509FindType.FindByThumbprint.ToString())
                            .FromJsonToObject<X509FindType>(),
                    StoreLocation =
                        encryptionCertificateArgs.GetValue("storeLocation", StoreLocation.CurrentUser.ToString())
                            .FromJsonToObject<StoreLocation>(),
                    StoreName =
                        encryptionCertificateArgs.GetValue("storeName", StoreName.My.ToString())
                            .FromJsonToObject<StoreName>(),
                    Value = encryptionCertificateArgs.GetValue("value", string.Empty)
                };
                hostConfig.Certificate.Certificates.Add(certificateConfig);
            }

            hostConfig.Runtime.SuperUser = new UserElement
            {
                Username = superuserArgs.GetValue("username", "azureuser"),
                Password = superuserArgs.GetValue("password", "aZuReu$rpWd"),
                IsEncrypted = bool.Parse(databaseArgs.GetValue("isEncrypted", bool.FalseString.ToLower()))
            };

            hostConfig.Database.DefaultKey = "default";
            hostConfig.Database.Databases.Add(new DatabaseProviderConfiguration
            {
                Key = "default",
                Host = databaseArgs["host"],
                Port = int.Parse(databaseArgs["port"]),
                InstanceName = databaseArgs["instanceName"],
                Username = databaseArgs["username"],
                Password = databaseArgs["password"],
                IsEncrypted = bool.Parse(databaseArgs.GetValue("isEncrypted", bool.FalseString.ToLower())),
                ProviderType = GetProvider(databaseArgs["providerType"]),
                Location = databaseArgs.GetValue("location", string.Empty)
            });

            foreach (var endPoint in RoleEnvironment.CurrentRoleInstance.InstanceEndpoints)
            {
                Debug.WriteLine(endPoint.Key + " " + endPoint.Value.IPEndpoint.Port + " " + endPoint.Value.Protocol);

                if (!endPoint.Key.StartsWith("KonfDB"))
                    continue;

                hostConfig.Runtime.Server.Add(new ServiceTypeConfiguration
                {
                    Port = endPoint.Value.IPEndpoint.Port,
                    Type = ConvertAzureProtocol(endPoint.Key, endPoint.Value.Protocol)
                });
            }

            return hostConfig;
        }