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

Update deployement parameters #2155

Merged
merged 1 commit into from
Jun 5, 2023
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
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; }
}
}
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);
Comment on lines +99 to +102

Check warning

Code scanning / CodeQL

Useless assignment to local variable

This assignment to [result](1) is useless, since its value is never read.

// 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);
Comment on lines +100 to +103

Check warning

Code scanning / CodeQL

Useless assignment to local variable

This assignment to [result](1) is useless, since its value is never read.

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

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