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

Merge dev into dev s100 15 10 #216

Merged
merged 7 commits into from
Oct 15, 2024
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
14 changes: 14 additions & 0 deletions NVDSuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,20 @@
<packageUrl regex="true">^pkg:nuget/System\.Runtime\.Caching@.*$</packageUrl>
<vulnerabilityName>CVE-2024-43483</vulnerabilityName>
</suppress>
<suppress>
<notes><![CDATA[
file name: System.Security.Cryptography.Xml:4.7.0
]]></notes>
<packageUrl regex="true">^pkg:nuget/System\.Security\.Cryptography\.Xml@.*$</packageUrl>
<vulnerabilityName>CVE-2022-34716</vulnerabilityName>
</suppress>
<suppress>
<notes><![CDATA[
file name: System.Runtime.Caching:8.0.0
]]></notes>
<packageUrl regex="true">^pkg:nuget/System\.Runtime\.Caching@.*$</packageUrl>
<vulnerabilityName>CVE-2024-43483</vulnerabilityName>
</suppress>
<suppress>
<notes><![CDATA[
file name: System.Security.Cryptography.Xml:4.7.0
Expand Down
24 changes: 9 additions & 15 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,7 @@ stages:
- name: "EnterpriseEventServiceConfiguration.ClientId"
value: $(EnterpriseEventServiceConfigurationClientId)
- name: "PermitConfiguration.PermitDecryptionHardwareId"
value: $(PermitDecryptionHardwareId)
- name: "PermitWithSameKey.Permit"
value: $(PermitWithSameKeyPermit)
- name: "PermitWithSameKey.ActiveKey"
value: $(PermitWithSameKeyACTIVEKEY)
- name: "PermitWithSameKey.NextKey"
value: $(PermitWithSameKeyNEXTKEY)
- name: "PermitWithDifferentKey.Permit"
value: $(PermitWithDifferentKeyPermit)
- name: "PermitWithDifferentKey.ActiveKey"
value: $(PermitWithDifferentKeyACTIVEKEY)
- name: "PermitWithDifferentKey.NextKey"
value: $(PermitWithDifferentKeyNEXTKEY)
value: $(PermitDecryptionHardwareId)
- name: mockWebAppName
value: $[ stageDependencies.DevDeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockWebApp'] ]
- name: mockWebAppResourceGroup
Expand Down Expand Up @@ -567,7 +555,9 @@ stages:
- name: "AzureADConfiguration.ClientSecretNoRole"
value: $(AzureADConfigurationClientSecretNoRole)
- name: "EnterpriseEventServiceConfiguration.ClientId"
value: $(EnterpriseEventServiceConfigurationClientId)
value: $(EnterpriseEventServiceConfigurationClientId)
- name: "PermitConfiguration.PermitDecryptionHardwareId"
value: $(PermitDecryptionHardwareId)
- name: mockWebAppName
value: $[ stageDependencies.DevDeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockWebApp'] ]
- name: mockWebAppResourceGroup
Expand Down Expand Up @@ -716,7 +706,9 @@ stages:
- name: "AzureADConfiguration.ClientSecretNoRole"
value: $(AzureADConfigurationClientSecretNoRole)
- name: "EnterpriseEventServiceConfiguration.ClientId"
value: $(EnterpriseEventServiceConfigurationClientId)
value: $(EnterpriseEventServiceConfigurationClientId)
- name: "PermitConfiguration.PermitDecryptionHardwareId"
value: $(PermitDecryptionHardwareId)
- name: mockWebAppName
value: $[ stageDependencies.DevDeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockWebApp'] ]
- name: mockWebAppResourceGroup
Expand Down Expand Up @@ -788,6 +780,8 @@ stages:
value: $(AzureADConfigurationAutoTestClientIdNoRole)
- name: "AzureADConfiguration.ClientSecretNoRole"
value: $(AzureADConfigurationClientSecretNoRole)
- name: "PermitConfiguration.PermitDecryptionHardwareId"
value: $(PermitDecryptionHardwareId)
- name: mockWebAppName
value: $[ stageDependencies.Devdeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockWebApp'] ]
- name: mockWebAppResourceGroup
Expand Down
67 changes: 44 additions & 23 deletions src/UKHO.ERPFacade.API/Controllers/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
using Newtonsoft.Json.Linq;
using UKHO.ERPFacade.API.Helpers;
using UKHO.ERPFacade.Common.Configuration;
using UKHO.ERPFacade.Common.Constants;
using UKHO.ERPFacade.Common.Exceptions;
using UKHO.ERPFacade.Common.HttpClients;
using UKHO.ERPFacade.Common.IO;
using UKHO.ERPFacade.Common.IO.Azure;
using UKHO.ERPFacade.Common.Logging;
using UKHO.ERPFacade.Common.Models;
using UKHO.ERPFacade.Common.Models.TableEntities;
using Status = UKHO.ERPFacade.Common.Enums.Status;

namespace UKHO.ERPFacade.API.Controllers
{
Expand All @@ -28,15 +31,6 @@ public class WebhookController : BaseController<WebhookController>
private readonly IOptions<SapConfiguration> _sapConfig;
private readonly ILicenceUpdatedSapMessageBuilder _licenceUpdatedSapMessageBuilder;

private const string EventIdKey = "id";
private const string CorrelationIdKey = "data.correlationId";
private const string EncEventFileName = "EncPublishingEvent.json";
private const string SapXmlPayloadFileName = "SapXmlPayload.xml";
private const string LicenceUpdatedContainerName = "licenceupdatedblobs";
private const string LicenceUpdatedEventFileName = "LicenceUpdatedEvent.json";
private const string RecordOfSaleContainerName = "recordofsaleblobs";
private const string JsonFileType = ".json";

public WebhookController(IHttpContextAccessor contextAccessor,
ILogger<WebhookController> logger,
IAzureTableReaderWriter azureTableReaderWriter,
Expand Down Expand Up @@ -82,25 +76,34 @@ public virtual async Task<IActionResult> NewEncContentPublishedEventReceived([Fr
{
_logger.LogInformation(EventIds.NewEncContentPublishedEventReceived.ToEventId(), "ERP Facade webhook has received new enccontentpublished event from EES.");

var correlationId = encEventJson.SelectToken(CorrelationIdKey)?.Value<string>();
var correlationId = encEventJson.SelectToken(Constants.CorrelationIdKey)?.Value<string>();

if (string.IsNullOrEmpty(correlationId))
{
_logger.LogWarning(EventIds.CorrelationIdMissingInEvent.ToEventId(), "CorrelationId is missing in enccontentpublished event.");
return new BadRequestObjectResult(StatusCodes.Status400BadRequest);
}

EncEventEntity encEventEntity = new()
{
RowKey = Guid.NewGuid().ToString(),
PartitionKey = Guid.NewGuid().ToString(),
Timestamp = DateTime.UtcNow,
CorrelationId = correlationId,
RequestDateTime = null
};

_logger.LogInformation(EventIds.AddingEntryForEncContentPublishedEventInAzureTable.ToEventId(), "Adding/Updating entry for enccontentpublished event in azure table.");
await _azureTableReaderWriter.UpsertEntity(correlationId);
await _azureTableReaderWriter.UpsertEntity(correlationId, Constants.S57EventTableName, encEventEntity);

_logger.LogInformation(EventIds.UploadEncContentPublishedEventInAzureBlobStarted.ToEventId(), "Uploading enccontentpublished event payload in blob storage.");
await _azureBlobEventWriter.UploadEvent(encEventJson.ToString(), correlationId, EncEventFileName);
await _azureBlobEventWriter.UploadEvent(encEventJson.ToString(), Constants.S57EventContainerName, correlationId + '/' + Constants.S57EncEventFileName);
_logger.LogInformation(EventIds.UploadEncContentPublishedEventInAzureBlobCompleted.ToEventId(), "The enccontentpublished event payload is uploaded in blob storage successfully.");

var sapPayload = _encContentSapMessageBuilder.BuildSapMessageXml(JsonConvert.DeserializeObject<EncEventPayload>(encEventJson.ToString()));

_logger.LogInformation(EventIds.UploadSapXmlPayloadInAzureBlobStarted.ToEventId(), "Uploading the SAP XML payload in blob storage.");
await _azureBlobEventWriter.UploadEvent(sapPayload.ToIndentedString(), correlationId, SapXmlPayloadFileName);
await _azureBlobEventWriter.UploadEvent(sapPayload.ToIndentedString(), Constants.S57EventContainerName, correlationId + '/' + Constants.SapXmlPayloadFileName);
_logger.LogInformation(EventIds.UploadSapXmlPayloadInAzureBlobCompleted.ToEventId(), "SAP XML payload is uploaded in blob storage successfully.");

var response = await _sapClient.PostEventData(sapPayload, _sapConfig.Value.SapEndpointForEncEvent, _sapConfig.Value.SapServiceOperationForEncEvent, _sapConfig.Value.SapUsernameForEncEvent, _sapConfig.Value.SapPasswordForEncEvent);
Expand All @@ -111,7 +114,7 @@ public virtual async Task<IActionResult> NewEncContentPublishedEventReceived([Fr
}
_logger.LogInformation(EventIds.EncUpdateSentToSap.ToEventId(), "ENC update has been sent to SAP successfully. | {StatusCode}", response.StatusCode);

await _azureTableReaderWriter.UpdateRequestTimeEntity(correlationId);
await _azureTableReaderWriter.UpdateEntity(correlationId, Constants.S57EventTableName, new[] { new KeyValuePair<string, DateTime>("RequestDateTime", DateTime.UtcNow) });

return new OkObjectResult(StatusCodes.Status200OK);
}
Expand Down Expand Up @@ -142,20 +145,29 @@ public virtual async Task<IActionResult> RecordOfSalePublishedEventReceived([Fro
{
_logger.LogInformation(EventIds.RecordOfSalePublishedEventReceived.ToEventId(), "ERP Facade webhook has received record of sale event from EES.");

var correlationId = recordOfSaleEventJson.SelectToken(CorrelationIdKey)?.Value<string>();
var eventId = recordOfSaleEventJson.SelectToken(EventIdKey)?.Value<string>();
var correlationId = recordOfSaleEventJson.SelectToken(Constants.CorrelationIdKey)?.Value<string>();
var eventId = recordOfSaleEventJson.SelectToken(Constants.EventIdKey)?.Value<string>();

if (string.IsNullOrEmpty(correlationId))
{
_logger.LogWarning(EventIds.CorrelationIdMissingInRecordOfSaleEvent.ToEventId(), "CorrelationId is missing in Record of Sale published event.");
return new BadRequestObjectResult(StatusCodes.Status400BadRequest);
}

RecordOfSaleEventEntity recordOfSaleEvent = new()
{
RowKey = Guid.NewGuid().ToString(),
PartitionKey = Guid.NewGuid().ToString(),
Timestamp = DateTime.UtcNow,
CorrelationId = correlationId,
Status = Status.Incomplete.ToString()
};

_logger.LogInformation(EventIds.StoreRecordOfSalePublishedEventInAzureTable.ToEventId(), "Storing the received Record of sale published event in azure table.");
await _azureTableReaderWriter.UpsertRecordOfSaleEntity(correlationId);
await _azureTableReaderWriter.UpsertEntity(correlationId, Constants.RecordOfSaleEventTableName, recordOfSaleEvent);

_logger.LogInformation(EventIds.UploadRecordOfSalePublishedEventInAzureBlob.ToEventId(), "Uploading the received Record of sale published event in blob storage.");
await _azureBlobEventWriter.UploadEvent(recordOfSaleEventJson.ToString(), RecordOfSaleContainerName, correlationId + '/' + eventId + JsonFileType);
await _azureBlobEventWriter.UploadEvent(recordOfSaleEventJson.ToString(), Constants.RecordOfSaleEventContainerName, correlationId + '/' + eventId + Constants.RecordOfSaleEventFileExtension);
_logger.LogInformation(EventIds.UploadedRecordOfSalePublishedEventInAzureBlob.ToEventId(), "Record of sale published event is uploaded in blob storage successfully.");

_logger.LogInformation(EventIds.AddMessageToAzureQueue.ToEventId(), "Adding the received Record of sale published event in queue storage.");
Expand Down Expand Up @@ -191,25 +203,34 @@ public virtual async Task<IActionResult> LicenceUpdatedPublishedEventReceived([F
{
_logger.LogInformation(EventIds.LicenceUpdatedEventPublishedEventReceived.ToEventId(), "ERP Facade webhook has received new licence updated publish event from EES.");

var correlationId = licenceUpdatedEventJson.SelectToken(CorrelationIdKey)?.Value<string>();
var correlationId = licenceUpdatedEventJson.SelectToken(Constants.CorrelationIdKey)?.Value<string>();

if (string.IsNullOrEmpty(correlationId))
{
_logger.LogWarning(EventIds.CorrelationIdMissingInLicenceUpdatedEvent.ToEventId(), "CorrelationId is missing in Licence updated published event.");
return new BadRequestObjectResult(StatusCodes.Status400BadRequest);
}

LicenseUpdatedEventEntity licenceUpdatedEventEntity = new()
{
RowKey = Guid.NewGuid().ToString(),
PartitionKey = Guid.NewGuid().ToString(),
Timestamp = DateTime.UtcNow,
CorrelationId = correlationId,
Status = Status.Incomplete.ToString()
};

_logger.LogInformation(EventIds.StoreLicenceUpdatedPublishedEventInAzureTable.ToEventId(), "Storing the received Licence updated published event in azure table.");
await _azureTableReaderWriter.UpsertLicenceUpdatedEntity(correlationId);
await _azureTableReaderWriter.UpsertEntity(correlationId, Constants.LicenceUpdatedEventTableName, licenceUpdatedEventEntity);

_logger.LogInformation(EventIds.UploadLicenceUpdatedPublishedEventInAzureBlob.ToEventId(), "Uploading the received Licence updated published event in blob storage.");
await _azureBlobEventWriter.UploadEvent(licenceUpdatedEventJson.ToString(), LicenceUpdatedContainerName, correlationId + '/' + LicenceUpdatedEventFileName);
await _azureBlobEventWriter.UploadEvent(licenceUpdatedEventJson.ToString(), Constants.LicenceUpdatedEventContainerName, correlationId + '/' + Constants.LicenceUpdatedEventFileName);
_logger.LogInformation(EventIds.UploadedLicenceUpdatedPublishedEventInAzureBlob.ToEventId(), "Licence updated published event is uploaded in blob storage successfully.");

var sapPayload = _licenceUpdatedSapMessageBuilder.BuildLicenceUpdatedSapMessageXml(JsonConvert.DeserializeObject<LicenceUpdatedEventPayLoad>(licenceUpdatedEventJson.ToString()), correlationId);

_logger.LogInformation(EventIds.UploadLicenceUpdatedSapXmlPayloadInAzureBlob.ToEventId(), "Uploading the SAP xml payload for licence updated event in blob storage.");
await _azureBlobEventWriter.UploadEvent(sapPayload.ToIndentedString(), LicenceUpdatedContainerName, correlationId + '/' + SapXmlPayloadFileName);
await _azureBlobEventWriter.UploadEvent(sapPayload.ToIndentedString(), Constants.LicenceUpdatedEventContainerName, correlationId + '/' + Constants.SapXmlPayloadFileName);
_logger.LogInformation(EventIds.UploadedLicenceUpdatedSapXmlPayloadInAzureBlob.ToEventId(), "SAP xml payload for licence updated event is uploaded in blob storage successfully.");

var response = await _sapClient.PostEventData(sapPayload, _sapConfig.Value.SapEndpointForRecordOfSale, _sapConfig.Value.SapServiceOperationForRecordOfSale, _sapConfig.Value.SapUsernameForRecordOfSale, _sapConfig.Value.SapPasswordForRecordOfSale);
Expand All @@ -221,7 +242,7 @@ public virtual async Task<IActionResult> LicenceUpdatedPublishedEventReceived([F

_logger.LogInformation(EventIds.LicenceUpdatedPublishedEventUpdatePushedToSap.ToEventId(), "The licence updated event data has been sent to SAP successfully. | {StatusCode}", response.StatusCode);

await _azureTableReaderWriter.UpdateLicenceUpdatedEventStatus(correlationId);
await _azureTableReaderWriter.UpdateEntity(correlationId, Constants.LicenceUpdatedEventTableName, new[] { new KeyValuePair<string, string>("Status", Status.Complete.ToString()) });

return new OkObjectResult(StatusCodes.Status200OK);
}
Expand Down
6 changes: 3 additions & 3 deletions src/UKHO.ERPFacade.API/Health/HealthResponseWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
using System.Text.Json.Serialization;
using System.Text.Unicode;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using UKHO.ERPFacade.Common.Constants;

namespace UKHO.ERPFacade.API.Health
{
public static class HealthResponseWriter
{
private const string DefaultContentType = "application/json";

private static readonly byte[] _emptyResponse = "{}"u8.ToArray();
private static readonly Lazy<JsonSerializerOptions> _options = new(CreateJsonOptions);

public static async Task WriteHealthCheckUiResponse(HttpContext httpContext, HealthReport report)
public static async Task WriteHealthCheckUiResponse(HttpContext httpContext, HealthReport report)
{
if (report != null)
{
httpContext.Response.ContentType = DefaultContentType;
httpContext.Response.ContentType = Constants.DefaultContentType;

ErpHealthReport uiReport = ErpHealthReport.CreateFrom(report);

Expand Down
Loading
Loading