From ed1e4db4f27b6306854e1408ae399ae3b975959b Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 14:52:13 +0100 Subject: [PATCH 1/8] Minor formatting changes --- Readme.md | 5 +++-- .../ParameterStoreConfigurationProvider.cs | 9 ++++----- .../ParameterStoreConfigurationSource.cs | 4 ++-- .../ParameterStoreExtension.cs | 4 ++-- src/example-api/Startup.cs | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Readme.md b/Readme.md index e551a01..0166a66 100644 --- a/Readme.md +++ b/Readme.md @@ -9,7 +9,7 @@ Example configuration for a asp.net core project: public static IWebHost BuildWebHost(string[] args) { - + return WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostContext, config)=> { @@ -42,6 +42,7 @@ Example configuration for a asp.net core project: } # Alternatively + You can also use parameterStoreConfig.UseDefaultCredentials = true; to let AWS handle this. # Finding your way in the solution @@ -55,7 +56,7 @@ To use the provided samples you have to will have to setup 3 parameters in the P /somenamespace/someotherkey /somenamespace/somesecurekey => This needs to be set up as a secure string, which requires a KMS-Encryption key -You will also have set up and save a local default aws profile on the computer if you want to use StoredProfileAWSCredentials as it is used +You will also have set up and save a local default aws profile on the computer if you want to use StoredProfileAWSCredentials as it is used in the example above (see http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) # ParameterStore on AWS diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs index 20bdb90..dfd09f1 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs @@ -1,9 +1,9 @@ -using Amazon.SimpleSystemsManagement; +using System; +using System.Collections.Generic; +using System.Linq; +using Amazon.SimpleSystemsManagement; using Amazon.SimpleSystemsManagement.Model; using Microsoft.Extensions.Configuration; -using System.Linq; -using System; -using System.Collections.Generic; namespace ParameterStoreConfigurationProvider { @@ -32,7 +32,6 @@ public override void Load() { using (var client = new AmazonSimpleSystemsManagementClient(this.configurationSource.AwsCredential, Amazon.RegionEndpoint.GetBySystemName(this.configurationSource.Region))) { - responses = MappingClientResponseToData(client); } } diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationSource.cs b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationSource.cs index 97c4814..eda2f52 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationSource.cs +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationSource.cs @@ -1,6 +1,6 @@ -using Amazon.Runtime; +using System.Collections.Generic; +using Amazon.Runtime; using Microsoft.Extensions.Configuration; -using System.Collections.Generic; namespace ParameterStoreConfigurationProvider { diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreExtension.cs b/src/ParameterStoreConfigurationProvider/ParameterStoreExtension.cs index 3c3f1fb..69707db 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreExtension.cs +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreExtension.cs @@ -1,5 +1,5 @@ -using Microsoft.Extensions.Configuration; -using System; +using System; +using Microsoft.Extensions.Configuration; namespace ParameterStoreConfigurationProvider { diff --git a/src/example-api/Startup.cs b/src/example-api/Startup.cs index 6c1ad62..b6af7ff 100644 --- a/src/example-api/Startup.cs +++ b/src/example-api/Startup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -15,7 +15,7 @@ public class Startup { public Startup(IConfiguration configuration) { - Configuration = configuration; + Configuration = configuration; } public IConfiguration Configuration { get; } From ad7ecdf4ea9f9d932527f1475fea3c603a729ca9 Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 17:41:31 +0100 Subject: [PATCH 2/8] Updated unit tests to use UseDefaultCredentials --- test/example-api-test/ConfigurationTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/example-api-test/ConfigurationTest.cs b/test/example-api-test/ConfigurationTest.cs index a4c9f70..6e611a1 100644 --- a/test/example-api-test/ConfigurationTest.cs +++ b/test/example-api-test/ConfigurationTest.cs @@ -100,7 +100,7 @@ private void SetupValidServer() } }; parameterStoreConfig.Region = "eu-west-1"; - parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); + parameterStoreConfig.UseDefaultCredentials = true; }) .AddParameterStoreConfig(parameterStoreConfig => { @@ -127,7 +127,7 @@ private void SetupValidServer() }; parameterStoreConfig.WithDecryption = true; parameterStoreConfig.Region = "eu-west-1"; - parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); + parameterStoreConfig.UseDefaultCredentials = true; }); var config = builder.Build(); @@ -172,7 +172,7 @@ private void SetupInvalidServer() }; parameterStoreConfig.WithDecryption = true; parameterStoreConfig.Region = "eu-west-1"; - parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); + parameterStoreConfig.UseDefaultCredentials = true; }); var config = builder.Build(); From c6284f7ba2e1329d3c3586fbbb1450e0dd2daa93 Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 19:12:43 +0100 Subject: [PATCH 3/8] Update of readme and minor cleanup --- .vscode/tasks.json | 2 +- Readme.md | 13 ++++++------- src/example-api/Controllers/ValuesController.cs | 3 --- src/example-api/Program.cs | 9 ++------- src/example-api/Startup.cs | 6 ------ 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4166009..4cdf972 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,7 +2,7 @@ "version": "2.0.0", "tasks": [ { - "taskName": "build", + "label": "build", "command": "dotnet", "type": "process", "args": [ diff --git a/Readme.md b/Readme.md index 0166a66..ecdbb56 100644 --- a/Readme.md +++ b/Readme.md @@ -5,13 +5,13 @@ Enrich your configuration with plain text or secure settings from AWS ParameterS ## Example -Example configuration for a asp.net core project: +Example configuration for an ASP.Net Core project: public static IWebHost BuildWebHost(string[] args) { return WebHost.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostContext, config)=> + .ConfigureAppConfiguration((hostContext, config) => { config.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) @@ -47,8 +47,8 @@ You can also use parameterStoreConfig.UseDefaultCredentials = true; to let AWS h # Finding your way in the solution -in /src you find two projects, one example-api and the src for the nuget package itself -in /test you find the unittests +In /src you find two projects, one example-api and the src for the nuget package itself +In /test you find the unit tests To use the provided samples you have to will have to setup 3 parameters in the ParameterStore @@ -56,9 +56,8 @@ To use the provided samples you have to will have to setup 3 parameters in the P /somenamespace/someotherkey /somenamespace/somesecurekey => This needs to be set up as a secure string, which requires a KMS-Encryption key -You will also have set up and save a local default aws profile on the computer if you want to use StoredProfileAWSCredentials as it is used -in the example above (see http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) +You will also have set up and save a local default aws profile on the computer if you want to use StoredProfileAWSCredentials as it is used in the example above (see http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) # ParameterStore on AWS -see: http://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html +For reference see the [Parameter Store documentation on AWS](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) diff --git a/src/example-api/Controllers/ValuesController.cs b/src/example-api/Controllers/ValuesController.cs index f2bf7a0..ce66318 100644 --- a/src/example-api/Controllers/ValuesController.cs +++ b/src/example-api/Controllers/ValuesController.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; diff --git a/src/example-api/Program.cs b/src/example-api/Program.cs index f9c77ee..57955db 100644 --- a/src/example-api/Program.cs +++ b/src/example-api/Program.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using ParameterStoreConfigurationProvider; namespace example_api @@ -20,9 +16,8 @@ public static void Main(string[] args) public static IWebHost BuildWebHost(string[] args) { - return WebHost.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostContext, config)=> + .ConfigureAppConfiguration((hostContext, config) => { config.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) diff --git a/src/example-api/Startup.cs b/src/example-api/Startup.cs index b6af7ff..9548d02 100644 --- a/src/example-api/Startup.cs +++ b/src/example-api/Startup.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; namespace example_api { From 10df3bda4233854cae59a83429e50651f60b4060 Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 19:20:54 +0100 Subject: [PATCH 4/8] Upgraded nuget to netstandard2.0 Bumped internal dependencies Some minor code improvements --- .../ParameterStoreConfigurationProvider.cs | 36 +++++++++---------- ...ParameterStoreConfigurationProvider.csproj | 15 ++++---- src/example-api/example-api.csproj | 2 -- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs index dfd09f1..add5026 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs @@ -7,30 +7,29 @@ namespace ParameterStoreConfigurationProvider { - public class ParameterStoreConfigurationProvider : ConfigurationProvider { - private readonly ParameterStoreConfigurationSource configurationSource; + private readonly ParameterStoreConfigurationSource _configurationSource; public ParameterStoreConfigurationProvider(ParameterStoreConfigurationSource configurationSource) { - this.configurationSource = configurationSource; + _configurationSource = configurationSource; } public override void Load() { IEnumerable responses; - if (this.configurationSource.UseDefaultCredentials) + if (_configurationSource.UseDefaultCredentials) { - using (var client = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(this.configurationSource.Region))) + using (var client = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(_configurationSource.Region))) { responses = MappingClientResponseToData(client); } } else { - using (var client = new AmazonSimpleSystemsManagementClient(this.configurationSource.AwsCredential, Amazon.RegionEndpoint.GetBySystemName(this.configurationSource.Region))) + using (var client = new AmazonSimpleSystemsManagementClient(_configurationSource.AwsCredential, Amazon.RegionEndpoint.GetBySystemName(_configurationSource.Region))) { responses = MappingClientResponseToData(client); } @@ -39,9 +38,9 @@ public override void Load() MapResults(responses); } - private IEnumerable MappingClientResponseToData(AmazonSimpleSystemsManagementClient client) + private IEnumerable MappingClientResponseToData(IAmazonSimpleSystemsManagement client) { - IEnumerable requests = PrepareRequests(); + var requests = PrepareRequests(); IList responses = new List(); foreach (var request in requests) @@ -57,8 +56,9 @@ private IEnumerable MappingClientResponseToData(AmazonSim private void CheckParametersValidity(GetParametersResponse response) { var requiredInvalidParameters = response.InvalidParameters.Where(item => - this.configurationSource.ParameterMapping.First(pm => + _configurationSource.ParameterMapping.First(pm => pm.AwsName == item).Optional == false).ToList(); + if (requiredInvalidParameters.Count > 0) { var wrongParams = ""; @@ -71,9 +71,9 @@ private void CheckParametersValidity(GetParametersResponse response) } } - internal IEnumerable PrepareRequests() + private IEnumerable PrepareRequests() { - var names = this.configurationSource.ParameterMapping.Select(x => x.AwsName).ToList(); + var names = _configurationSource.ParameterMapping.Select(x => x.AwsName).ToList(); const int groupSize = 10; var requests = names @@ -82,30 +82,30 @@ internal IEnumerable PrepareRequests() .Select(g => new GetParametersRequest { Names = g.ToList(), - WithDecryption = this.configurationSource.WithDecryption + WithDecryption = _configurationSource.WithDecryption }); return requests; } - internal void MapResults(IEnumerable responses) + private void MapResults(IEnumerable responses) { - this.Data = new Dictionary(); + Data = new Dictionary(); foreach (var response in responses) { foreach (var parameter in response.Parameters) { var parameterMapping = - this.configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter.Name); - this.Data[parameterMapping.SettingName] = parameter.Value; + _configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter.Name); + Data[parameterMapping.SettingName] = parameter.Value; } foreach (var parameter in response.InvalidParameters) { var parameterMapping = - this.configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter); - this.Data[parameterMapping.SettingName] = parameterMapping.Default; + _configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter); + Data[parameterMapping.SettingName] = parameterMapping.Default; } } } diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj index 53d3975..826f870 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj @@ -1,21 +1,20 @@  - netcoreapp2.0 + netstandard2.0 true - Use AWS ParameterStore to configure your .net core project + Use AWS ParameterStore to configure your .Net project https://github.com/schwamster/ParameterStoreConfigurationProvider - https://github.com/schwamster/ParameterStoreConfigurationProvider/blob/master/LICENSE + MIT Bastian Töpfer AWS ParameterStore Configuration - 1.1.0 + 2.0.0 - - - - + + + diff --git a/src/example-api/example-api.csproj b/src/example-api/example-api.csproj index 67d164d..24fa118 100644 --- a/src/example-api/example-api.csproj +++ b/src/example-api/example-api.csproj @@ -9,8 +9,6 @@ - - From 2976a42003685464f41599a51f03df98fc7cc275 Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 21:01:48 +0100 Subject: [PATCH 5/8] Upgrade example-api and example-api-test to netcoreapp3.1 --- .vscode/launch.json | 2 +- ...Controller.cs => ConfigurationController.cs} | 13 +++++++------ src/example-api/Program.cs | 17 ++++++++++------- src/example-api/Startup.cs | 16 ++++++++++++---- src/example-api/appsettings.Development.json | 7 +++---- src/example-api/appsettings.json | 15 +++++---------- src/example-api/example-api.csproj | 15 ++------------- test/example-api-test/ConfigurationTest.cs | 8 ++++---- test/example-api-test/appsettings.json | 15 +++++---------- test/example-api-test/example-api-test.csproj | 17 ++++++++++++----- 10 files changed, 61 insertions(+), 64 deletions(-) rename src/example-api/Controllers/{ValuesController.cs => ConfigurationController.cs} (57%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3a9238a..e56041a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/example-api/bin/Debug/netcoreapp2.0/example-api.dll", + "program": "${workspaceFolder}/src/example-api/bin/Debug/netcoreapp3.1/example-api.dll", "args": [], "cwd": "${workspaceFolder}/src/example-api", "stopAtEntry": false, diff --git a/src/example-api/Controllers/ValuesController.cs b/src/example-api/Controllers/ConfigurationController.cs similarity index 57% rename from src/example-api/Controllers/ValuesController.cs rename to src/example-api/Controllers/ConfigurationController.cs index ce66318..224a2d3 100644 --- a/src/example-api/Controllers/ValuesController.cs +++ b/src/example-api/Controllers/ConfigurationController.cs @@ -4,21 +4,22 @@ namespace example_api.Controllers { - [Route("api/[controller]")] - public class ConfigurationController : Controller + [ApiController] + [Route("[controller]")] + public class ConfigurationController : ControllerBase { - private readonly IConfiguration configuration; + private readonly IConfiguration _configuration; public ConfigurationController(IConfiguration configuration) { - this.configuration = configuration; + _configuration = configuration; } - // GET api/values/5 + // GET Configuration/key [HttpGet("{key}")] public string Get(string key) { - var value = configuration[key]; + var value = _configuration[key]; Console.WriteLine($"configuration: {value}"); return value ?? "***ValueWasNull***"; } diff --git a/src/example-api/Program.cs b/src/example-api/Program.cs index 57955db..9a9e3d7 100644 --- a/src/example-api/Program.cs +++ b/src/example-api/Program.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.IO; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using ParameterStoreConfigurationProvider; namespace example_api @@ -11,12 +11,12 @@ public class Program { public static void Main(string[] args) { - BuildWebHost(args).Run(); + BuildHost(args).Run(); } - public static IWebHost BuildWebHost(string[] args) + public static IHost BuildHost(string[] args) { - return WebHost.CreateDefaultBuilder(args) + return Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostContext, config) => { config.SetBasePath(Directory.GetCurrentDirectory()) @@ -31,7 +31,7 @@ public static IWebHost BuildWebHost(string[] args) }; parameterStoreConfig.Region = "eu-west-1"; parameterStoreConfig.UseDefaultCredentials = true; - // parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); + // parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); }) .AddParameterStoreConfig(parameterStoreConfig => { @@ -42,10 +42,13 @@ public static IWebHost BuildWebHost(string[] args) parameterStoreConfig.WithDecryption = true; parameterStoreConfig.Region = "eu-west-1"; parameterStoreConfig.UseDefaultCredentials = true; - // parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); + // parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); }); }) - .UseStartup() + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) .Build(); } } diff --git a/src/example-api/Startup.cs b/src/example-api/Startup.cs index 9548d02..dcdaa16 100644 --- a/src/example-api/Startup.cs +++ b/src/example-api/Startup.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace example_api { @@ -17,18 +18,25 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } - app.UseMvc(); + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); } } -} +} \ No newline at end of file diff --git a/src/example-api/appsettings.Development.json b/src/example-api/appsettings.Development.json index f334029..33dc90f 100644 --- a/src/example-api/appsettings.Development.json +++ b/src/example-api/appsettings.Development.json @@ -1,10 +1,9 @@ { "Logging": { - "IncludeScopes": false, "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } } } diff --git a/src/example-api/appsettings.json b/src/example-api/appsettings.json index e5bef9a..a456eed 100644 --- a/src/example-api/appsettings.json +++ b/src/example-api/appsettings.json @@ -1,16 +1,11 @@ { "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } }, + "AllowedHosts": "*", "somekey": "blup" } diff --git a/src/example-api/example-api.csproj b/src/example-api/example-api.csproj index 24fa118..a7ed759 100644 --- a/src/example-api/example-api.csproj +++ b/src/example-api/example-api.csproj @@ -1,21 +1,10 @@ - netcoreapp2.0 + netcoreapp3.1 + example-api - - - - - - - - - - - - diff --git a/test/example-api-test/ConfigurationTest.cs b/test/example-api-test/ConfigurationTest.cs index 6e611a1..9fd16ad 100644 --- a/test/example-api-test/ConfigurationTest.cs +++ b/test/example-api-test/ConfigurationTest.cs @@ -21,7 +21,7 @@ public async System.Threading.Tasks.Task PipelineSetupTestAsync_GetRegularSettin { // Act SetupValidServer(); - var response = await _client.GetAsync("/api/Configuration/somekey"); + var response = await _client.GetAsync("/Configuration/somekey"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); @@ -36,7 +36,7 @@ public async System.Threading.Tasks.Task PipelineSetupTestAsync_GetSecureSetting { // Act SetupValidServer(); - var response = await _client.GetAsync("/api/Configuration/somesecurekey"); + var response = await _client.GetAsync("/Configuration/somesecurekey"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); @@ -50,7 +50,7 @@ public async System.Threading.Tasks.Task PipelineSetupTestAsync_GetDefaultSettin { // Act SetupValidServer(); - var response = await _client.GetAsync("/api/Configuration/nonexistantkey"); + var response = await _client.GetAsync("/Configuration/nonexistantkey"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); @@ -64,7 +64,7 @@ public async System.Threading.Tasks.Task PipelineSetupTestAsync_GetNullDefaultSe { // Act SetupValidServer(); - var response = await _client.GetAsync("/api/Configuration/anothernonexistantkey"); + var response = await _client.GetAsync("/Configuration/anothernonexistantkey"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); diff --git a/test/example-api-test/appsettings.json b/test/example-api-test/appsettings.json index e5bef9a..a456eed 100644 --- a/test/example-api-test/appsettings.json +++ b/test/example-api-test/appsettings.json @@ -1,16 +1,11 @@ { "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } }, + "AllowedHosts": "*", "somekey": "blup" } diff --git a/test/example-api-test/example-api-test.csproj b/test/example-api-test/example-api-test.csproj index 80842ab..02c2d0f 100644 --- a/test/example-api-test/example-api-test.csproj +++ b/test/example-api-test/example-api-test.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp3.1 false @@ -14,10 +14,17 @@ - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + From 687e7498ba22f1bbdb23149bded565cacb9558fb Mon Sep 17 00:00:00 2001 From: PolaricEntropy Date: Sat, 10 Dec 2022 21:24:23 +0100 Subject: [PATCH 6/8] Updated example in readme to correspond with the example code --- Readme.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index ecdbb56..f273c84 100644 --- a/Readme.md +++ b/Readme.md @@ -7,10 +7,9 @@ Enrich your configuration with plain text or secure settings from AWS ParameterS Example configuration for an ASP.Net Core project: - public static IWebHost BuildWebHost(string[] args) + public static IHost BuildHost(string[] args) { - - return WebHost.CreateDefaultBuilder(args) + return Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostContext, config) => { config.SetBasePath(Directory.GetCurrentDirectory()) @@ -37,7 +36,10 @@ Example configuration for an ASP.Net Core project: parameterStoreConfig.AwsCredential = new Amazon.Runtime.StoredProfileAWSCredentials(); }); }) - .UseStartup() + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) .Build(); } From ea4767b95a39a08095bfbea7060c25aedbbd0832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ehrby?= Date: Fri, 24 Feb 2023 15:57:46 +0100 Subject: [PATCH 7/8] Revert underscore change of private members. --- .../ParameterStoreConfigurationProvider.cs | 20 +++++++++---------- .../Controllers/ConfigurationController.cs | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs index add5026..3f157ce 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.cs @@ -9,27 +9,27 @@ namespace ParameterStoreConfigurationProvider { public class ParameterStoreConfigurationProvider : ConfigurationProvider { - private readonly ParameterStoreConfigurationSource _configurationSource; + private readonly ParameterStoreConfigurationSource configurationSource; public ParameterStoreConfigurationProvider(ParameterStoreConfigurationSource configurationSource) { - _configurationSource = configurationSource; + this.configurationSource = configurationSource; } public override void Load() { IEnumerable responses; - if (_configurationSource.UseDefaultCredentials) + if (configurationSource.UseDefaultCredentials) { - using (var client = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(_configurationSource.Region))) + using (var client = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(configurationSource.Region))) { responses = MappingClientResponseToData(client); } } else { - using (var client = new AmazonSimpleSystemsManagementClient(_configurationSource.AwsCredential, Amazon.RegionEndpoint.GetBySystemName(_configurationSource.Region))) + using (var client = new AmazonSimpleSystemsManagementClient(configurationSource.AwsCredential, Amazon.RegionEndpoint.GetBySystemName(configurationSource.Region))) { responses = MappingClientResponseToData(client); } @@ -56,7 +56,7 @@ private IEnumerable MappingClientResponseToData(IAmazonSi private void CheckParametersValidity(GetParametersResponse response) { var requiredInvalidParameters = response.InvalidParameters.Where(item => - _configurationSource.ParameterMapping.First(pm => + configurationSource.ParameterMapping.First(pm => pm.AwsName == item).Optional == false).ToList(); if (requiredInvalidParameters.Count > 0) @@ -73,7 +73,7 @@ private void CheckParametersValidity(GetParametersResponse response) private IEnumerable PrepareRequests() { - var names = _configurationSource.ParameterMapping.Select(x => x.AwsName).ToList(); + var names = configurationSource.ParameterMapping.Select(x => x.AwsName).ToList(); const int groupSize = 10; var requests = names @@ -82,7 +82,7 @@ private IEnumerable PrepareRequests() .Select(g => new GetParametersRequest { Names = g.ToList(), - WithDecryption = _configurationSource.WithDecryption + WithDecryption = configurationSource.WithDecryption }); return requests; @@ -97,14 +97,14 @@ private void MapResults(IEnumerable responses) foreach (var parameter in response.Parameters) { var parameterMapping = - _configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter.Name); + configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter.Name); Data[parameterMapping.SettingName] = parameter.Value; } foreach (var parameter in response.InvalidParameters) { var parameterMapping = - _configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter); + configurationSource.ParameterMapping.First(pm => pm.AwsName == parameter); Data[parameterMapping.SettingName] = parameterMapping.Default; } } diff --git a/src/example-api/Controllers/ConfigurationController.cs b/src/example-api/Controllers/ConfigurationController.cs index 224a2d3..8c3f9b5 100644 --- a/src/example-api/Controllers/ConfigurationController.cs +++ b/src/example-api/Controllers/ConfigurationController.cs @@ -8,18 +8,18 @@ namespace example_api.Controllers [Route("[controller]")] public class ConfigurationController : ControllerBase { - private readonly IConfiguration _configuration; + private readonly IConfiguration configuration; public ConfigurationController(IConfiguration configuration) { - _configuration = configuration; + this.configuration = configuration; } // GET Configuration/key [HttpGet("{key}")] public string Get(string key) { - var value = _configuration[key]; + var value = configuration[key]; Console.WriteLine($"configuration: {value}"); return value ?? "***ValueWasNull***"; } From 0e8ab5ebb60046b14961bb4ef1a07b7902fb84d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ehrby?= Date: Sun, 26 Feb 2023 16:37:27 +0100 Subject: [PATCH 8/8] Updated dependencies --- .../ParameterStoreConfigurationProvider.csproj | 6 +++--- test/example-api-test/example-api-test.csproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj index 826f870..d0b0674 100644 --- a/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj +++ b/src/ParameterStoreConfigurationProvider/ParameterStoreConfigurationProvider.csproj @@ -12,9 +12,9 @@ - - - + + + diff --git a/test/example-api-test/example-api-test.csproj b/test/example-api-test/example-api-test.csproj index 02c2d0f..4dcf693 100644 --- a/test/example-api-test/example-api-test.csproj +++ b/test/example-api-test/example-api-test.csproj @@ -14,14 +14,14 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all