From bf69a5dcdbb6c7977eb9b7e00f82f9d12edb6f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DELAGE=20Rapha=C3=ABl?= <36408929+delager@users.noreply.github.com> Date: Wed, 22 Mar 2023 19:32:35 +0100 Subject: [PATCH] Add AWS configuration in ConfigHandler (#1948) --- src/AzureIoTHub.Portal.Domain/ConfigHandler.cs | 3 +++ .../ConfigHandlerBase.cs | 4 ++++ .../DevelopmentConfigHandler.cs | 6 +++++- .../ProductionConfigHandler.cs | 10 +++++++--- .../Infrastructure/DevelopmentConfigHandlerTests.cs | 3 +++ .../Infrastructure/ProductionConfigHandlerTests.cs | 3 +++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs index d66ca86c8..5409d29a9 100644 --- a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs @@ -74,5 +74,8 @@ public abstract class ConfigHandler public abstract string MySQLConnectionString { get; } public abstract string DbProvider { get; } + public abstract string AWSAccess { get; } + public abstract string AWSAccessSecret { get; } + public abstract string AWSRegion { get; } } } diff --git a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs index 0b3fc80bf..515bb4ca7 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs @@ -49,5 +49,9 @@ internal abstract class ConfigHandlerBase : ConfigHandler internal const string IdeasUrlKey = "Ideas:Url"; internal const string IdeasAuthenticationHeaderKey = "Ideas:Authentication:Header"; internal const string IdeasAuthenticationTokenKey = "Ideas:Authentication:Token"; + + internal const string AWSAccessKey = "AWS:Access"; + internal const string AWSAccessSecretKey = "AWS:AccessSecret"; + internal const string AWSRegionKey = "AWS:Region"; } } diff --git a/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs b/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs index bb0a4e0e2..1e9cdb170 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs @@ -80,6 +80,10 @@ internal DevelopmentConfigHandler(IConfiguration config) public override string MySQLConnectionString => this.config[MySQLConnectionStringKey]!; - public override string DbProvider => this.config.GetValue(DbProviderKey, DbProviders.PostgreSQL)!; + public override string DbProvider => this.config.GetValue(DbProviderKey, DbProviders.PostgreSQL); + + public override string AWSAccess => this.config[AWSAccessKey]; + public override string AWSAccessSecret => this.config[AWSAccessSecretKey]; + public override string AWSRegion => this.config[AWSRegionKey]; } } diff --git a/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs b/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs index 850d7e98d..b0f253f79 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs @@ -78,8 +78,12 @@ internal ProductionConfigHandler(IConfiguration config) public override string LoRaKeyManagementApiVersion => this.config[LoRaKeyManagementApiVersionKey]!; public override bool IdeasEnabled => this.config.GetValue(IdeasEnabledKey, false); - public override string IdeasUrl => this.config.GetValue(IdeasUrlKey, string.Empty)!; - public override string IdeasAuthenticationHeader => this.config.GetValue(IdeasAuthenticationHeaderKey, "Ocp-Apim-Subscription-Key")!; - public override string IdeasAuthenticationToken => this.config.GetValue(IdeasAuthenticationTokenKey, string.Empty)!; + public override string IdeasUrl => this.config.GetValue(IdeasUrlKey, string.Empty); + public override string IdeasAuthenticationHeader => this.config.GetValue(IdeasAuthenticationHeaderKey, "Ocp-Apim-Subscription-Key"); + public override string IdeasAuthenticationToken => this.config.GetValue(IdeasAuthenticationTokenKey, string.Empty); + + public override string AWSAccess => this.config[AWSAccessKey]; + public override string AWSAccessSecret => this.config[AWSAccessSecretKey]; + public override string AWSRegion => this.config[AWSRegionKey]; } } diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs index 830c4c66e..5ed5eedc8 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs @@ -48,6 +48,9 @@ private DevelopmentConfigHandler CreateDevelopmentConfigHandler() [TestCase(ConfigHandlerBase.StorageAccountConnectionStringKey, nameof(ConfigHandlerBase.StorageAccountConnectionString))] [TestCase(ConfigHandlerBase.PostgreSQLConnectionStringKey, nameof(ConfigHandlerBase.PostgreSQLConnectionString))] [TestCase(ConfigHandlerBase.MySQLConnectionStringKey, nameof(ConfigHandlerBase.MySQLConnectionString))] + [TestCase(ConfigHandlerBase.AWSAccessKey, nameof(ConfigHandlerBase.AWSAccess))] + [TestCase(ConfigHandlerBase.AWSAccessSecretKey, nameof(ConfigHandlerBase.AWSAccessSecret))] + [TestCase(ConfigHandlerBase.AWSRegionKey, nameof(ConfigHandlerBase.AWSRegion))] public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName) { // Arrange diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs index 49aeb9999..df3eae374 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs @@ -73,6 +73,9 @@ public void SecretsShouldGetValueFromConnectionStrings(string configKey, string [TestCase(ConfigHandlerBase.OIDCApiClientIdKey, nameof(ConfigHandlerBase.OIDCApiClientId))] [TestCase(ConfigHandlerBase.LoRaKeyManagementUrlKey, nameof(ConfigHandlerBase.LoRaKeyManagementUrl))] [TestCase(ConfigHandlerBase.LoRaKeyManagementApiVersionKey, nameof(ConfigHandlerBase.LoRaKeyManagementApiVersion))] + [TestCase(ConfigHandlerBase.AWSAccessKey, nameof(ConfigHandlerBase.AWSAccess))] + [TestCase(ConfigHandlerBase.AWSAccessSecretKey, nameof(ConfigHandlerBase.AWSAccessSecret))] + [TestCase(ConfigHandlerBase.AWSRegionKey, nameof(ConfigHandlerBase.AWSRegion))] public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName) { // Arrange