Пример #1
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "host.json"), optional: false, reloadOnChange: true)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "local.settings.json"), optional: true, reloadOnChange: true)
            .AddEnvironmentVariables();

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(builder.ConfigurationBuilder.Build())
                         .Enrich.FromLogContext()
                         .Enrich.WithExceptionDetails()
                         .Enrich.WithProperty("Proc", "Aha.Dns.Notifications.CloudFunctions")
                         .CreateLogger();
        }
Пример #2
0
        public static IFunctionsConfigurationBuilder ConfigureKeyVault(this IFunctionsConfigurationBuilder builder, string vaultUrl, Assembly assembly = null)
        {
            var azureServiceTokenProvider = new AzureServiceTokenProvider();
            var keyVaultClient            = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(
                    azureServiceTokenProvider.KeyVaultTokenCallback));

            builder.ConfigurationBuilder
            //.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
            .AddAzureKeyVault(vaultUrl, keyVaultClient, new DefaultKeyVaultSecretManager());
            if (assembly != null)
            {
                builder.ConfigurationBuilder.AddUserSecrets(assembly);
            }

            return(builder);
        }
Пример #3
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            if (string.Equals(context.EnvironmentName, "Production", StringComparison.OrdinalIgnoreCase))
            {
                // For Production (Using Key Vault with Managed Identity)
                var builtConfig = builder.ConfigurationBuilder.Build();

                builder.ConfigurationBuilder.AddAzureKeyVault(new Uri(builtConfig["KeyVaultEndpoint"]), new DefaultAzureCredential());
            }
            else
            {
                // For Local development (Using User Secrets)
                builder.ConfigurationBuilder.AddUserSecrets <Startup>();
            }
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var azureServiceTokenProvider = new AzureServiceTokenProvider();
            var keyVaultClient            = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(
                    azureServiceTokenProvider.KeyVaultTokenCallback));

            FunctionsHostBuilderContext context = builder.GetContext();

            var builtConfig = builder.ConfigurationBuilder.Build();

            builder.ConfigurationBuilder
            .AddAzureKeyVault(builtConfig["AzureVaultURL"], keyVaultClient, new DefaultKeyVaultSecretManager())
            //.AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
            // .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
            .AddEnvironmentVariables();
        }
Пример #5
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     // Add Azure App Configuration as additional configuration source
     builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
     {
         options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
         // Load all keys that start with `TestApp:` and have no label
         .Select("TestApp:*")
         // Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
         // Use the default cache expiration of 30 seconds. It can be overriden via AzureAppConfigurationRefreshOptions.SetCacheExpiration.
         .ConfigureRefresh(refreshOptions =>
                           refreshOptions.Register("TestApp:Settings:Sentinel", refreshAll: true)
                           )
         // Load all feature flags with no label. To load specific feature flags and labels, set via FeatureFlagOptions.Select.
         // Use the default cache expiration of 30 seconds. It can be overriden via FeatureFlagOptions.CacheExpirationInterval.
         .UseFeatureFlags();
     });
 }
Пример #6
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            string appcfEndpoint   = Environment.GetEnvironmentVariable("APPCF_ENDPOINT");
            string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var    credential      = new DefaultAzureCredential();

            builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
            {
                options.Connect(new Uri(appcfEndpoint), credential)
                .Select("TestApp:Settings:*", environmentName)
                .Select("ConnectionStrings:SqlDb:*", environmentName)
                .ConfigureRefresh(refresh =>
                                  refresh.Register("TestApp:Settings:Sentinel", refreshAll: true)
                                  .SetCacheExpiration(new TimeSpan(0, 5, 0))
                                  );
                options.ConfigureKeyVault(kv => kv.SetCredential(credential));
            });
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var environment = Environment.GetEnvironmentVariable("ENVIRONMENT") ?? "Production";

            if (environment.Equals(Environments.Development, StringComparison.OrdinalIgnoreCase))
            {
                builder.ConfigurationBuilder.AddUserSecrets(typeof(Startup).Assembly);
            }

            builder.ConfigurationBuilder.AddInMemoryCollection(new Dictionary <string, string>()
            {
                { "CampaignDataContainerName", "campaign-data" },
                { "DataUploadsContainerName", Core.DataManagement.Constants.ContainerName },
                { "CourseUploadsFolderName", Core.DataManagement.Constants.CoursesFolder },
                { "VenueUploadsFolderName", Core.DataManagement.Constants.VenuesFolder },
                { "ApprenticeshipUploadsFolderName", Core.DataManagement.Constants.ApprenticeshipsFolder }
            });
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var managedIdentityCredentials = new ManagedIdentityCredential();
            var defaultCredentials         = new DefaultAzureCredential();

            builder.ConfigurationBuilder
            .AddEnvironmentVariables()
            .AddAzureAppConfiguration((options) =>
            {
                var configconnection = Environment.GetEnvironmentVariable("AppConfigConnectionString");
                options.Connect(configconnection);
                options.ConfigureKeyVault(vault => vault.SetCredential(new DefaultAzureCredential()));

                //use following after setting managed identity
                //options.Connect(new Uri(Environment.GetEnvironmentVariable("ConfigConnString")), new ManagedIdentityCredential()));
            });

            Configuration = builder.ConfigurationBuilder.Build();
        }
Пример #9
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var config = builder.ConfigurationBuilder.Build();

            // create a new configurationbuilder and add appconfiguration
            builder.ConfigurationBuilder.AddAzureAppConfiguration((options) =>
            {
                var defaultAzureCredential = GetDefaultAzureCredential();

                options.Connect(new Uri(config["AppConfigUrl"]), defaultAzureCredential)
                // also setup key vault for key vault references
                .ConfigureKeyVault(kvOptions =>
                {
                    kvOptions.SetCredential(defaultAzureCredential);
                });

                // configure appconfiguation features you want;
                // options.UseFeatureFlags();
                // options.Select(KeyFilter.Any, LabelFilter.Null);
            });
        }
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     try
     {
         // On Azure, this is the path where the app is.
         // If you use Directory.GetCurrentDirectory(), you will get D:\Program Files (x86)\SiteExtensions\Functions\3.0.14785\32bit
         // Adapted from: https://stackoverflow.com/a/60078802
         var basePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..");
         builder.ConfigurationBuilder
         .SetBasePath(basePath)
         .AttachConfiguration(new HbtiEnvironment()
         {
             EnvironmentName = builder.GetContext().EnvironmentName
         });
     }
     catch (Exception ex)
     {
         HandleException(ex);
         throw;
     }
 }
Пример #11
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();
            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");


            var azureServiceTokeProvider = new AzureServiceTokenProvider();

            var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokeProvider.KeyVaultTokenCallback));


            _configurationRoot = builder.ConfigurationBuilder
                                 .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
                                 .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{environment}.json"), optional: true, reloadOnChange: false)
                                 .AddEnvironmentVariables()
                                 .Build();

            builder.ConfigurationBuilder.AddAzureKeyVault($"https://{_configurationRoot["dataconnections:azurekeyvault:keyvaultname"]}.vault.azure.net/", keyVaultClient, new DefaultKeyVaultSecretManager()).Build();

            _configurationRoot = builder.ConfigurationBuilder.Build();
        }
Пример #12
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            // create a new configurationbuilder and add appconfiguration
            builder.ConfigurationBuilder.AddAzureAppConfiguration((options) =>
            {
                var credentials = new DefaultAzureCredential(
                    new DefaultAzureCredentialOptions
                {
                    ExcludeSharedTokenCacheCredential = true,
                });

                options
                .Connect(new Uri("https://cfg-appconfig-demo.azconfig.io"), credentials)
                .ConfigureRefresh(c =>
                {
                    c
                    .Register("Sentinel", true)
                    .SetCacheExpiration(new TimeSpan(0, 0, 10));
                });
            });
        }
Пример #13
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     isLocal = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"));
     if (isLocal)
     {
         var appConfLocal = Environment.GetEnvironmentVariable("KeyConnectionString");
         builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
         {
             options.Connect(appConfLocal)
             .ConfigureRefresh(refreshOptions =>
                               refreshOptions.Register("TestApp:Settings:Message02")
                               .SetCacheExpiration(TimeSpan.FromSeconds(30))
                               )
             .UseFeatureFlags(featureFlagOptions => {
                 featureFlagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(20);
             });
         });
     }
     else
     {
         string cs = Environment.GetEnvironmentVariable("EndpointURL");
         builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
         {
             //Rol Requerido para AppConfiguration: App Configuration Data Reader
             //Rol Requerido para KeyVault: Key Vault Secrets User
             options.Connect(new Uri(cs), new ManagedIdentityCredential())
             .ConfigureKeyVault(kv =>
             {
                 kv.SetCredential(new DefaultAzureCredential());
             })
             .ConfigureRefresh(refreshOptions =>
                               refreshOptions.Register("TestApp:Settings:Message02")
                               .SetCacheExpiration(TimeSpan.FromSeconds(30))
                               )
             .UseFeatureFlags(featureFlagOptions => {
                 featureFlagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(20);
             });
         });
     }
 }
Пример #14
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            const string vhInfraCore = "/mnt/secrets/vh-infra-core";
            const string vhBookingQueueSubscriber = "/mnt/secrets/vh-booking-queue-subscriber";

            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.json"), true)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), true)
            .AddAksKeyVaultSecretProvider(vhInfraCore)
            .AddAksKeyVaultSecretProvider(vhBookingQueueSubscriber)
            .AddUserSecrets("F6705640-D918-4180-B98A-BAB7ADAA4817")
            .AddEnvironmentVariables();

            base.ConfigureAppConfiguration(builder);
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.json"), true, true)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{env}.json"), true, true);


            var cosmosKeyVaultUrl = Environment.GetEnvironmentVariable("KeyVaultUrl");

            if (!string.IsNullOrEmpty(cosmosKeyVaultUrl))
            {
                var secretClient = new SecretClient(new Uri(cosmosKeyVaultUrl), new DefaultAzureCredential());
                builder.ConfigurationBuilder.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());
            }

            builder.ConfigurationBuilder.AddEnvironmentVariables();
            builder.ConfigurationBuilder.Build();
        }
Пример #16
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var builtConfig = builder.ConfigurationBuilder
                              .AddEnvironmentVariables()
                              .Build();

            var context = builder.GetContext();

            if (!string.IsNullOrEmpty(context.EnvironmentName) &&
                context.EnvironmentName.ToLower() == "development")
            {
                BuiltConfig = builder.ConfigurationBuilder
                              .SetBasePath(Environment.CurrentDirectory)
                              .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                              .AddUserSecrets(Assembly.GetExecutingAssembly(), true)
                              .AddEnvironmentVariables()
                              .Build();
            }
            else
            {
                try
                {
                    var tokenProvider = new AzureServiceTokenProvider();
                    var kvClient      = new KeyVaultClient(
                        new KeyVaultClient.AuthenticationCallback(
                            tokenProvider.KeyVaultTokenCallback)
                        );
                    BuiltConfig = builder.ConfigurationBuilder
                                  .SetBasePath(Environment.CurrentDirectory)
                                  // .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                  .AddEnvironmentVariables()
                                  .AddAzureKeyVault(builtConfig["keyVaultUrl"], kvClient, new DefaultKeyVaultSecretManager())
                                  .Build();
                } catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Пример #17
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            string appConfigUri = Environment.GetEnvironmentVariable("AppConfigEndpoint");

            builder.ConfigurationBuilder.AddAzureAppConfiguration(options => {
                options.Connect(new Uri(appConfigUri), new ManagedIdentityCredential())
                .ConfigureRefresh(ro =>
                {
                    ro.Register("GLOBAL:debugMode", LabelFilter.Null, refreshAll: true);
                    ro.Register("CORE:storageAccount", LabelFilter.Null, refreshAll: true);
                    ro.Register("CORE:storageQueue", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:tagPrefix", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:enableTag", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:startTimeTag", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:endTimeTag", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:setStatePrefix", LabelFilter.Null, refreshAll: true);
                    ro.Register("CONFIG:saveStatePrefix", LabelFilter.Null, refreshAll: true);
                    ro.SetCacheExpiration(TimeSpan.FromSeconds(60));
                });

                ConfigurationRefresher = options.GetRefresher();
            });
        }
Пример #18
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }


            base.ConfigureAppConfiguration(builder);

            const string vhInfraCore     = "/mnt/secrets/vh-infra-core";
            const string vhSchedulerJobs = "/mnt/secrets/vh-scheduler-jobs";

            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.json"), true)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), true)
            .AddAksKeyVaultSecretProvider(vhInfraCore)
            .AddAksKeyVaultSecretProvider(vhSchedulerJobs)
            .AddUserSecrets("518CD6B6-4F2B-4431-94C8-4D0F4137295F")
            .AddEnvironmentVariables();
        }
Пример #19
0
 /// <summary>
 /// Calculate environment from unreliable function environment setting.
 /// github.com/Azure/azure-functions-host/issues/6239 problem determining environment.
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static string GetCurrentEnvironmentName(this IFunctionsConfigurationBuilder builder)
 {
     return(GetCurrentEnvironmentName(builder.GetContext().EnvironmentName));
 }
Пример #20
0
 // This method gets called by the runtime. Use this method to configure the app configuration.
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     builder.ConfigurationBuilder.AddEnvironmentVariables();
 }
Пример #21
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     base.ConfigureAppConfiguration(builder);
     var context = builder.GetContext();
 }
Пример #22
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder, IConventionContext context)
 {
 }
Пример #23
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     builder.ConfigurationBuilder
     .AddEnvironmentVariables()
     .AddJsonFile("local.settings.json", true);
 }
Пример #24
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var cs = Environment.GetEnvironmentVariable("AZ_APPCONFIG_URI");

            builder.ConfigurationBuilder.AddAzureAppConfiguration(cs);
        }
Пример #25
0
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     //string cs = Environment.GetEnvironmentVariable("ConnectionString");
     // Microsoft.Extensions.Configuration.AzureAppConfiguration
     //builder.ConfigurationBuilder.AddAzureAppConfiguration(cs);
 }
 public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
     base.ConfigureAppConfiguration(builder);
 }
Пример #27
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            base.ConfigureAppConfiguration(builder);

            builder.ConfigurationBuilder.AddEnvironmentVariables("EventBridge_");
        }
Пример #28
0
 /// <summary>
 ///     Method called to configure the application with the conventions
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="context"></param>
 public virtual void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder, IConventionContext context)
 {
 }
 /// <summary>
 /// Performs the startup configuration action for configuring application configuration.
 /// The runtime will call this method at the right time during initialization.
 /// </summary>
 /// <param name="builder">The <see cref="IFunctionsConfigurationBuilder"/> that can be used to
 /// configure the application configuration.</param>
 public virtual void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
 {
 }
        /// <summary>
        /// Adds KeyVault configuration
        ///
        /// dotnet core 3.1 style
        /// </summary>
        /// <param name="builder"></param>
        public static void AddKeyVault(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            AddKeyVault(builder.ConfigurationBuilder, context.ApplicationRootPath);
        }