Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetGlobalAuditLogsFunction.cs
T
Claude b3187d9ef3 Migrate AuditLogs, RuleResults, Progress, Feedback, Auth functions to DAL
- GetAuditLogsFunction, GetGlobalAuditLogsFunction → IMaintenanceRepository
- GetRuleResultsFunction → IRuleRepository + IMaintenanceRepository + ISessionRepository
- ProgressPortalFunction, FeedbackFunction → ISessionRepository
- AuthFunction → IMetricsRepository

https://claude.ai/code/session_01NHWJfPaa8TQHuPzMD7gG63
2026-03-27 06:42:06 +00:00

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;
}
}
}
}