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 18 10 #220

Merged
merged 9 commits into from
Oct 18, 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
63 changes: 63 additions & 0 deletions NVDSuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -796,4 +796,67 @@
<packageUrl regex="true">^pkg:nuget/System\.Security\.Cryptography\.Xml@.*$</packageUrl>
<vulnerabilityName>CVE-2022-34716</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: Azure.Core.dll
]]>
</notes>
<packageUrl regex="true">^pkg:generic/Azure\.Core@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>
<suppress>
<notes>
<![CDATA[
file name: Azure.Core:1.43.0
]]>
</notes>
<packageUrl regex="true">^pkg:nuget/Azure\.Core@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>
<suppress>
<notes>
<![CDATA[
file name: Azure.Identity:1.12.1
]]>
</notes>
<packageUrl regex="true">^pkg:nuget/Azure\.Identity@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>

<suppress>
<notes>
<![CDATA[
file name: Microsoft.Extensions.Azure:1.7.4
]]>
</notes>
<packageUrl regex="true">^pkg:nuget/Microsoft\.Extensions\.Azure@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>
<suppress>
<notes>
<![CDATA[
file name: System.ClientModel.dll
]]>
</notes>
<packageUrl regex="true">^pkg:generic/System\.ClientModel@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>
<suppress>
<notes>
<![CDATA[
file name: Microsoft.Extensions.Azure.dll
]]>
</notes>
<packageUrl regex="true">^pkg:generic/Microsoft\.Extensions\.Azure@.*$</packageUrl>
<cve>CVE-2024-43591</cve>
</suppress>

</suppressions>
25 changes: 23 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,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 @@ -866,6 +868,7 @@ stages:
AzureSubscription: "ERP-Facade-Dev-A.011.05.12"

- stage: Livedeploy
dependsOn: PreProdDeploy
displayName: "Livedeploy (inc terraform, webapp deploy)"
variables:
- group: "ERP-Facade-Live"
Expand All @@ -874,8 +877,26 @@ stages:
value: $(AzureADConfigurationTenantId)
- name: "AzureADConfiguration.ClientId"
value: $(AzureADConfigurationClientId)
- name: "AzureADConfiguration.AutoTestClientId"
value: $(AzureADConfigurationAutoTestClientId)
- name: "AzureADConfiguration.ClientSecret"
value: $(AzureADConfigurationClientSecret)
- name: "AzureADConfiguration.AutoTestClientIdNoRole"
value: $(AzureADConfigurationAutoTestClientIdNoRole)
- name: "AzureADConfiguration.ClientSecretNoRole"
value: $(AzureADConfigurationClientSecretNoRole)
- name: "EnterpriseEventServiceConfiguration.ClientId"
value: $(EnterpriseEventServiceConfigurationClientId)
value: $(EnterpriseEventServiceConfigurationClientId)
- name: "AzureADConfiguration.AutoTestClientId"
value: $(AzureADConfigurationAutoTestClientId)
- name: "AzureADConfiguration.ClientSecret"
value: $(AzureADConfigurationClientSecret)
- name: "AzureADConfiguration.AutoTestClientIdNoRole"
value: $(AzureADConfigurationAutoTestClientIdNoRole)
- name: "AzureADConfiguration.ClientSecretNoRole"
value: $(AzureADConfigurationClientSecretNoRole)
- name: "PermitConfiguration.PermitDecryptionHardwareId"
value: $(PermitDecryptionHardwareId)
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/main'),startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')))
jobs:
- deployment: LiveDeployTerraform
Expand Down
39 changes: 5 additions & 34 deletions src/UKHO.ERPFacade.API/Controllers/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UKHO.ERPFacade.API.Helpers;
using UKHO.ERPFacade.API.Services;
using UKHO.ERPFacade.Common.Configuration;
using UKHO.ERPFacade.Common.Constants;
using UKHO.ERPFacade.Common.Exceptions;
Expand All @@ -27,7 +28,7 @@ public class WebhookController : BaseController<WebhookController>
private readonly IAzureBlobEventWriter _azureBlobEventWriter;
private readonly IAzureQueueHelper _azureQueueHelper;
private readonly ISapClient _sapClient;
private readonly IEncContentSapMessageBuilder _encContentSapMessageBuilder;
private readonly IS57Service _s57Service;
private readonly IOptions<SapConfiguration> _sapConfig;
private readonly ILicenceUpdatedSapMessageBuilder _licenceUpdatedSapMessageBuilder;

Expand All @@ -37,7 +38,7 @@ public WebhookController(IHttpContextAccessor contextAccessor,
IAzureBlobEventWriter azureBlobEventWriter,
IAzureQueueHelper azureQueueHelper,
ISapClient sapClient,
IEncContentSapMessageBuilder encContentSapMessageBuilder,
IS57Service s57Service,
IOptions<SapConfiguration> sapConfig,
ILicenceUpdatedSapMessageBuilder licenceUpdatedSapMessageBuilder)
: base(contextAccessor)
Expand All @@ -47,7 +48,7 @@ public WebhookController(IHttpContextAccessor contextAccessor,
_azureBlobEventWriter = azureBlobEventWriter;
_azureQueueHelper = azureQueueHelper;
_sapClient = sapClient;
_encContentSapMessageBuilder = encContentSapMessageBuilder;
_s57Service = s57Service;
_licenceUpdatedSapMessageBuilder = licenceUpdatedSapMessageBuilder;
_sapConfig = sapConfig ?? throw new ArgumentNullException(nameof(sapConfig));
}
Expand Down Expand Up @@ -84,37 +85,7 @@ public virtual async Task<IActionResult> NewEncContentPublishedEventReceived([Fr
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, Constants.S57EventTableName, encEventEntity);

_logger.LogInformation(EventIds.UploadEncContentPublishedEventInAzureBlobStarted.ToEventId(), "Uploading enccontentpublished event payload in blob storage.");
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(), 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);

if (!response.IsSuccessStatusCode)
{
throw new ERPFacadeException(EventIds.RequestToSapFailed.ToEventId(), $"An error occurred while sending a request to SAP. | {response.StatusCode}");
}
_logger.LogInformation(EventIds.EncUpdateSentToSap.ToEventId(), "ENC update has been sent to SAP successfully. | {StatusCode}", response.StatusCode);

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

return new OkObjectResult(StatusCodes.Status200OK);
}
Expand Down
54 changes: 17 additions & 37 deletions src/UKHO.ERPFacade.API/Helpers/EncContentSapMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ public XmlDocument BuildSapMessageXml(EncEventPayload eventData)

// Build SAP actions for Units
BuildUnitActions(eventData, soapXml, actionItemNode);

var xmlNode = SortXmlPayload(actionItemNode);

soapXml.SelectSingleNode(Constants.XpathCorrId).InnerText = eventData.Data.CorrelationId;
soapXml.SelectSingleNode(Constants.XpathNoOfActions).InnerText = xmlNode.ChildNodes.Count.ToString();
soapXml.SelectSingleNode(Constants.XpathRecDate).InnerText = DateTime.UtcNow.ToString(Constants.RecDateFormat);
soapXml.SelectSingleNode(Constants.XpathRecTime).InnerText = DateTime.UtcNow.ToString(Constants.RecTimeFormat);

// Finalize SAP XML message
FinalizeSapXmlMessage(soapXml, eventData.Data.CorrelationId, actionItemNode);
var IM_MATINFONode = soapXml.SelectSingleNode(Constants.XpathImMatInfo);
IM_MATINFONode.AppendChild(xmlNode);

_logger.LogInformation(EventIds.GenerationOfSapXmlPayloadCompleted.ToEventId(), "Generation of SAP XML payload completed.");

Expand Down Expand Up @@ -156,20 +163,7 @@ private void BuildUnitActions(EncEventPayload eventData, XmlDocument soapXml, Xm
}
}
}

private void FinalizeSapXmlMessage(XmlDocument soapXml, string correlationId, XmlNode actionItemNode)
{
var xmlNode = SortXmlPayload(actionItemNode);

SetXmlNodeValue(soapXml, Constants.XpathCorrId, correlationId);
SetXmlNodeValue(soapXml, Constants.XpathNoOfActions, xmlNode.ChildNodes.Count.ToString());
SetXmlNodeValue(soapXml, Constants.XpathRecDate, DateTime.UtcNow.ToString(Constants.RecDateFormat));
SetXmlNodeValue(soapXml, Constants.XpathRecTime, DateTime.UtcNow.ToString(Constants.RecTimeFormat));

var IM_MATINFONode = soapXml.SelectSingleNode(Constants.XpathImMatInfo);
IM_MATINFONode.AppendChild(xmlNode);
}


/// <summary>
/// Returns primary unit of sale for given product to get ProductName for ENC cell SAP actions.
/// </summary>
Expand Down Expand Up @@ -287,7 +281,7 @@ private XmlElement BuildAction(XmlDocument soapXml, Product product, UnitOfSale
private void AppendChildNode(XmlElement parentNode, XmlDocument doc, string nodeName, string value)
{
var childNode = doc.CreateElement(nodeName);
childNode.InnerText = value ?? string.Empty;
childNode.InnerText = value;
parentNode.AppendChild(childNode);
}

Expand Down Expand Up @@ -358,7 +352,7 @@ private void ProcessUkhoWeekNumberAttributes(string action, IEnumerable<ActionIt
attributeNode.InnerText = GetXmlNodeValue(validFrom, attribute.XmlNodeName);
break;
case Constants.WeekNo:
var weekNo = string.Join("", ukhoWeekNumber.Year, ukhoWeekNumber.Week.Value.ToString("D2"));
var weekNo = string.Join(Constants.UkhoWeekNoFormatSeparator, ukhoWeekNumber.Year, ukhoWeekNumber.Week.Value.ToString(Constants.UkhoWeekNoFormat));
attributeNode.InnerText = GetXmlNodeValue(weekNo, attribute.XmlNodeName);
break;
case Constants.Correction:
Expand All @@ -378,16 +372,7 @@ private void ProcessUkhoWeekNumberAttributes(string action, IEnumerable<ActionIt
throw new ERPFacadeException(EventIds.BuildingSapActionInformationException.ToEventId(), $"Error while generating SAP action information. | Action : {action} | XML Attribute : {attribute.XmlNodeName} | ErrorMessage : {ex.Message}");
}
}
}

private void SetXmlNodeValue(XmlDocument xmlDoc, string xPath, string value)
{
var node = xmlDoc.SelectSingleNode(xPath);
if (node != null)
{
node.InnerText = value;
}
}
}

private string GetXmlNodeValue(string fieldValue, string xmlNodeName = null)
{
Expand All @@ -403,22 +388,17 @@ private XmlNode SortXmlPayload(XmlNode actionItemNode)

// Sort based on the ActionNumber
var sortedActionItems = actionItems
.OrderBy(node => Convert.ToInt32(node.SelectSingleNode(Constants.ActionNumber)?.InnerText ?? "0"))
.OrderBy(node => Convert.ToInt32(node.SelectSingleNode(Constants.ActionNumber)?.InnerText))
.ToList();

// Update the sequence number in the sorted list
foreach (XmlNode actionItem in sortedActionItems)
{
var actionNumberNode = actionItem.SelectSingleNode(Constants.ActionNumber);
if (actionNumberNode != null)
{
actionNumberNode.InnerText = sequenceNumber.ToString();
sequenceNumber++;
}
actionItem.SelectSingleNode(Constants.ActionNumber).InnerText = sequenceNumber.ToString();
sequenceNumber++;
}

// Clear existing children and append sorted action items
actionItemNode.RemoveAll();
//Append sorted action items
foreach (XmlNode actionItem in sortedActionItems)
{
actionItemNode.AppendChild(actionItem);
Expand Down
4 changes: 3 additions & 1 deletion src/UKHO.ERPFacade.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using UKHO.ERPFacade.Common.Providers;
using UKHO.ERPFacade.Common.PermitDecryption;
using UKHO.Logging.EventHubLogProvider;
using UKHO.ERPFacade.API.Services;

namespace UKHO.ERPFacade
{
Expand Down Expand Up @@ -164,6 +165,7 @@ void ConfigAdditionalValuesProvider(IDictionary<string, object> additionalValues
sapActionConfiguration = configuration.GetSection("SapActionConfiguration").Get<SapActionConfiguration>()!;
builder.Services.Configure<EESHealthCheckEnvironmentConfiguration>(configuration.GetSection("EESHealthCheckEnvironmentConfiguration"));
builder.Services.Configure<PermitConfiguration>(configuration.GetSection("PermitConfiguration"));
builder.Services.Configure<AioConfiguration>(configuration.GetSection("AioConfiguration"));

builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

Expand All @@ -178,7 +180,7 @@ void ConfigAdditionalValuesProvider(IDictionary<string, object> additionalValues
builder.Services.AddScoped<ILicenceUpdatedSapMessageBuilder, LicenceUpdatedSapMessageBuilder>();
builder.Services.AddScoped<IWeekDetailsProvider, WeekDetailsProvider>();
builder.Services.AddScoped<IPermitDecryption, PermitDecryption>();
builder.Services.AddScoped<IS100DataContentSapMessageBuilder, S100DataContentSapMessageBuilder>();
builder.Services.AddScoped<IS57Service, S57Service>();

ConfigureHealthChecks(builder);

Expand Down
9 changes: 9 additions & 0 deletions src/UKHO.ERPFacade.API/Services/IS57Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Newtonsoft.Json.Linq;

namespace UKHO.ERPFacade.API.Services
{
public interface IS57Service
{
Task ProcessS57Event(JObject encEventJson);
}
}
Loading
Loading