Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1793 Add AmazonIoTClient and AmazonIotDataClient configurations #1951

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions src/AzureIoTHub.Portal.Domain/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
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
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<ItemGroup>
<PackageReference Include="AutoMapper" 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.8.1" />
<PackageReference Include="Azure.Messaging.EventHubs.Processor" Version="5.8.1" />
Expand Down
20 changes: 20 additions & 0 deletions src/AzureIoTHub.Portal.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/e2e-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
IoTHub__EventHub__Endpoint: "${IOTHUB__EVENTHUB__ENDPOINT}"
LoRaKeyManagement__Code: "${LORAKEYMANAGEMENT__CODE}"
Ideas__Authentication__Token: "${IDEAS__AUTHENTICATION__TOKEN}"
CloudProvider: "${CLOUDPROVIDER}"
depends_on:
- "database"
ports:
Expand Down