Added Viewer and

change to App Setting File from Constants
This commit is contained in:
2022-07-27 10:47:57 -07:00
parent 2afec95704
commit b155863645
1012 changed files with 53014 additions and 110896 deletions

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Services;
@ -15,20 +15,19 @@ namespace OI.Metrology.Archive.ApiContollers;
[ApiController]
public class InboundController : ControllerBase
{
private IConfiguration Config { get; }
private ILogger Logger { get; }
private readonly ILogger _Logger;
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IAttachmentsService _AttachmentService;
private readonly IInboundDataService _InboundDataService;
protected IMetrologyRepo _Repo;
protected IAttachmentsService _AttachmentService;
protected IInboundDataService _InboundDataService;
public InboundController(IConfiguration config, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
{
Config = config;
Logger = logger;
_Repo = repo;
_InboundDataService = inboundDataService;
_Logger = logger;
_AppSettings = appSettings;
_AttachmentService = attachmentService;
_InboundDataService = inboundDataService;
}
// this class represents the API response back to the client
@ -57,7 +56,7 @@ public class InboundController : ControllerBase
if (!IsIPAddressAllowed())
{
Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
_Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
r.Errors.Add("Remote IP is not on allowed list");
return Unauthorized(r);
}
@ -115,7 +114,7 @@ public class InboundController : ControllerBase
{
if (!IsIPAddressAllowed())
{
Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
_Logger.LogInformation($"Rejected remote IP: {HttpContext.Connection.RemoteIpAddress}");
return Unauthorized("Remote IP is not on allowed list");
}
@ -145,14 +144,13 @@ public class InboundController : ControllerBase
protected bool IsIPAddressAllowed()
{
string allowedList = Config[Constants.InboundApiAllowedIPList];
if (string.IsNullOrWhiteSpace(allowedList))
if (string.IsNullOrWhiteSpace(_AppSettings.InboundApiAllowedIPList))
return true;
System.Net.IPAddress remoteIP = HttpContext.Connection.RemoteIpAddress;
byte[] remoteIPBytes = remoteIP.GetAddressBytes();
string[] allowedIPs = allowedList.Split(';');
string[] allowedIPs = _AppSettings.InboundApiAllowedIPList.Split(';');
foreach (string ip in allowedIPs)
{
System.Net.IPAddress parsedIP;