Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #1793 Add AmazonIoTClient and AmazonIotDataClient configurations
Browse files Browse the repository at this point in the history
- Add "CloudProvider" in configuration
- Add AmazonIoTClient and AmazonIotDataClient configurations when CloudProvider is AWS

* Update src/AzureIoTHub.Portal.Server/Startup.cs

Add OrdinalIgnoreCase string comparison for CloudProvider

Co-authored-by: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com>

* Update src/AzureIoTHub.Portal.Server/Startup.cs

- Local variables camelCased
- Keep asynchronous
- Let the DI container build instances when it is called

Co-authored-by: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com>

* #1793 update src\AzureIoTHub.Portal.Server\Startup.cs missing reference

- Missing reference

* #1793 Add CloudProvider for E2E tests

Add CloudProvider config for E2E tests
Add Azure in the current test pipeline (a new AWS test pipeline will be created in the next feature)

---------

Co-authored-by: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com>
delager and kbeaugrand committed Jun 22, 2023
1 parent 4c2f89b commit fdd2709
Showing 11 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -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: |
1 change: 1 addition & 0 deletions src/AzureIoTHub.Portal.Domain/ConfigHandler.cs
Original file line number Diff line number Diff line change
@@ -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; }
13 changes: 13 additions & 0 deletions src/AzureIoTHub.Portal.Domain/Shared/Constants/CloudProviders.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
2 changes: 2 additions & 0 deletions src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
@@ -34,7 +34,9 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="AWSSDK.IoT" Version="3.7.105.14" />
<PackageReference Include="AWSSDK.IotData" Version="3.7.101.74" />
<PackageReference Include="Azure.Data.Tables" Version="12.8.0" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.9.2" />
<PackageReference Include="Azure.Messaging.EventHubs.Processor" Version="5.9.2" />
20 changes: 20 additions & 0 deletions src/AzureIoTHub.Portal.Server/Startup.cs
Original file line number Diff line number Diff line change
@@ -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<AmazonIoTClient>().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<IExportManager, ExportManager>();
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/e2e-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fdd2709

Please sign in to comment.