Fixing coresoapapi
This commit is contained in:
+4
-3
@@ -1,5 +1,6 @@
|
||||
using Autofac;
|
||||
using Autofac.Integration.WebApi;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Configuration;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.DataAccess;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Models;
|
||||
@@ -39,7 +40,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.App_Start
|
||||
RegisterSoapClasses(builder);
|
||||
|
||||
// Get apikey from secret file if available, otherwise fallback to appsettings
|
||||
var seqApiKey = ConfigurationManager.AppSettings["serilog:write-to:Seq.apiKey"];
|
||||
var seqApiKey = AppSettingsResolver.Get("serilog:write-to:Seq.apiKey");
|
||||
try
|
||||
{
|
||||
seqApiKey = File.ReadAllText("/vault/secrets/core-soap-api-wrapper-api-seq-api-key.json").Trim();
|
||||
@@ -52,7 +53,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.App_Start
|
||||
{
|
||||
return new LoggerConfiguration().Enrich.FromLogContext()
|
||||
.Enrich.With<HttpRequestIdEnricher>()
|
||||
.WriteTo.Seq(ConfigurationManager.AppSettings["serilog:write-to:Seq.serverUrl"], LogEventLevel.Information, 1000, null, seqApiKey)
|
||||
.WriteTo.Seq(AppSettingsResolver.Get("serilog:write-to:Seq.serverUrl"), LogEventLevel.Information, 1000, null, seqApiKey)
|
||||
.CreateLogger();
|
||||
}).SingleInstance();
|
||||
|
||||
@@ -86,4 +87,4 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.App_Start
|
||||
builder.RegisterType<CoreCmcConnection>().As<ICoreCmcConnection>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-9
@@ -1,7 +1,7 @@
|
||||
using Serilog;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Configuration;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -22,11 +22,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Attributes
|
||||
|
||||
public ApiKeyAuthorizeAttribute()
|
||||
{
|
||||
_externalApiKeySet = ConfigurationManager.AppSettings.AllKeys
|
||||
.Where(k => k.StartsWith(KeySetPrefix))
|
||||
.ToDictionary(
|
||||
k => k.Substring(KeySetPrefix.Length),
|
||||
k => ConfigurationManager.AppSettings[k]);
|
||||
_externalApiKeySet = AppSettingsResolver.GetByPrefix(KeySetPrefix);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -37,7 +33,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Attributes
|
||||
// do nothing, fallback to appsettings value if secret file is not found or cannot be read
|
||||
}
|
||||
|
||||
_authenticationFailureBehavior = ConfigurationManager.AppSettings["ApiSecurityConfiguration:ApiKeyAuthenticationFailureBehavior"] ?? "Error";
|
||||
_authenticationFailureBehavior = AppSettingsResolver.Get("ApiSecurityConfiguration:ApiKeyAuthenticationFailureBehavior") ?? "Error";
|
||||
}
|
||||
|
||||
protected override bool IsAuthorized(HttpActionContext actionContext)
|
||||
@@ -84,4 +80,4 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Attributes
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LCU.API.Internal.CoreSoapApiWrapper.Configuration
|
||||
{
|
||||
public static class AppSettingsResolver
|
||||
{
|
||||
private const string ExternalAppSettingsPath = "/app/config/environment-appsettings/appsettings.config";
|
||||
|
||||
private static readonly Lazy<IReadOnlyDictionary<string, string>> ExternalSettings =
|
||||
new Lazy<IReadOnlyDictionary<string, string>>(LoadExternalSettings);
|
||||
|
||||
public static string Get(string key)
|
||||
{
|
||||
if (ExternalSettings.Value.TryGetValue(key, out var value) && !string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return ConfigurationManager.AppSettings[key];
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetByPrefix(string prefix)
|
||||
{
|
||||
var mergedSettings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
|
||||
foreach (var key in appSettings.AllKeys.Where(k => k != null && k.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
mergedSettings[key.Substring(prefix.Length)] = appSettings[key];
|
||||
}
|
||||
|
||||
foreach (var kvp in ExternalSettings.Value.Where(kvp => kvp.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
mergedSettings[kvp.Key.Substring(prefix.Length)] = kvp.Value;
|
||||
}
|
||||
|
||||
return mergedSettings;
|
||||
}
|
||||
|
||||
private static IReadOnlyDictionary<string, string> LoadExternalSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ExternalAppSettingsPath))
|
||||
{
|
||||
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
var document = XDocument.Load(ExternalAppSettingsPath);
|
||||
|
||||
return document.Root?
|
||||
.Elements("add")
|
||||
.Where(element => element.Attribute("key") != null)
|
||||
.ToDictionary(
|
||||
element => element.Attribute("key").Value,
|
||||
element => element.Attribute("value")?.Value,
|
||||
StringComparer.OrdinalIgnoreCase)
|
||||
?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Web.Http;
|
||||
using Serilog;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Configuration;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Models;
|
||||
|
||||
namespace LCU.API.Internal.CoreSoapApiWrapper.Controllers
|
||||
@@ -21,7 +21,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Controllers
|
||||
var result = new EnvironmentView();
|
||||
result.Application = "LCU.API.Internal.CoreSoapApiWrapper";
|
||||
result.CurrentDate = DateTime.Now;
|
||||
result.Environment = ConfigurationManager.AppSettings["KnownEnvironment"];
|
||||
result.Environment = AppSettingsResolver.Get("KnownEnvironment");
|
||||
Log.Verbose($"{result.Application}'s status endpoint was hit in {result.Environment}");
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Models;
|
||||
|
||||
namespace LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities
|
||||
@@ -44,7 +45,9 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities
|
||||
|
||||
private TransactionOutput SubmitTransactionInput(TransactionInput transactionInput)
|
||||
{
|
||||
var client = new CoreApiServiceClient(_soapConfiguration.Endpoint);
|
||||
var client = string.IsNullOrWhiteSpace(_soapConfiguration.CoreApiServiceUrl)
|
||||
? new CoreApiServiceClient(_soapConfiguration.Endpoint)
|
||||
: new CoreApiServiceClient(_soapConfiguration.Endpoint, new EndpointAddress(_soapConfiguration.CoreApiServiceUrl));
|
||||
TransactionOutput output = client.SubmitRequest(transactionInput);
|
||||
|
||||
if (output?.Output?.UserAuthentication == null || output?.Output?.Responses == null)
|
||||
@@ -60,4 +63,4 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -181,6 +181,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App_Start\AssignSecurityRequirements.cs" />
|
||||
<Compile Include="Configuration\AppSettingsResolver.cs" />
|
||||
<Compile Include="Attributes\ApiKeyAuthorizeAttribute.cs" />
|
||||
<Compile Include="App_Start\FilterConfig.cs" />
|
||||
<Compile Include="App_Start\IocBootstrapper.cs" />
|
||||
@@ -336,4 +337,4 @@
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target> -->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
+24
-21
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using LCU.API.Internal.CoreSoapApiWrapper.Configuration;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
|
||||
@@ -10,25 +11,26 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Models
|
||||
{
|
||||
int defaultValue;
|
||||
|
||||
SafUrl = ConfigurationManager.AppSettings["soapconnection:safUrl"];
|
||||
DeviceId = ConfigurationManager.AppSettings["soapconnection:deviceId"];
|
||||
UserId = ReadSecret("/vault/secrets/core-soap-api-wrapper-soap-connection-user-id.json") ?? ConfigurationManager.AppSettings["soapconnection:userId"];
|
||||
Password = ReadSecret("/vault/secrets/core-soap-api-wrapper-soap-connection-password.json") ?? ConfigurationManager.AppSettings["soapconnection:password"];
|
||||
EnvironmentCode = ConfigurationManager.AppSettings["soapconnection:prodEnvCd"];
|
||||
DefCode = ConfigurationManager.AppSettings["soapconnection:prodDefCd"];
|
||||
ApplicationId = ConfigurationManager.AppSettings["soapconnection:applId"];
|
||||
Endpoint = ConfigurationManager.AppSettings["soapconnection:endpoint"];
|
||||
ApprovalPersonNumber = ConfigurationManager.AppSettings["soapconnection:approvalpersonnumber"];
|
||||
OverrideCashBoxNumber = ConfigurationManager.AppSettings["soapconnection:overridecashboxnumber"];
|
||||
SocketDeviceId = ConfigurationManager.AppSettings["socketconnection:deviceId"];
|
||||
SocketApplicationId = ConfigurationManager.AppSettings["socketconnection:applId"];
|
||||
SocketUserId = ReadSecret("/vault/secrets/core-soap-api-wrapper-socket-connection-user-id.json") ?? ConfigurationManager.AppSettings["socketconnection:userId"];
|
||||
SocketPassword = ReadSecret("/vault/secrets/core-soap-api-wrapper-socket-connection-password.json") ?? ConfigurationManager.AppSettings["socketconnection:password"];
|
||||
SocketTimeout = int.TryParse(ConfigurationManager.AppSettings["socketconnection:timeout"], out defaultValue) ? defaultValue : 10000;
|
||||
IPAddress = ConfigurationManager.AppSettings["socketconnection:ipAddress"];
|
||||
PortId = int.TryParse(ConfigurationManager.AppSettings["socketconnection:portId"], out defaultValue) ? defaultValue : 2503;
|
||||
RequestType = ConfigurationManager.AppSettings["socketconnection:reqType"];
|
||||
AuthenticationType = ConfigurationManager.AppSettings["socketconnection:authType"];
|
||||
SafUrl = AppSettingsResolver.Get("soapconnection:safUrl");
|
||||
DeviceId = AppSettingsResolver.Get("soapconnection:deviceId");
|
||||
UserId = ReadSecret("/vault/secrets/core-soap-api-wrapper-soap-connection-user-id.json") ?? AppSettingsResolver.Get("soapconnection:userId");
|
||||
Password = ReadSecret("/vault/secrets/core-soap-api-wrapper-soap-connection-password.json") ?? AppSettingsResolver.Get("soapconnection:password");
|
||||
EnvironmentCode = AppSettingsResolver.Get("soapconnection:prodEnvCd");
|
||||
DefCode = AppSettingsResolver.Get("soapconnection:prodDefCd");
|
||||
ApplicationId = AppSettingsResolver.Get("soapconnection:applId");
|
||||
Endpoint = AppSettingsResolver.Get("soapconnection:endpoint");
|
||||
CoreApiServiceUrl = AppSettingsResolver.Get("soapconnection:coreApiServiceUrl");
|
||||
ApprovalPersonNumber = AppSettingsResolver.Get("soapconnection:approvalpersonnumber");
|
||||
OverrideCashBoxNumber = AppSettingsResolver.Get("soapconnection:overridecashboxnumber");
|
||||
SocketDeviceId = AppSettingsResolver.Get("socketconnection:deviceId");
|
||||
SocketApplicationId = AppSettingsResolver.Get("socketconnection:applId");
|
||||
SocketUserId = ReadSecret("/vault/secrets/core-soap-api-wrapper-socket-connection-user-id.json") ?? AppSettingsResolver.Get("socketconnection:userId");
|
||||
SocketPassword = ReadSecret("/vault/secrets/core-soap-api-wrapper-socket-connection-password.json") ?? AppSettingsResolver.Get("socketconnection:password");
|
||||
SocketTimeout = int.TryParse(AppSettingsResolver.Get("socketconnection:timeout"), out defaultValue) ? defaultValue : 10000;
|
||||
IPAddress = AppSettingsResolver.Get("socketconnection:ipAddress");
|
||||
PortId = int.TryParse(AppSettingsResolver.Get("socketconnection:portId"), out defaultValue) ? defaultValue : 2503;
|
||||
RequestType = AppSettingsResolver.Get("socketconnection:reqType");
|
||||
AuthenticationType = AppSettingsResolver.Get("socketconnection:authType");
|
||||
|
||||
string ReadSecret(string path)
|
||||
{
|
||||
@@ -54,6 +56,7 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Models
|
||||
public string DefCode { get; set; }
|
||||
public string ApplicationId { get; set; }
|
||||
public string Endpoint { get; set; }
|
||||
public string CoreApiServiceUrl { get; set; }
|
||||
public string ApprovalPersonNumber { get; set; }
|
||||
public string OverrideCashBoxNumber { get; set; }
|
||||
public string SocketDeviceId { get; set; }
|
||||
@@ -66,4 +69,4 @@ namespace LCU.API.Internal.CoreSoapApiWrapper.Models
|
||||
public string RequestType { get; set; }
|
||||
public string AuthenticationType { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -20,6 +20,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://UATapi.dna.lcu-internal.com:10005/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<!-- Socket Connection-->
|
||||
|
||||
+1
@@ -23,6 +23,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://prodapi.dna.lcu-internal.com:10002/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<!-- Socket Connection-->
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://UATapi.dna.lcu-internal.com:10005/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
|
||||
<!-- Socket Connection-->
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" />
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" />
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" />
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://UATapi.dna.lcu-internal.com:10005/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" />
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" />
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" />
|
||||
<!-- END Soap Connection -->
|
||||
|
||||
+1
@@ -15,6 +15,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" />
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" />
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" />
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://prodapi.dna.lcu-internal.com:10002/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" />
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" />
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" />
|
||||
<!-- END Soap Connection -->
|
||||
|
||||
+1
@@ -15,6 +15,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" />
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" />
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" />
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://UATapi.dna.lcu-internal.com:10005/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" />
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" />
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" />
|
||||
<!-- END Soap Connection -->
|
||||
|
||||
+1
@@ -15,6 +15,7 @@
|
||||
<add key="soapconnection:prodDefCd" value="SAF2006" />
|
||||
<add key="soapconnection:applId" value="7e837e75-2e19-45d5-8c3a-4735a275a6cf" />
|
||||
<add key="soapconnection:endpoint" value="lcu_10002" />
|
||||
<add key="soapconnection:coreApiServiceUrl" value="https://UATapi.dna.lcu-internal.com:10005/Extensions/DNA.CoreApiService/CoreApiService.svc/Soap11" />
|
||||
<add key="soapconnection:approvalpersonnumber" value="5775" />
|
||||
<add key="soapconnection:overridecashboxnumber" value="800" />
|
||||
<!-- END Soap Connection -->
|
||||
|
||||
Reference in New Issue
Block a user