Files
BeWoPlaner/Service/ServiceUtils/Update/UpdateRequestValidator.cs
rene 77f2f549dc Update passiert über Sessions.
Sessions werden beim Plan erstellt
Sessions beinhalten Session_ID, Tenant (Zugriff auf andere Kunden unterbinden) und alle Files zum Download.
Files sind standardhaft 5x abrufbar.
Nach dem Closen von Sessions werden ALLE Sessions überprüft, ob ein Timeout vorliegt.
-> verbesserungsfähig

Sessions gelten nach 10 Minuten als ungültig.
Sessions ohne Files werden geclosed
2023-01-09 15:30:50 +01:00

105 lines
3.6 KiB
C#

using BeWo.Service.ServiceProxy;
using BeWo.Service.ServiceUtils.Paths;
using BS.SharedLauncher.DataContract;
using BS.SharedLauncher.Enums;
using BS.SharedLauncher.Information;
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace BeWo.Service.ServiceUtils.Update
{
public static class UpdateRequestValidator
{
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns>Exception string, otherwise null</returns>
public static string IsUpdatePlanRequestValid(UpdatePlanRequest request, string tenant)
{
if (!VerifySession(request.Session, tenant))
return "Session konnte nicht verifiziert werden.";
return null;
}
/// <summary>
/// Validiert die Anfrage und lädt benötigte Parameter in die Anfrage (z.b. absoluten Path zum Laden der Datei)
/// </summary>
/// <param name="request"></param>
/// <param name="tenant"></param>
/// <returns>Exception string or null if successfull</returns>
public static string Validate(UpdateFileRequest request, string tenant)
{
if (!string.IsNullOrEmpty(request.UpdateFile.AbsolutePath) ||
string.IsNullOrEmpty(request.UpdateSessionId) ||
string.IsNullOrEmpty(request.UpdateFile.RelativePath))
return "Fehlerhafte Anfrage";
var session = UpdateServerSessionManager.CurrentSession(request.UpdateSessionId);
if (session is null)
return $"Session \"{request.UpdateSessionId}\" nicht verfügbar";
if (session.Tenant != tenant)
return "Tenant konnte nicht bestätigt werden.";
if (session.FileLimiterDict.ContainsKey(
request.UpdateFile.RelativePath))
return $"Angefragte Datei nicht verfügbar. Anfrage an \"{request.UpdateFile.RelativePath}\"";
if (session.IsTimeouted)
return "Timeout";
return null;
}
private static bool VerifySession(SessionDC session, string tenant)
{
SessionInformation.Login.Username = session.Username;
SessionInformation.Login.Password = session.Password;
SessionInformation.Login.Tenant = tenant;
ServiceFacade.UpdateServerAddresses(session.CoreServerAddress);
var result = ServiceFacade.DoLauncherServiceSync(x => x.IsUserValid(session.TempUsername, session.Password, session.Pin, session.ClientID, true));
if (result == UserValidationResult.UserValid)
return true;
return false;
}
private static bool VerifyVersion(UpdateFileRequest request, string tenant)
{
var version_config = UpdateConfigReader.GetValidVersion(tenant);
return request.Version == version_config;
}
private static bool VerifySource(UpdateFileRequest request)
{
switch (request.UpdateFile.Source)
{
case UpdateFileSource.Invalid:
return false;
case UpdateFileSource.VersionDefault:
break;
case UpdateFileSource.VersionTenant:
break;
case UpdateFileSource.VersionUser:
return false;
case UpdateFileSource.OverrideTenant:
break;
case UpdateFileSource.OverrideUser:
return false;
default:
return false;
}
return true;
}
}
}