Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            services.AddControllers();
            services.AddOptions()
            .Configure <HotaConfiguration>(this.Configuration.GetSection("Hota"))
            .Configure <AzureAdConfiguration>(this.Configuration.GetSection("AzureAd"));

            services.AddSingleton(sp =>
            {
                var config = sp.GetRequiredService <AzureAdConfiguration>();
                return(KeyVaultHelpers.Create(config));
            });

            services.AddSingleton(sp =>
            {
                var config         = sp.GetRequiredService <AzureAdConfiguration>();
                var keyVaultClient = sp.GetRequiredService <KeyVaultClient>();

                return(new HotaAzureStorage(
                           async t => (await keyVaultClient.GetSecretAsync($"https://{config.KeyVaultName}.vault.azure.net/hotastorage-TableStorageSas", t)).Value,
                           TimeSpan.FromDays(1)));
            });

            services.AddHostedService <HotaService>();
        }
Exemple #2
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((context, config) =>
        {
            if (context.HostingEnvironment.IsProduction())
            {
                var builtConfig   = config.Build();
                var azureAdConfig = new AzureAdConfiguration();
                builtConfig.Bind("AzureAd", azureAdConfig);

                config.AddAzureKeyVault(
                    $"https://{azureAdConfig.KeyVaultName}.vault.azure.net/",
                    KeyVaultHelpers.Create(azureAdConfig),
                    new DefaultKeyVaultSecretManager());
            }
        })
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup <Startup>();
        });