mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 04:32:32 +00:00
b3187d9ef3
- GetAuditLogsFunction, GetGlobalAuditLogsFunction → IMaintenanceRepository - GetRuleResultsFunction → IRuleRepository + IMaintenanceRepository + ISessionRepository - ProgressPortalFunction, FeedbackFunction → ISessionRepository - AuthFunction → IMetricsRepository https://claude.ai/code/session_01NHWJfPaa8TQHuPzMD7gG63
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System.Net;
|
|
using AutopilotMonitor.Functions.Helpers;
|
|
using AutopilotMonitor.Shared.DataAccess;
|
|
using Microsoft.Azure.Functions.Worker;
|
|
using Microsoft.Azure.Functions.Worker.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace AutopilotMonitor.Functions.Functions.Admin
|
|
{
|
|
public class GetGlobalAuditLogsFunction
|
|
{
|
|
private readonly ILogger<GetGlobalAuditLogsFunction> _logger;
|
|
private readonly IMaintenanceRepository _maintenanceRepo;
|
|
|
|
public GetGlobalAuditLogsFunction(
|
|
ILogger<GetGlobalAuditLogsFunction> logger,
|
|
IMaintenanceRepository maintenanceRepo)
|
|
{
|
|
_logger = logger;
|
|
_maintenanceRepo = maintenanceRepo;
|
|
}
|
|
|
|
[Function("GetGlobalAuditLogs")]
|
|
public async Task<HttpResponseData> Run(
|
|
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "global/audit/logs")] HttpRequestData req)
|
|
{
|
|
_logger.LogInformation("GetGlobalAuditLogs function processing request (Global Admin Mode)");
|
|
|
|
try
|
|
{
|
|
// Authentication + GlobalAdminOnly authorization enforced by PolicyEnforcementMiddleware
|
|
var userEmail = TenantHelper.GetUserIdentifier(req);
|
|
|
|
_logger.LogInformation($"Fetching all audit logs across all tenants (User: {userEmail})");
|
|
|
|
var logs = await _maintenanceRepo.GetAllAuditLogsAsync(maxResults: 100);
|
|
|
|
var response = req.CreateResponse(HttpStatusCode.OK);
|
|
await response.WriteAsJsonAsync(new
|
|
{
|
|
success = true,
|
|
count = logs.Count,
|
|
logs = logs
|
|
});
|
|
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting global audit logs");
|
|
|
|
var errorResponse = req.CreateResponse(HttpStatusCode.InternalServerError);
|
|
await errorResponse.WriteAsJsonAsync(new
|
|
{
|
|
success = false,
|
|
message = "Internal server error",
|
|
count = 0,
|
|
logs = Array.Empty<object>()
|
|
});
|
|
|
|
return errorResponse;
|
|
}
|
|
}
|
|
}
|
|
}
|