Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetAuditLogsFunction.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 GetAuditLogsFunction
{
private readonly ILogger<GetAuditLogsFunction> _logger;
private readonly IMaintenanceRepository _maintenanceRepo;
public GetAuditLogsFunction(ILogger<GetAuditLogsFunction> logger, IMaintenanceRepository maintenanceRepo)
{
_logger = logger;
_maintenanceRepo = maintenanceRepo;
}
[Function("GetAuditLogs")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "audit/logs")] HttpRequestData req)
{
_logger.LogInformation("GetAuditLogs function processing request");
try
{
// Authentication + MemberRead authorization enforced by PolicyEnforcementMiddleware
string tenantId = TenantHelper.GetTenantId(req);
string userIdentifier = TenantHelper.GetUserIdentifier(req);
_logger.LogInformation($"Fetching audit logs for tenant {tenantId} by user {userIdentifier}");
// Get audit logs from storage
var logs = await _maintenanceRepo.GetAuditLogsAsync(tenantId, 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 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;
}
}
}
}