Skip to content

Commit

Permalink
Merge pull request #116 from UKHO/Feature/143937-decrypt-permit-string
Browse files Browse the repository at this point in the history
143937 decrypt permit string
  • Loading branch information
jrippington authored Mar 1, 2024
2 parents 32307e3 + 2491438 commit cee76f4
Show file tree
Hide file tree
Showing 58 changed files with 4,435 additions and 3,283 deletions.
29 changes: 29 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,20 @@ stages:
value: $(AzureADConfigurationClientId)
- name: "SharedKeyConfiguration.Key"
value: $(SharedKeyConfigurationKey)
- 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)
jobs:
- deployment: DevDeployTerraform
displayName: "Dev - Deploy Terraform"
Expand Down Expand Up @@ -675,7 +689,22 @@ stages:
value: $[ stageDependencies.Devdeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockWebAppResourceGroupName'] ]
- name: "SapMockConfiguration.BaseUrl"
value: $[ stageDependencies.Devdeploy.DevDeployTerraform.outputs['DevDeployTerraform.TerraformDeploy.mockwebappurl'] ]
- 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)
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/main'),startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')))

jobs:
- deployment: QADeployTerraform
displayName: "Qa - Deploy Terraform"
Expand Down
140 changes: 140 additions & 0 deletions src/UKHO.ERPFacade.API/ConfigurationFiles/SapActions.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@
"JsonPropertyName": "CurrentWeekAlphaCorrection",
"XmlNodeName": "CORRECTION",
"SortingOrder": 15
},
{
"IsRequired": true,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": true,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -244,6 +258,20 @@
"JsonPropertyName": "CurrentWeekAlphaCorrection",
"XmlNodeName": "CORRECTION",
"SortingOrder": 15
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -362,6 +390,20 @@
"JsonPropertyName": "CurrentWeekAlphaCorrection",
"XmlNodeName": "CORRECTION",
"SortingOrder": 15
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -459,6 +501,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -561,6 +617,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -663,6 +733,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -784,6 +868,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": true,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": true,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -881,6 +979,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -983,6 +1095,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
},
Expand Down Expand Up @@ -1085,6 +1211,20 @@
"JsonPropertyName": "UnitType",
"XmlNodeName": "UNITTYPE",
"SortingOrder": 12
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "ACTIVEKEY",
"SortingOrder": 16
},
{
"IsRequired": false,
"Section": "Product",
"JsonPropertyName": "Permit",
"XmlNodeName": "NEXTKEY",
"SortingOrder": 17
}
]
}
Expand Down
27 changes: 26 additions & 1 deletion src/UKHO.ERPFacade.API/Helpers/EncContentSapMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UKHO.ERPFacade.Common.Logging;
using UKHO.ERPFacade.Common.Models;
using UKHO.ERPFacade.Common.Providers;
using UKHO.ERPFacade.Common.PermitDecryption;

namespace UKHO.ERPFacade.API.Helpers
{
Expand All @@ -14,6 +15,7 @@ public class EncContentSapMessageBuilder : IEncContentSapMessageBuilder
private readonly IFileSystemHelper _fileSystemHelper;
private readonly IOptions<SapActionConfiguration> _sapActionConfig;
private readonly IWeekDetailsProvider _weekDetailsProvider;
private readonly IPermitDecryption _permitDecryption;

private const string SapXmlPath = "SapXmlTemplates\\SAPRequest.xml";
private const string XpathImMatInfo = $"//*[local-name()='IM_MATINFO']";
Expand Down Expand Up @@ -42,19 +44,24 @@ public class EncContentSapMessageBuilder : IEncContentSapMessageBuilder
private const string Correction = "CORRECTION";
private const string IsCorrectionTrue = "Y";
private const string IsCorrectionFalse = "N";
private const string ActiveKey = "ACTIVEKEY";
private const string NextKey = "NEXTKEY";
private const string ProductStatusNewEdition = "New Edition";

public EncContentSapMessageBuilder(ILogger<EncContentSapMessageBuilder> logger,
IXmlHelper xmlHelper,
IFileSystemHelper fileSystemHelper,
IOptions<SapActionConfiguration> sapActionConfig,
IWeekDetailsProvider weekDetailsProvider
IWeekDetailsProvider weekDetailsProvider,
IPermitDecryption permitDecryption
)
{
_logger = logger;
_xmlHelper = xmlHelper;
_fileSystemHelper = fileSystemHelper;
_sapActionConfig = sapActionConfig;
_weekDetailsProvider = weekDetailsProvider;
_permitDecryption = permitDecryption;
}

/// <summary>
Expand Down Expand Up @@ -302,6 +309,8 @@ private XmlElement BuildAction(XmlDocument soapXml, Product product, UnitOfSale

List<(int sortingOrder, XmlElement itemNode)> actionAttributeList = new();

PermitKey? permitKey = action.ActionNumber == 1 || (action.ActionNumber == 7 && product.Status.StatusName == ProductStatusNewEdition) ? _permitDecryption.GetPermitKeys(product.Permit) : null;

foreach (var node in action.Attributes.Where(x => x.Section == ProductSection))
{
XmlElement itemSubNode = soapXml.CreateElement(node.XmlNodeName);
Expand All @@ -316,6 +325,22 @@ private XmlElement BuildAction(XmlDocument soapXml, Product product, UnitOfSale
{
itemSubNode.InnerText = GetXmlNodeValue(childCell.ToString());
}
else if (node.XmlNodeName == ActiveKey)
{
itemSubNode.InnerText = string.Empty;
if (permitKey != null && !string.IsNullOrEmpty(permitKey.ActiveKey))
{
itemSubNode.InnerText = permitKey.ActiveKey;
}
}
else if (node.XmlNodeName == NextKey)
{
itemSubNode.InnerText = string.Empty;
if (permitKey != null && !string.IsNullOrEmpty(permitKey.NextKey))
{
itemSubNode.InnerText = permitKey.NextKey;
}
}
else
{
object jsonFieldValue = CommonHelper.ParseXmlNode(node.JsonPropertyName, product, product.GetType());
Expand Down
3 changes: 3 additions & 0 deletions src/UKHO.ERPFacade.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using UKHO.ERPFacade.Common.IO.Azure;
using UKHO.ERPFacade.Common.Models;
using UKHO.ERPFacade.Common.Providers;
using UKHO.ERPFacade.Common.PermitDecryption;
using UKHO.ERPFacade.Common.Services;
using UKHO.Logging.EventHubLogProvider;

Expand Down Expand Up @@ -172,6 +173,7 @@ void ConfigAdditionalValuesProvider(IDictionary<string, object> additionalValues
builder.Services.Configure<SapActionConfiguration>(configuration.GetSection("SapActionConfiguration"));
sapActionConfiguration = configuration.GetSection("SapActionConfiguration").Get<SapActionConfiguration>()!;
builder.Services.Configure<EESHealthCheckEnvironmentConfiguration>(configuration.GetSection("EESHealthCheckEnvironmentConfiguration"));
builder.Services.Configure<PermitConfiguration>(configuration.GetSection("PermitConfiguration"));

builder.Services.AddInfrastructure();

Expand All @@ -190,6 +192,7 @@ void ConfigAdditionalValuesProvider(IDictionary<string, object> additionalValues
builder.Services.AddScoped<IEESClient, EESClient>();
builder.Services.AddScoped<ILicenceUpdatedSapMessageBuilder, LicenceUpdatedSapMessageBuilder>();
builder.Services.AddScoped<IWeekDetailsProvider, WeekDetailsProvider>();
builder.Services.AddScoped<IPermitDecryption, PermitDecryption>();

builder.Services.AddHealthChecks()
.AddCheck<SapServiceHealthCheck>("SapServiceHealthCheck")
Expand Down
3 changes: 3 additions & 0 deletions src/UKHO.ERPFacade.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"ServerURL": "",
"ServiceName": "",
"Environment": ""
},
"PermitConfiguration": {
"PermitDecryptionHardwareId": ""
}
}
10 changes: 10 additions & 0 deletions src/UKHO.ERPFacade.Common/Configuration/PermitConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Diagnostics.CodeAnalysis;

namespace UKHO.ERPFacade.Common.Configuration
{
[ExcludeFromCodeCoverage]
public class PermitConfiguration
{
public string PermitDecryptionHardwareId { get; set; } = string.Empty;
}
}
10 changes: 8 additions & 2 deletions src/UKHO.ERPFacade.Common/Logging/EventIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public enum EventIds
/// 940137 - All related events are not present in Azure blob.
/// </summary>
AllRelatedEventsAreNotPresentInBlob = 940137,

/// <summary>
/// 940138 - The record has been completed already.
/// </summary>
Expand All @@ -706,7 +706,13 @@ public enum EventIds
/// <summary>
/// 940141 - Invalid UkhoWeekNumber field in enccontentpublished event from EES.
/// </summary>
InvalidUkhoWeekNumber = 940141
InvalidUkhoWeekNumber = 940141,

/// <summary>
/// 940141 - Exception occured while decrypting the permit string.
/// </summary>
PermitDecryptionException = 940142

}

/// <summary>
Expand Down
Loading

0 comments on commit cee76f4

Please sign in to comment.