Exemple #1
0
        /// <summary>
        /// Конфигурация загружается из переменных окружения
        /// И из Azure Storage если заданы переменные окружения
        ///   ConfigStorageUri
        ///   ConfigStorageSas
        ///   ConfigStorageContainer
        ///
        /// или из файла appsettings.local.json если переменные не заданы
        /// </summary>
        /// <param name="builder"></param>
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            //Get enviroment variables for config file access
            var configStorage = new ConfigStorageAccess();

            if (!configStorage.Configured)
            {
                builder.ConfigurationBuilder
                .AddJsonFile(Path.Combine(context.ApplicationRootPath, ConfigFileNameLocal), false, false)
                .AddEnvironmentVariables();
            }
            else
            {
                CheckConfigurationBlob(configStorage).Wait();

                var azureBlobFileProvider = new AzureBlobFileProvider(new AzureBlobOptions()
                {
                    ConnectionString  = configStorage.ConnectionString,
                    DocumentContainer = configStorage.ContainerName
                });

                builder.ConfigurationBuilder
                .AddJsonFile(azureBlobFileProvider, ConfigFileName, false, false)
                .AddEnvironmentVariables();
            }
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            var builtConfig      = builder.ConfigurationBuilder.Build();
            var keyVaultEndpoint = builtConfig["AzureKeyVaultEndpoint"];

            if (!string.IsNullOrEmpty(keyVaultEndpoint))
            {
                // using Key Vault, either local dev or deployed

                //var azureServiceTokenProvider = new AzureServiceTokenProvider();
                //var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

                //builder.ConfigurationBuilder
                //        .AddAzureKeyVault(keyVaultEndpoint)
                //        .SetBasePath(Environment.CurrentDirectory)
                //        .AddJsonFile("local.settings.json", true)
                //        .AddEnvironmentVariables()
                //    .Build();
            }
            else
            {
                // local dev no Key Vault
                builder.ConfigurationBuilder
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("local.settings.json", true)
                .AddUserSecrets(Assembly.GetExecutingAssembly(), true)
                .AddEnvironmentVariables()
                .Build();
            }
        }
    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var context = builder.GetContext();

        builder.ConfigurationBuilder
        .AddUserSecrets <Startup>()
        .AddEnvironmentVariables();
    }
Exemple #4
0
        /// <summary>
        /// Configure application settings for the Azure Functions Application using local.settings.json, secrets.settings.json and environment variables.
        /// </summary>
        /// <param name="builder">IFunctionsConfigurationBuilder used to configure the application.</param>
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            base.ConfigureAppConfiguration(builder);

            var basePath = builder.GetContext().ApplicationRootPath;

            ConfigureAppConfiguration(builder.ConfigurationBuilder, basePath);
        }
Exemple #5
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "local.settings.json"), optional: true, reloadOnChange: false)
            .AddEnvironmentVariables();
        }
Exemple #6
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            // auto-detect SkillHostEndpoint
            FunctionsHostBuilderContext context = builder.GetContext();
            var hostname = builder.ConfigurationBuilder.Build().GetValue <string>("WEBSITE_HOSTNAME");
            var protocol = hostname.StartsWith("localhost") ? "http" : "https";

            builder.ConfigurationBuilder.AddInMemoryCollection(new[] { new KeyValuePair <string, string>("SkillHostEndpoint", $"{protocol}://{hostname}/api") });
        }
Exemple #7
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .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()
            .Build();
        }
Exemple #8
0
        //FunctionsStartup
        //NOTE: https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-dotnet-dependency-injection
        //NOTE: https://blog.shibayan.jp/entry/20200823/1598186591
        //NOTE: https://stackoverflow.com/questions/57564396/how-do-i-mix-custom-parameter-binding-with-dependency-injection-in-azure-functio

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

            builder.ConfigurationBuilder
            .SetBasePath(context.ApplicationRootPath)
            .AddJsonFile("appSettings.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();
        }
Exemple #9
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
            .AddUserSecrets(Assembly.GetExecutingAssembly(), false)
            .AddEnvironmentVariables();
            base.ConfigureAppConfiguration(builder);
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            // Note that these files are not automatically copied on build or publish.
            // See the csproj file to for the correct setup.
            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false);
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var ctx = builder.GetContext();

            Configuration = builder.ConfigurationBuilder
                            .AddJsonFile(Path.Combine(ctx.ApplicationRootPath, "local.settings.json"), true, true)
                            .AddJsonFile(Path.Combine(ctx.ApplicationRootPath, "appsettings.json"), false, true)
                            .AddUserSecrets(Assembly.GetExecutingAssembly(), true, true)
                            .AddEnvironmentVariables()
                            .Build();
        }
Exemple #12
0
        /// <summary>
        /// Creates an <see cref="IConfiguration"/> instance and attaches to an `appsettings.json` file, also adding an `appsettings.{environment}.json` on top of it, if available, based on current AZURE_FUNCTIONS_ENVIRONMENT environment variable.
        /// </summary>
        /// <param name="builder">An instance of <see cref="IFunctionsConfigurationBuilder"/>.</param>
        /// <param name="reloadOnChange">Whether the configuration should be reloaded on file change.</param>
        /// <returns>The <see cref="IFunctionsConfigurationBuilder"/>.</returns>
        public static IFunctionsConfigurationBuilder UseAppSettings(this IFunctionsConfigurationBuilder builder, bool reloadOnChange = false)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: reloadOnChange)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{builder.GetCurrentEnvironmentName()}.json"), optional: true, reloadOnChange: reloadOnChange)
            .AddEnvironmentVariables();

            return(builder);
        }
Exemple #13
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .SetBasePath(context.ApplicationRootPath)
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{context.EnvironmentName}.json", optional: true)
            .AddJsonFile("local.settings.json", optional: true)
            .Build();
        }
Exemple #14
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(System.IO.Path.Combine(context.ApplicationRootPath, "local.settings.json"), true)
            .AddJsonFile(System.IO.Path.Combine(context.ApplicationRootPath, "localization.json"))
            .AddJsonFile(System.IO.Path.Combine(context.ApplicationRootPath, "wellknown.json"))
            .AddEnvironmentVariables()
            .Build();
        }
Exemple #15
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
            //.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("AZMAN-AAC-CONNECTION"), optional: true)
            //.AddUserSecrets(Assembly.GetExecutingAssembly(), true)
            .AddEnvironmentVariables();
        }
Exemple #16
0
    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var context = builder.GetContext();

        _environmentName = context.EnvironmentName;

        if (_environmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
        {
            builder.ConfigurationBuilder.AddUserSecrets <Startup>();
        }

        _configuration = builder.ConfigurationBuilder.Build();
    }
Exemple #17
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder configurationBuilder)
        {
            FunctionsHostBuilderContext context = configurationBuilder.GetContext();

            string applicationRoot   = context.ApplicationRootPath;
            string environmentName   = context.EnvironmentName;
            string settingsDirectory = "settings";

            configurationBuilder.ConfigurationBuilder.AddBotRuntimeConfiguration(
                applicationRoot,
                settingsDirectory,
                environmentName);
        }
        //override ConfigurationBuilder Settings if you want
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            //Overrideden behavior read from, appsettings.json
            FunctionsHostBuilderContext context = builder.GetContext();

            builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: false, reloadOnChange: true)
            //Adding Environmental Files //add Conditions
            //.AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
            .AddEnvironmentVariables();

            //Default behavior read from local.settings.json
            //base.ConfigureAppConfiguration(builder);
        }
        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();
        }
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            FunctionsHostBuilderContext context = builder.GetContext();

            _ = builder.ConfigurationBuilder
                .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), true, false)
                .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), true, false)
                .AddEnvironmentVariables();

#if DEBUG
            if ("development".Equals(context.EnvironmentName, System.StringComparison.CurrentCultureIgnoreCase))
            {
                _ = builder.ConfigurationBuilder.AddUserSecrets <Startup>();
            }
#endif
        }
Exemple #21
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();
        }
Exemple #23
0
        public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {
            var config = builder.GetContext().Configuration;

            // 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);
            });
        }
Exemple #24
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();
        }
 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;
     }
 }
        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();
        }
Exemple #27
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);
                }
            }
        }
Exemple #28
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);
        }
Exemple #29
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();
        }
Exemple #30
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));
 }