Skip to content

Commit

Permalink
Update deployement parameters (#2155)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Jun 18, 2023
1 parent d7cbb0c commit 22a42c7
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 59 deletions.
1 change: 1 addition & 0 deletions src/AzureIoTHub.Portal.Domain/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ public abstract class ConfigHandler
public abstract string AWSS3StorageConnectionString { get; }
public abstract string AWSBucketName { get; }
public abstract string AWSAccountId { get; }
public abstract IEnumerable<string> AWSGreengrassRequiredRoles { get; }
}
}
1 change: 1 addition & 0 deletions src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal abstract class ConfigHandlerBase : ConfigHandler
internal const string AWSS3StorageConnectionStringKey = "AWS:S3Storage:ConnectionString";
internal const string AWSBucketNameKey = "AWS:BucketName";
internal const string AWSAccountIdKey = "AWS:AccountId";
internal const string AWSGreengrassRequiredRolesKey = "AWS:GreengrassRequiredRoles";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace AzureIoTHub.Portal.Infrastructure
{
using System.Collections.Generic;
using AzureIoTHub.Portal.Domain.Shared.Constants;
using Microsoft.Extensions.Configuration;

Expand Down Expand Up @@ -90,5 +91,6 @@ internal DevelopmentConfigHandler(IConfiguration config)
public override string AWSS3StorageConnectionString => this.config[AWSS3StorageConnectionStringKey]!;
public override string AWSBucketName => this.config[AWSBucketNameKey]!;
public override string AWSAccountId => this.config[AWSAccountIdKey]!;
public override IEnumerable<string> AWSGreengrassRequiredRoles => this.config.GetSection(AWSGreengrassRequiredRolesKey).Get<string[]>()!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ internal ProductionAWSConfigHandler(IConfiguration config)
public override string AWSS3StorageConnectionString => this.config[AWSS3StorageConnectionStringKey]!;
public override string AWSBucketName => this.config[AWSBucketNameKey]!;
public override string AWSAccountId => this.config[AWSAccountIdKey]!;
public override IEnumerable<string> AWSGreengrassRequiredRoles => this.config.GetSection(AWSGreengrassRequiredRolesKey).Get<string[]>()!;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace AzureIoTHub.Portal.Infrastructure
{
using System.Collections.Generic;
using AzureIoTHub.Portal.Domain.Shared.Constants;
using Microsoft.Extensions.Configuration;

Expand Down Expand Up @@ -94,5 +95,6 @@ internal ProductionAzureConfigHandler(IConfiguration config)
public override string AWSBucketName => throw new NotImplementedException();
public override string AWSAccountId => throw new NotImplementedException();

public override IEnumerable<string> AWSGreengrassRequiredRoles => throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,14 @@ public async Task<DeviceCredentials> GetEdgeDeviceCredentials(IoTEdgeDevice devi
{
var createCertificateTuple = await GenerateCertificate(device.DeviceName);

_ = await this.amazonIoTClient.AttachPolicyAsync(new AttachPolicyRequest
foreach (var item in this.configHandler.AWSGreengrassRequiredRoles)
{
PolicyName = "GreengrassV2IoTThingPolicy",
Target = createCertificateTuple.Item2
});

_ = await this.amazonIoTClient.AttachPolicyAsync(new AttachPolicyRequest
{
PolicyName = "GreengrassCoreTokenExchangeRoleAliasPolicy",
Target = createCertificateTuple.Item2
});
_ = await this.amazonIoTClient.AttachPolicyAsync(new AttachPolicyRequest
{
PolicyName = item,
Target = createCertificateTuple.Item2
});
}

return createCertificateTuple.Item1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private DevelopmentConfigHandler CreateDevelopmentConfigHandler()
[TestCase(ConfigHandlerBase.AWSS3StorageConnectionStringKey, nameof(ConfigHandlerBase.AWSS3StorageConnectionString))]
[TestCase(ConfigHandlerBase.CloudProviderKey, nameof(ConfigHandlerBase.CloudProvider))]
[TestCase(ConfigHandlerBase.AWSBucketNameKey, nameof(ConfigHandlerBase.AWSBucketName))]
[TestCase(ConfigHandlerBase.AWSAccountIdKey, nameof(ConfigHandlerBase.AWSAccountId))]
public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName)
{
// Arrange
Expand All @@ -74,6 +75,36 @@ public void SettingsShouldGetValueFromAppSettings(string configKey, string confi
this.mockRepository.VerifyAll();
}

[TestCase(ConfigHandlerBase.AWSGreengrassRequiredRolesKey, nameof(ConfigHandlerBase.AWSGreengrassRequiredRoles))]
public void SettingsShouldGetSectionFromAppSettings(string configKey, string configPropertyName)
{
// Arrange
var mockSection = this.mockRepository.Create<IConfigurationSection>();

_ = mockSection.SetupGet(c => c.Value)
.Returns(Guid.NewGuid().ToString());

_ = mockSection.SetupGet(c => c.Path)
.Returns(configKey);

_ = mockSection.Setup(c => c.GetChildren())
.Returns(Array.Empty<IConfigurationSection>());

var configHandler = CreateDevelopmentConfigHandler();

_ = this.mockConfiguration.Setup(c => c.GetSection(It.Is<string>(x => x == configKey)))
.Returns(mockSection.Object);

// Act
var result = configHandler
.GetType()
.GetProperty(configPropertyName)
.GetValue(configHandler, null);

// Assert
this.mockRepository.VerifyAll();
}

[TestCase(ConfigHandlerBase.OIDCValidateAudienceKey, nameof(ConfigHandlerBase.OIDCValidateAudience))]
[TestCase(ConfigHandlerBase.OIDCValidateIssuerKey, nameof(ConfigHandlerBase.OIDCValidateIssuer))]
[TestCase(ConfigHandlerBase.OIDCValidateIssuerSigningKeyKey, nameof(ConfigHandlerBase.OIDCValidateIssuerSigningKey))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private ProductionAWSConfigHandler CreateProductionAWSConfigHandler()
[TestCase(ConfigHandlerBase.AWSS3StorageConnectionStringKey, nameof(ConfigHandlerBase.AWSS3StorageConnectionString))]
[TestCase(ConfigHandlerBase.CloudProviderKey, nameof(ConfigHandlerBase.CloudProvider))]
[TestCase(ConfigHandlerBase.AWSBucketNameKey, nameof(ConfigHandlerBase.AWSBucketName))]
[TestCase(ConfigHandlerBase.AWSAccountIdKey, nameof(ConfigHandlerBase.AWSAccountId))]

public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName)
{
Expand All @@ -75,6 +76,36 @@ public void SettingsShouldGetValueFromAppSettings(string configKey, string confi
this.mockRepository.VerifyAll();
}

[TestCase(ConfigHandlerBase.AWSGreengrassRequiredRolesKey, nameof(ConfigHandlerBase.AWSGreengrassRequiredRoles))]
public void SettingsShouldGetSectionFromAppSettings(string configKey, string configPropertyName)
{
// Arrange
var mockSection = this.mockRepository.Create<IConfigurationSection>();

_ = mockSection.SetupGet(c => c.Value)
.Returns(Guid.NewGuid().ToString());

_ = mockSection.SetupGet(c => c.Path)
.Returns(configKey);

_ = mockSection.Setup(c => c.GetChildren())
.Returns(Array.Empty<IConfigurationSection>());

var configHandler = CreateProductionAWSConfigHandler();

_ = this.mockConfiguration.Setup(c => c.GetSection(It.Is<string>(x => x == configKey)))
.Returns(mockSection.Object);

// Act
var result = configHandler
.GetType()
.GetProperty(configPropertyName)
.GetValue(configHandler, null);

// Assert
this.mockRepository.VerifyAll();
}

[TestCase(nameof(ConfigHandlerBase.StorageAccountConnectionString))]
[TestCase(nameof(ConfigHandlerBase.StorageAccountDeviceModelImageMaxAge))]
public void SettingsShouldThrowError(string configPropertyName)
Expand Down
Loading

0 comments on commit 22a42c7

Please sign in to comment.