diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index e62d8e476..3461f2a13 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -111,6 +111,8 @@ jobs: IOTHUB__EVENTHUB__ENDPOINT: ${{ secrets.IOTHUB__EVENTHUB__ENDPOINT }} LORAKEYMANAGEMENT__CODE: ${{ secrets.LORAKEYMANAGEMENT__CODE }} IDEAS__AUTHENTICATION__TOKEN: ${{ secrets.IDEAS__AUTHENTICATION__TOKEN }} + + CLOUDPROVIDER: Azure - name: Wait until portal is up run: | diff --git a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs index 5409d29a9..957f41ed6 100644 --- a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs @@ -74,6 +74,7 @@ public abstract class ConfigHandler public abstract string MySQLConnectionString { get; } public abstract string DbProvider { get; } + public abstract string CloudProvider { get; } public abstract string AWSAccess { get; } public abstract string AWSAccessSecret { get; } public abstract string AWSRegion { get; } diff --git a/src/AzureIoTHub.Portal.Domain/Shared/Constants/CloudProviders.cs b/src/AzureIoTHub.Portal.Domain/Shared/Constants/CloudProviders.cs new file mode 100644 index 000000000..c3a50d661 --- /dev/null +++ b/src/AzureIoTHub.Portal.Domain/Shared/Constants/CloudProviders.cs @@ -0,0 +1,13 @@ +// Copyright (c) CGI France. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace AzureIoTHub.Portal.Domain.Shared.Constants +{ + + public static class CloudProviders + { + public const string Azure = "Azure"; + + public const string AWS = "AWS"; + } +} diff --git a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs index 515bb4ca7..fe173c382 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs @@ -50,6 +50,8 @@ internal abstract class ConfigHandlerBase : ConfigHandler internal const string IdeasAuthenticationHeaderKey = "Ideas:Authentication:Header"; internal const string IdeasAuthenticationTokenKey = "Ideas:Authentication:Token"; + internal const string CloudProviderKey = "CloudProvider"; + 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 1e9cdb170..2dd64285f 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs @@ -82,6 +82,8 @@ internal DevelopmentConfigHandler(IConfiguration config) public override string DbProvider => this.config.GetValue(DbProviderKey, DbProviders.PostgreSQL); + public override string CloudProvider => this.config[CloudProviderKey]; + 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 b0f253f79..ba04bd317 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs @@ -82,6 +82,8 @@ internal ProductionConfigHandler(IConfiguration config) 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 CloudProvider => this.config[CloudProviderKey]; + 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.Server/AzureIoTHub.Portal.Server.csproj b/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj index 2e7c83a28..a52adf6ca 100644 --- a/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj +++ b/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj @@ -34,7 +34,9 @@ - + + + diff --git a/src/AzureIoTHub.Portal.Server/Startup.cs b/src/AzureIoTHub.Portal.Server/Startup.cs index eee420db3..ce066c009 100644 --- a/src/AzureIoTHub.Portal.Server/Startup.cs +++ b/src/AzureIoTHub.Portal.Server/Startup.cs @@ -6,6 +6,9 @@ namespace AzureIoTHub.Portal.Server using System; using System.IO; using System.Threading.Tasks; + using Amazon; + using Amazon.IoT; + using Amazon.IotData; using AzureIoTHub.Portal.Application.Managers; using AzureIoTHub.Portal.Application.Services; using AzureIoTHub.Portal.Application.Startup; @@ -77,6 +80,23 @@ public void ConfigureServices(IServiceCollection services) _ = services.AddSingleton(new PortalMetric()); _ = services.AddSingleton(new LoRaGatewayIDList()); + if (configuration.CloudProvider.Equals(CloudProviders.AWS, StringComparison.Ordinal)) + { + _ = services.AddSingleton(() => new AmazonIoTClient(configuration.AWSAccess, configuration.AWSAccessSecret, RegionEndpoint.GetBySystemName(configuration.AWSRegion))); + _ = services.AddSingleton(async sp => + { + var endpoint = await sp.GetService().DescribeEndpointAsync(new Amazon.IoT.Model.DescribeEndpointRequest + { + EndpointType = "iot:Data-ATS" + }); + + return new AmazonIotDataClient(configuration.AWSAccess, configuration.AWSAccessSecret, new AmazonIotDataConfig + { + ServiceURL = $"https://{endpoint.EndpointAddress}" + }); + }); + } + _ = services.AddRazorPages(); _ = services.AddTransient(); diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs index 5ed5eedc8..bb62f55ce 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs @@ -51,6 +51,7 @@ private DevelopmentConfigHandler CreateDevelopmentConfigHandler() [TestCase(ConfigHandlerBase.AWSAccessKey, nameof(ConfigHandlerBase.AWSAccess))] [TestCase(ConfigHandlerBase.AWSAccessSecretKey, nameof(ConfigHandlerBase.AWSAccessSecret))] [TestCase(ConfigHandlerBase.AWSRegionKey, nameof(ConfigHandlerBase.AWSRegion))] + [TestCase(ConfigHandlerBase.CloudProviderKey, nameof(ConfigHandlerBase.CloudProvider))] 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 df3eae374..217020387 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs @@ -76,6 +76,7 @@ public void SecretsShouldGetValueFromConnectionStrings(string configKey, string [TestCase(ConfigHandlerBase.AWSAccessKey, nameof(ConfigHandlerBase.AWSAccess))] [TestCase(ConfigHandlerBase.AWSAccessSecretKey, nameof(ConfigHandlerBase.AWSAccessSecret))] [TestCase(ConfigHandlerBase.AWSRegionKey, nameof(ConfigHandlerBase.AWSRegion))] + [TestCase(ConfigHandlerBase.CloudProviderKey, nameof(ConfigHandlerBase.CloudProvider))] public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName) { // Arrange diff --git a/src/e2e-docker-compose.yml b/src/e2e-docker-compose.yml index 8bfd18f12..540e5d091 100644 --- a/src/e2e-docker-compose.yml +++ b/src/e2e-docker-compose.yml @@ -51,6 +51,7 @@ services: IoTHub__EventHub__Endpoint: "${IOTHUB__EVENTHUB__ENDPOINT}" LoRaKeyManagement__Code: "${LORAKEYMANAGEMENT__CODE}" Ideas__Authentication__Token: "${IDEAS__AUTHENTICATION__TOKEN}" + CloudProvider: "${CLOUDPROVIDER}" depends_on: database: condition: service_healthy