Пример #1
0
        private static void Init()
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            Console.WriteLine($"Environment: {environment}");

            var builder = new ConfigurationBuilder()
                          .AddJsonFile($"appsettings.{environment}.json", true, true)
                          .AddEnvironmentVariables();

            IConfigurationRoot Configuration = builder.Build();

            // Retrieve configuration from sections
            ApplicationSettings.ConnectionString          = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value;
            ApplicationSettings.DatabaseId                = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value;
            ApplicationSettings.UserCollection            = Configuration.GetSection("ApplicationSettings:UserCollection")?.Value;
            ApplicationSettings.RabbitMQUsername          = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value;
            ApplicationSettings.RabbitMQPassword          = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value;
            ApplicationSettings.RabbitMQHostname          = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value;
            ApplicationSettings.RabbitMQPort              = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value);
            ApplicationSettings.UserRegistrationQueueName = Configuration.GetSection("ApplicationSettings:UserRegistrationQueueName")?.Value;
            ApplicationSettings.KeyVaultCertificateName   = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value;
            ApplicationSettings.KeyVaultClientId          = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value;
            ApplicationSettings.KeyVaultClientSecret      = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value;
            ApplicationSettings.KeyVaultIdentifier        = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value;
            ApplicationSettings.KeyVaultEncryptionKey     = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value;
            ApplicationSettings.SendGridAPIKey            = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value;

            mongoDBConnectionInfo = new MongoDBConnectionInfo()
            {
                ConnectionString = ApplicationSettings.ConnectionString,
                DatabaseId       = ApplicationSettings.DatabaseId,
                UserCollection   = ApplicationSettings.UserCollection
            };

            keyVaultConnectionInfo = new KeyVaultConnectionInfo()
            {
                CertificateName    = ApplicationSettings.KeyVaultCertificateName,
                ClientId           = ApplicationSettings.KeyVaultClientId,
                ClientSecret       = ApplicationSettings.KeyVaultClientSecret,
                KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier
            };

            using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo))
            {
                secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result;
            }

            using (BlockchainHelper blockchainHelper = new BlockchainHelper())
            {
                wordlist = blockchainHelper.ReadMnemonic();
            }
        }
Пример #2
0
        private static void Init()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile($"appsettings.json", true, true)
                          .AddEnvironmentVariables();

            IConfigurationRoot Configuration = builder.Build();

            // Retrieve configuration from sections
            Settings.ConnectionString          = Configuration.GetSection("ConnectionString")?.Value;
            Settings.DatabaseId                = Configuration.GetSection("DatabaseId")?.Value;
            Settings.UserCollection            = Configuration.GetSection("UserCollection")?.Value;
            Settings.RabbitMQUsername          = Configuration.GetSection("RabbitMQUsername")?.Value;
            Settings.RabbitMQPassword          = Configuration.GetSection("RabbitMQPassword")?.Value;
            Settings.RabbitMQHostname          = Configuration.GetSection("RabbitMQHostname")?.Value;
            Settings.RabbitMQPort              = Convert.ToInt16(Configuration.GetSection("RabbitMQPort")?.Value);
            Settings.UserRegistrationQueueName = Configuration.GetSection("UserRegistrationQueueName")?.Value;
            Settings.KeyVaultCertificateName   = Configuration.GetSection("KeyVaultCertificateName")?.Value;
            Settings.KeyVaultClientId          = Configuration.GetSection("KeyVaultClientId")?.Value;
            Settings.KeyVaultClientSecret      = Configuration.GetSection("KeyVaultClientSecret")?.Value;
            Settings.KeyVaultIdentifier        = Configuration.GetSection("KeyVaultIdentifier")?.Value;
            Settings.KeyVaultEncryptionKey     = Configuration.GetSection("KeyVaultEncryptionKey")?.Value;
            Settings.SendGridAPIKey            = Configuration.GetSection("SendGridAPIKey")?.Value;

            mongoDBConnectionInfo = new MongoDBConnectionInfo()
            {
                ConnectionString = Settings.ConnectionString,
                DatabaseId       = Settings.DatabaseId,
                UserCollection   = Settings.UserCollection
            };

            keyVaultConnectionInfo = new KeyVaultConnectionInfo()
            {
                CertificateName    = Settings.KeyVaultCertificateName,
                ClientId           = Settings.KeyVaultClientId,
                ClientSecret       = Settings.KeyVaultClientSecret,
                KeyVaultIdentifier = Settings.KeyVaultIdentifier
            };

            using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo))
            {
                secret = keyVaultHelper.GetVaultKeyAsync(Settings.KeyVaultEncryptionKey).Result;
            }

            using (BlockchainHelper blockchainHelper = new BlockchainHelper())
            {
                wordlist = blockchainHelper.ReadMnemonic();
            }
        }