mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-22 06:18:06 +00:00
Remove some response-only properties from the Task model (#2335)
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Azure.Functions.Worker;
|
using Microsoft.Azure.Functions.Worker;
|
||||||
using Microsoft.Azure.Functions.Worker.Http;
|
using Microsoft.Azure.Functions.Worker.Http;
|
||||||
|
|
||||||
@ -31,20 +32,36 @@ public class Tasks {
|
|||||||
return await _context.RequestHandling.NotOk(req, request.ErrorV, "task get");
|
return await _context.RequestHandling.NotOk(req, request.ErrorV, "task get");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.OkV.TaskId != null) {
|
if (request.OkV.TaskId is Guid taskId) {
|
||||||
var task = await _context.TaskOperations.GetByTaskId(request.OkV.TaskId.Value);
|
var task = await _context.TaskOperations.GetByTaskId(taskId);
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
return await _context.RequestHandling.NotOk(req, new Error(ErrorCode.INVALID_REQUEST, new[] { "unable to find task"
|
return await _context.RequestHandling.NotOk(
|
||||||
}), "task get");
|
req,
|
||||||
|
new Error(
|
||||||
|
ErrorCode.INVALID_REQUEST,
|
||||||
|
new[] { "unable to find task" }),
|
||||||
|
"task get");
|
||||||
}
|
}
|
||||||
task.Nodes = await _context.NodeTasksOperations.GetNodeAssignments(request.OkV.TaskId.Value).ToListAsync();
|
|
||||||
task.Events = await _context.TaskEventOperations.GetSummary(request.OkV.TaskId.Value).ToListAsync();
|
|
||||||
|
|
||||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
var (nodes, events) = await (
|
||||||
await response.WriteAsJsonAsync(task);
|
_context.NodeTasksOperations.GetNodeAssignments(taskId).ToListAsync().AsTask(),
|
||||||
return response;
|
_context.TaskEventOperations.GetSummary(taskId).ToListAsync().AsTask());
|
||||||
|
|
||||||
|
var result = new TaskSearchResult(
|
||||||
|
JobId: task.JobId,
|
||||||
|
TaskId: task.TaskId,
|
||||||
|
State: task.State,
|
||||||
|
Os: task.Os,
|
||||||
|
Config: task.Config,
|
||||||
|
Error: task.Error,
|
||||||
|
Auth: task.Auth,
|
||||||
|
Heartbeat: task.Heartbeat,
|
||||||
|
EndTime: task.EndTime,
|
||||||
|
UserInfo: task.UserInfo,
|
||||||
|
Nodes: nodes,
|
||||||
|
Events: events);
|
||||||
|
|
||||||
|
return await RequestHandling.Ok(req, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tasks = await _context.TaskOperations.SearchAll().ToListAsync();
|
var tasks = await _context.TaskOperations.SearchAll().ToListAsync();
|
||||||
|
@ -256,8 +256,6 @@ public record Task(
|
|||||||
DateTimeOffset? Heartbeat = null,
|
DateTimeOffset? Heartbeat = null,
|
||||||
DateTimeOffset? EndTime = null,
|
DateTimeOffset? EndTime = null,
|
||||||
UserInfo? UserInfo = null) : StatefulEntityBase<TaskState>(State) {
|
UserInfo? UserInfo = null) : StatefulEntityBase<TaskState>(State) {
|
||||||
public List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
|
|
||||||
public List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record TaskEvent(
|
public record TaskEvent(
|
||||||
|
@ -35,6 +35,21 @@ public record NodeSearchResult(
|
|||||||
bool DebugKeepNode
|
bool DebugKeepNode
|
||||||
) : BaseResponse();
|
) : BaseResponse();
|
||||||
|
|
||||||
|
public record TaskSearchResult(
|
||||||
|
Guid JobId,
|
||||||
|
Guid TaskId,
|
||||||
|
TaskState State,
|
||||||
|
Os Os,
|
||||||
|
TaskConfig Config,
|
||||||
|
Error? Error,
|
||||||
|
Authentication? Auth,
|
||||||
|
DateTimeOffset? Heartbeat,
|
||||||
|
DateTimeOffset? EndTime,
|
||||||
|
UserInfo? UserInfo,
|
||||||
|
List<TaskEventSummary> Events,
|
||||||
|
List<NodeAssignment> Nodes
|
||||||
|
) : BaseResponse();
|
||||||
|
|
||||||
public record BoolResult(
|
public record BoolResult(
|
||||||
bool Result
|
bool Result
|
||||||
) : BaseResponse();
|
) : BaseResponse();
|
||||||
|
Reference in New Issue
Block a user