Skip to content

Commit

Permalink
Merge pull request #19 from Worth-NL/fix/Configuration_RenameAndFixTests
Browse files Browse the repository at this point in the history
Fix/configuration rename and fix tests
  • Loading branch information
Thomas-M-Krystyan authored Apr 10, 2024
2 parents f89c1e9 + 2c50e2e commit e3fcaca
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 231 deletions.
68 changes: 34 additions & 34 deletions Documentation/OMC - Documentation.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace EventsHandler.Configuration
public sealed record WebApiConfiguration
{
/// <summary>
/// Gets the configuration for Notify NL (internal) system.
/// Gets the configuration for OMC (internal) system.
/// </summary>
internal NotifyComponent Notify { get; }
internal OmcComponent OMC { get; }

/// <summary>
/// Gets the configuration for the user (external) system.
Expand All @@ -29,12 +29,12 @@ public sealed record WebApiConfiguration
public WebApiConfiguration(ILoadersContext loaderContext) // NOTE: The only constructor to be used with Dependency Injection
{
// Recreating structure of "appsettings.json" or "secrets.json" files to use them later as objects
this.Notify = new NotifyComponent(loaderContext, nameof(this.Notify));
this.OMC = new OmcComponent(loaderContext, nameof(this.OMC));
this.User = new UserComponent(loaderContext, nameof(this.User));
}

/// <summary>
/// The common base for <see cref="NotifyComponent"/> and <see cref="UserComponent"/>.
/// The common base for <see cref="OmcComponent"/> and <see cref="UserComponent"/>.
/// </summary>
internal abstract record BaseComponent
{
Expand Down Expand Up @@ -112,17 +112,17 @@ internal string UserName()
}

/// <summary>
/// The "Notify" part of the configuration.
/// The "OMC" part of the configuration.
/// </summary>
internal record NotifyComponent : BaseComponent
internal record OmcComponent : BaseComponent
{
/// <inheritdoc cref="ApiComponent"/>
internal ApiComponent API { get; }

/// <summary>
/// Initializes a new instance of the <see cref="NotifyComponent"/> class.
/// Initializes a new instance of the <see cref="OmcComponent"/> class.
/// </summary>
public NotifyComponent(ILoadersContext loadersContext, string parentName)
public OmcComponent(ILoadersContext loadersContext, string parentName)
: base(loadersContext, parentName)
{
this.API = new ApiComponent(loadersContext, parentName);
Expand Down Expand Up @@ -351,7 +351,8 @@ private static string GetValue(ILoadingService loadersContext, string currentPat
{
string finalPath = loadersContext.GetPathWithNode(currentPath, nodeName);

return loadersContext.GetData<string>(finalPath);
return loadersContext.GetData<string>(finalPath)
.NotEmpty(finalPath);
}

/// <summary>
Expand All @@ -361,7 +362,8 @@ private static TData GetValue<TData>(ILoadingService loadersContext, string curr
{
string finalPath = loadersContext.GetPathWithNode(currentPath, nodeName);

return loadersContext.GetData<TData>(finalPath);
return loadersContext.GetData<TData>(finalPath)
.NotEmpty(finalPath);
}

/// <summary>
Expand All @@ -370,7 +372,6 @@ private static TData GetValue<TData>(ILoadingService loadersContext, string curr
private static string GetDomainValue(ILoadingService loadersContext, string currentPath, string nodeName)
{
return GetValue<string>(loadersContext, currentPath, nodeName)
// NOTE: Validate only once when the value is cached
.WithoutHttp()
.WithoutEndpoint();
}
Expand All @@ -381,7 +382,6 @@ private static string GetDomainValue(ILoadingService loadersContext, string curr
private static string GetTemplateIdValue(ILoadingService loadersContext, string currentPath, string nodeName)
{
return GetValue<string>(loadersContext, currentPath, nodeName)
// NOTE: Validate only once when the value is cached
.ValidTemplateId();
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class ApiController
{
internal const string Route = "[controller]";

internal const string Version = "1.654";
internal const string Version = "1.66";
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions EventsHandler/Api/EventsHandler/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<IActionResult> HealthCheckAsync()
try
{
// Health Check URL
string healthCheckUrl = $"{this._configuration.Notify.API.BaseUrl()}/_status?simple=true";
string healthCheckUrl = $"{this._configuration.OMC.API.BaseUrl()}/_status?simple=true";

// Request
using var httpClient = new HttpClient();
Expand Down Expand Up @@ -247,7 +247,7 @@ private async Task<IActionResult> SendAsync(
{
// Initialize the .NET client of "NotifyNL" API service
var notifyClient = new NotificationClient( // TODO: Client to be resolved by IClientFactory (to be testable)
this._configuration.Notify.API.BaseUrl(),
this._configuration.OMC.API.BaseUrl(),
this._configuration.User.API.Key.NotifyNL());

// Determine template type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static T NotEmpty<T>(this T? value, string key)
{
if (value is string stringValue)
{
return string.IsNullOrWhiteSpace(stringValue)
return string.IsNullOrEmpty(stringValue)
? throw new ArgumentException(Resources.Configuration_ERROR_ValueNotFoundOrEmpty + Separated(key))
: value;
}
Expand Down
6 changes: 3 additions & 3 deletions EventsHandler/Api/EventsHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b
setup.TokenValidationParameters = new TokenValidationParameters
{
// Validation parameters
ValidIssuer = configuration.Notify.Authorization.JWT.Issuer(),
ValidAudience = configuration.Notify.Authorization.JWT.Audience(),
IssuerSigningKey = encryptionContext.GetSecurityKey(configuration.Notify.Authorization.JWT.Secret()),
ValidIssuer = configuration.OMC.Authorization.JWT.Issuer(),
ValidAudience = configuration.OMC.Authorization.JWT.Audience(),
IssuerSigningKey = encryptionContext.GetSecurityKey(configuration.OMC.Authorization.JWT.Secret()),

// Validation criteria
ValidateIssuer = true,
Expand Down
64 changes: 2 additions & 62 deletions EventsHandler/Api/EventsHandler/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,12 @@
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7042;http://localhost:5270"
},
"IIS Express (Development)": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"NOTIFY_AUTHORIZATION_JWT_SECRET": "5lkLJ%5z$%KQ^^94VsLn6cENql7c%V19Yl3MLv7#odu*QoTYxK37ZF$7x4qQgmea*$S^s!kS0o2Ddaqo&7j3o4e2*Kx&2AXBG7Nu",
"NOTIFY_AUTHORIZATION_JWT_ISSUER": "https://omc.sandbox.notifynl.nl/",
"NOTIFY_AUTHORIZATION_JWT_AUDIENCE": "https://omc.sandbox.notifynl.nl/",
"NOTIFY_AUTHORIZATION_JWT_EXPIRESINMIN": "60",
"NOTIFY_AUTHORIZATION_JWT_USERID": "Notify NL (Development)",
"NOTIFY_AUTHORIZATION_JWT_USERNAME": "Notify NL (Development)",
"NOTIFY_API_BASEURL": "https://api.notifynl.nl",
"USER_AUTHORIZATION_JWT_SECRET": "worthsys123",
"USER_AUTHORIZATION_JWT_ISSUER": "goc",
"USER_AUTHORIZATION_JWT_AUDIENCE": " ",
"USER_AUTHORIZATION_JWT_EXPIRESINMIN": "60",
"USER_AUTHORIZATION_JWT_USERID": "Worth Systems",
"USER_AUTHORIZATION_JWT_USERNAME": "Development",
"USER_API_KEY_NOTIFYNL": "omc-7355b75b-8fa8-4923-85fb-d68432379b51-6d1eca33-bbd3-4e7a-a3f6-25bef2373223",
"USER_API_KEY_OBJECTEN": "c901449999175647118edd15d1f7d1f6a3863367",
"USER_DOMAIN_OPENNOTIFICATIES": "opennotificaties.test.denhaag.opengem.nl",
"USER_DOMAIN_OPENZAAK": "openzaak.test.denhaag.opengem.nl",
"USER_DOMAIN_OPENKLANT": "openklant.test.denhaag.opengem.nl",
"USER_DOMAIN_OBJECTEN": "objecten.test.denhaag.opengem.nl",
"USER_DOMAIN_OBJECTTYPEN": "objecttypen.test.denhaag.opengem.nl",
"USER_TEMPLATEIDS_SMS_ZAAKCREATE": "530651bd-291a-475a-8db4-db76eaa6fed3",
"USER_TEMPLATEIDS_SMS_ZAAKUPDATE": "5d70dcea-6134-4154-bfa2-ce68424a2cf3",
"USER_TEMPLATEIDS_SMS_ZAAKCLOSE": "9822b2fa-ffa3-4da1-b487-673e59631b51",
"USER_TEMPLATEIDS_EMAIL_ZAAKCREATE": "530651bd-291a-475a-8db4-db76eaa6fed3",
"USER_TEMPLATEIDS_EMAIL_ZAAKUPDATE": "ff24e8c5-c97a-40ae-b341-9ad1d5008740",
"USER_TEMPLATEIDS_EMAIL_ZAAKCLOSE": "98a5348d-3058-4488-bb14-5d61519a5aca"
}
},
"IIS Express (Testing)": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"NOTIFY_AUTHORIZATION_JWT_SECRET": "0143783a1ec3fa39f97a3e020336ced849c2c8947e024d7be13e505fdf321d1e",
"NOTIFY_AUTHORIZATION_JWT_ISSUER": "worth-omc",
"NOTIFY_AUTHORIZATION_JWT_AUDIENCE": "worth-omc",
"NOTIFY_AUTHORIZATION_JWT_EXPIRESINMIN": "3600",
"NOTIFY_AUTHORIZATION_JWT_USERID": "Test-Omc-DenHaag",
"NOTIFY_AUTHORIZATION_JWT_USERNAME": "Test-Omc-DenHaag",
"NOTIFY_API_BASEURL": "https://api.acc.notifynl.nl",
"USER_AUTHORIZATION_JWT_SECRET": "VoorFrank123",
"USER_AUTHORIZATION_JWT_ISSUER": "omc",
"USER_AUTHORIZATION_JWT_AUDIENCE": " ",
"USER_AUTHORIZATION_JWT_EXPIRESINMIN": "3600",
"USER_AUTHORIZATION_JWT_USERID": "Test-DenHaag",
"USER_AUTHORIZATION_JWT_USERNAME": "Test-DenHaag",
"USER_API_KEY_NOTIFYNL": "testdenhaaglive-87b0c601-cfcf-4666-96d0-c547c3eaf530-f613bfd0-5727-4553-a051-5217f26f2325",
"USER_API_KEY_OBJECTEN": "84ae24e804065bc577c0742365800620c94344ee",
"USER_DOMAIN_OPENNOTIFICATIES": "opennotificaties.test.denhaag.opengem.nl",
"USER_DOMAIN_OPENZAAK": "openzaak.test.denhaag.opengem.nl",
"USER_DOMAIN_OPENKLANT": "openklant.test.denhaag.opengem.nl",
"USER_DOMAIN_OBJECTEN": "objecten.test.denhaag.opengem.nl",
"USER_DOMAIN_OBJECTTYPEN": "objecttypen.test.denhaag.opengem.nl",
"USER_TEMPLATEIDS_SMS_ZAAKCREATE": "16db6a4e-67d8-48e4-b810-57a584317fd6",
"USER_TEMPLATEIDS_SMS_ZAAKUPDATE": "a8e9b4f3-eaf8-4b64-b768-dbf27eef9a2c",
"USER_TEMPLATEIDS_SMS_ZAAKCLOSE": "6870115a-2b13-4edf-b1a8-f70316619b49",
"USER_TEMPLATEIDS_EMAIL_ZAAKCREATE": "0d529f89-9588-4c4f-a46b-5f6cc1c7add4",
"USER_TEMPLATEIDS_EMAIL_ZAAKUPDATE": "0dd4833d-9d57-4c47-8256-9f76449fdb38",
"USER_TEMPLATEIDS_EMAIL_ZAAKCLOSE": "0e7b577e-2935-4258-9aaa-bc86cb5abc37"
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

using EventsHandler.Extensions;
using EventsHandler.Properties;
using EventsHandler.Services.DataLoading.Base;
using EventsHandler.Services.DataLoading.Interfaces;

namespace EventsHandler.Services.DataLoading
{
/// <inheritdoc cref="ILoadingService"/>
internal sealed class ConfigurationLoader : BaseLoader
internal sealed class ConfigurationLoader : ILoadingService
{
private readonly IConfiguration _configuration;

Expand All @@ -23,32 +22,34 @@ public ConfigurationLoader(IConfiguration configuration)
#region Polymorphism
/// <inheritdoc cref="ILoadingService.GetData{T}(string)"/>
/// <exception cref="ArgumentException"/>
protected override TData GetData<TData>(string key)
TData ILoadingService.GetData<TData>(string key)
{
// The key is missing
if (string.IsNullOrWhiteSpace(key))
{
throw new KeyNotFoundException(Resources.Configuration_ERROR_ValueNotFoundOrEmpty);
throw new KeyNotFoundException(Resources.Configuration_ERROR_ValueNotFoundOrEmpty + key.Separated());
}

return this._configuration.GetValue<TData>(key).NotEmpty(key);
return this._configuration.GetValue<TData>(key)
// The value is null
?? throw new KeyNotFoundException(Resources.Configuration_ERROR_ValueNotFoundOrEmpty + key.Separated());
}

/// <inheritdoc cref="BaseLoader.GetPathWithNode(string, string)"/>
protected override string GetPathWithNode(string currentPath, string nodeName)
/// <inheritdoc cref="ILoadingService.GetPathWithNode(string, string)"/>
string ILoadingService.GetPathWithNode(string currentPath, string nodeName)
{
return $"{currentPath}{(string.IsNullOrWhiteSpace(nodeName)
? string.Empty
: GetNodePath(nodeName))}";
: ((ILoadingService)this).GetNodePath(nodeName))}";
}

/// <inheritdoc cref="BaseLoader.GetNodePath(string)"/>
protected override string GetNodePath(string nodeName)
/// <inheritdoc cref="ILoadingService.GetNodePath(string)"/>
string ILoadingService.GetNodePath(string nodeName)
{
const string separator = ":";

return $"{separator}{nodeName}";
}
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

using EventsHandler.Extensions;
using EventsHandler.Properties;
using EventsHandler.Services.DataLoading.Base;
using EventsHandler.Services.DataLoading.Interfaces;

namespace EventsHandler.Services.DataLoading
{
/// <inheritdoc cref="ILoadingService"/>
internal sealed class EnvironmentLoader : BaseLoader
internal sealed class EnvironmentLoader : ILoadingService
{
#region Polymorphism
/// <inheritdoc cref="ILoadingService.GetData{T}(string)"/>
/// <exception cref="NotImplementedException">The operating system (OS) is not supported.</exception>
protected override TData GetData<TData>(string key)
TData ILoadingService.GetData<TData>(string key)
{
// The key is missing
if (string.IsNullOrWhiteSpace(key))
Expand All @@ -26,6 +25,7 @@ protected override TData GetData<TData>(string key)
or PlatformID.MacOSX
or PlatformID.Unix)
{
// The value is null
object value = Environment.GetEnvironmentVariable(key)
?? throw new KeyNotFoundException(Resources.Configuration_ERROR_EnvironmentVariableGetNull + key.Separated());

Expand All @@ -35,21 +35,21 @@ or PlatformID.MacOSX
throw new NotImplementedException(Resources.Configuration_ERROR_EnvironmentNotSupported);
}

/// <inheritdoc cref="BaseLoader.GetPathWithNode(string, string)"/>
protected override string GetPathWithNode(string currentPath, string nodeName)
/// <inheritdoc cref="ILoadingService.GetPathWithNode(string, string)"/>
string ILoadingService.GetPathWithNode(string currentPath, string nodeName)
{
return $"{currentPath.ToUpper()}{(string.IsNullOrWhiteSpace(nodeName)
? string.Empty
: GetNodePath(nodeName))}";
: ((ILoadingService)this).GetNodePath(nodeName))}";
}

/// <inheritdoc cref="BaseLoader.GetNodePath(string)"/>
protected override string GetNodePath(string nodeName)
/// <inheritdoc cref="ILoadingService.GetNodePath(string)"/>
string ILoadingService.GetNodePath(string nodeName)
{
const string separator = "_";

return $"{separator}{nodeName.ToUpper()}";
}
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ public interface ILoadingService
/// The formatted node path.
/// </returns>
internal string GetPathWithNode(string currentPath, string nodeName);

/// <summary>
/// Precedes the (eventually formatted) node name with a respective separator.
/// </summary>
/// <param name="nodeName">The name of the configuration node.</param>
/// <returns>
/// The formatted node path.
/// </returns>
internal string GetNodePath(string nodeName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public interface ILoadersContext : ILoadingService
/// <param name="loaderType">The specific loader to be set.</param>
internal void SetLoader(LoaderTypes loaderType);
}
}
}
Loading

0 comments on commit e3fcaca

Please sign in to comment.