This commit is contained in:
2020-05-19 23:54:57 +00:00
parent 337482714d
commit 81270c45de
4 changed files with 104 additions and 47 deletions

View File

@@ -1,10 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using System.Threading.Tasks;
using AyaNova.Biz;
using Newtonsoft.Json.Linq;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//************************************************************************************************************** */
@@ -41,7 +45,7 @@ namespace AyaNova.Api.Controllers
private readonly AyContext ct;
private readonly ILogger<BackupController> log;
private readonly ApiServerState serverState;
/// <summary>
@@ -57,21 +61,61 @@ namespace AyaNova.Api.Controllers
serverState = apiServerState;
}
/*
LOOKAT:
A backup archive consists of a similar format to the v7 data dumper utility, json file per object in subdirectories corresponding to object type all in a zip archive
Route to trigger restore from selected file
Route to force immediate backup
Backup code in biz objects "IBackup" interface (which in turn is probably going to implement an IExport interface as it serves dual purpose
of exporting data, or maybe that's special purpose custom objects for exporting like csv etc since there is likely a graph of data involved)
- object is exported / backed up to json
Restore code in biz objects "IRestore" interface
- object(s) imported via restore and data given to them or file or whatever (See discource project)
/// <summary>
/// Trigger immediate system backup
///
/// </summary>
/// <returns>Job Id</returns>
[HttpPost("backup-now")]
[Authorize]
public async Task<IActionResult> PostServerState()
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
*/
if (!Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull | AuthorizationRoles.OpsAdminLimited))
return StatusCode(403, new ApiNotAuthorizedResponse());
//TODO: Copy the code from ImportAyaNova7Controller upload method instead of this old crap
var JobName = $"Backup (on demand)";
OpsJob j = new OpsJob();
j.Name = JobName;
j.ObjectType = AyaType.NoType;
j.JobType = JobType.Backup;
j.SubType = JobSubType.NotSet;
j.Exclusive = true;
await JobsBiz.AddJobAsync(j, ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct);
return Accepted(new { JobId = j.GId });
}
#region old shit
/*
LOOKAT:
A backup archive consists of a similar format to the v7 data dumper utility, json file per object in subdirectories corresponding to object type all in a zip archive
Route to trigger restore from selected file
Route to force immediate backup
Backup code in biz objects "IBackup" interface (which in turn is probably going to implement an IExport interface as it serves dual purpose
of exporting data, or maybe that's special purpose custom objects for exporting like csv etc since there is likely a graph of data involved)
- object is exported / backed up to json
Restore code in biz objects "IRestore" interface
- object(s) imported via restore and data given to them or file or whatever (See discource project)
*/
//TODO: Copy the code from ImportAyaNova7Controller upload method instead of this old crap
// /// <summary>
// /// Upload AyaNova backup files
@@ -85,7 +129,7 @@ Restore code in biz objects "IRestore" interface
// public async Task<IActionResult> Upload()
// {
// //Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
// try
// {
// if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
@@ -158,7 +202,7 @@ Restore code in biz objects "IRestore" interface
// section = await reader.ReadNextSectionAsync();
// }
// }
@@ -183,7 +227,7 @@ Restore code in biz objects "IRestore" interface
// }
// return mediaType.Encoding;
// }
#endregion old shit
}//eoc
}//eons