mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 04:32:32 +00:00
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
This commit is contained in:
@@ -10,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Admin
|
||||
public class GetAuditLogsFunction
|
||||
{
|
||||
private readonly ILogger<GetAuditLogsFunction> _logger;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly IMaintenanceRepository _maintenanceRepo;
|
||||
|
||||
public GetAuditLogsFunction(ILogger<GetAuditLogsFunction> logger, TableStorageService storageService)
|
||||
public GetAuditLogsFunction(ILogger<GetAuditLogsFunction> logger, IMaintenanceRepository maintenanceRepo)
|
||||
{
|
||||
_logger = logger;
|
||||
_storageService = storageService;
|
||||
_maintenanceRepo = maintenanceRepo;
|
||||
}
|
||||
|
||||
[Function("GetAuditLogs")]
|
||||
@@ -33,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Admin
|
||||
_logger.LogInformation($"Fetching audit logs for tenant {tenantId} by user {userIdentifier}");
|
||||
|
||||
// Get audit logs from storage
|
||||
var logs = await _storageService.GetAuditLogsAsync(tenantId, maxResults: 100);
|
||||
var logs = await _maintenanceRepo.GetAuditLogsAsync(tenantId, maxResults: 100);
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
await response.WriteAsJsonAsync(new
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
using System.Net;
|
||||
using AutopilotMonitor.Functions.Helpers;
|
||||
using AutopilotMonitor.Functions.Services;
|
||||
using AutopilotMonitor.Shared.DataAccess;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -10,14 +10,14 @@ namespace AutopilotMonitor.Functions.Functions.Admin
|
||||
public class GetGlobalAuditLogsFunction
|
||||
{
|
||||
private readonly ILogger<GetGlobalAuditLogsFunction> _logger;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly IMaintenanceRepository _maintenanceRepo;
|
||||
|
||||
public GetGlobalAuditLogsFunction(
|
||||
ILogger<GetGlobalAuditLogsFunction> logger,
|
||||
TableStorageService storageService)
|
||||
IMaintenanceRepository maintenanceRepo)
|
||||
{
|
||||
_logger = logger;
|
||||
_storageService = storageService;
|
||||
_maintenanceRepo = maintenanceRepo;
|
||||
}
|
||||
|
||||
[Function("GetGlobalAuditLogs")]
|
||||
@@ -33,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Admin
|
||||
|
||||
_logger.LogInformation($"Fetching all audit logs across all tenants (User: {userEmail})");
|
||||
|
||||
var logs = await _storageService.GetAllAuditLogsAsync(maxResults: 100);
|
||||
var logs = await _maintenanceRepo.GetAllAuditLogsAsync(maxResults: 100);
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
await response.WriteAsJsonAsync(new
|
||||
|
||||
@@ -6,6 +6,7 @@ using AutopilotMonitor.Functions.Extensions;
|
||||
using AutopilotMonitor.Functions.Helpers;
|
||||
using AutopilotMonitor.Functions.Services;
|
||||
using AutopilotMonitor.Shared;
|
||||
using AutopilotMonitor.Shared.DataAccess;
|
||||
using AutopilotMonitor.Shared.Models;
|
||||
using Azure;
|
||||
using Azure.Data.Tables;
|
||||
@@ -23,7 +24,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback
|
||||
private readonly AdminConfigurationService _adminConfigService;
|
||||
private readonly TenantAdminsService _tenantAdminsService;
|
||||
private readonly TelegramNotificationService _telegramNotificationService;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly ISessionRepository _sessionRepo;
|
||||
private readonly TableClient _feedbackTableClient;
|
||||
|
||||
public FeedbackFunction(
|
||||
@@ -32,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback
|
||||
AdminConfigurationService adminConfigService,
|
||||
TenantAdminsService tenantAdminsService,
|
||||
TelegramNotificationService telegramNotificationService,
|
||||
TableStorageService storageService,
|
||||
ISessionRepository sessionRepo,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -40,7 +41,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback
|
||||
_adminConfigService = adminConfigService;
|
||||
_tenantAdminsService = tenantAdminsService;
|
||||
_telegramNotificationService = telegramNotificationService;
|
||||
_storageService = storageService;
|
||||
_sessionRepo = sessionRepo;
|
||||
|
||||
var connectionString = configuration["AzureTableStorageConnectionString"];
|
||||
var serviceClient = new TableServiceClient(connectionString);
|
||||
@@ -78,7 +79,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback
|
||||
return await WriteJson(req, new { eligible = false });
|
||||
|
||||
// 5. Sessions check — at least 1 session exists
|
||||
var sessionPage = await _storageService.GetSessionsAsync(tenantId, maxResults: 1);
|
||||
var sessionPage = await _sessionRepo.GetSessionsAsync(tenantId, maxResults: 1);
|
||||
if (sessionPage.Sessions.Count == 0)
|
||||
return await WriteJson(req, new { eligible = false });
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using AutopilotMonitor.Functions.Extensions;
|
||||
using AutopilotMonitor.Functions.Services;
|
||||
using AutopilotMonitor.Shared.DataAccess;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
@@ -18,7 +19,7 @@ public class AuthFunction
|
||||
private readonly GlobalAdminService _globalAdminService;
|
||||
private readonly TenantConfigurationService _tenantConfigService;
|
||||
private readonly TenantAdminsService _tenantAdminsService;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly IMetricsRepository _metricsRepo;
|
||||
private readonly PreviewWhitelistService _previewWhitelistService;
|
||||
private readonly TelegramNotificationService _telegramNotificationService;
|
||||
private readonly GlobalNotificationService _globalNotificationService;
|
||||
@@ -28,7 +29,7 @@ public class AuthFunction
|
||||
GlobalAdminService globalAdminService,
|
||||
TenantConfigurationService tenantConfigService,
|
||||
TenantAdminsService tenantAdminsService,
|
||||
TableStorageService storageService,
|
||||
IMetricsRepository metricsRepo,
|
||||
PreviewWhitelistService previewWhitelistService,
|
||||
TelegramNotificationService telegramNotificationService,
|
||||
GlobalNotificationService globalNotificationService)
|
||||
@@ -37,7 +38,7 @@ public class AuthFunction
|
||||
_globalAdminService = globalAdminService;
|
||||
_tenantConfigService = tenantConfigService;
|
||||
_tenantAdminsService = tenantAdminsService;
|
||||
_storageService = storageService;
|
||||
_metricsRepo = metricsRepo;
|
||||
_previewWhitelistService = previewWhitelistService;
|
||||
_telegramNotificationService = telegramNotificationService;
|
||||
_globalNotificationService = globalNotificationService;
|
||||
@@ -172,7 +173,7 @@ public class AuthFunction
|
||||
bool canManageBootstrapTokens = memberRole?.CanManageBootstrapTokens ?? false;
|
||||
|
||||
// Record user login activity for metrics tracking
|
||||
_ = _storageService.RecordUserLoginAsync(tenantId, upn, displayName, objectId)
|
||||
_ = _metricsRepo.RecordUserLoginAsync(tenantId, upn, displayName, objectId)
|
||||
.ContinueWith(t => _logger.LogWarning(t.Exception?.InnerException, "Fire-and-forget RecordUserLoginAsync failed"), TaskContinuationOptions.OnlyOnFaulted);
|
||||
|
||||
var userInfo = new
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Net;
|
||||
using System.Web;
|
||||
using AutopilotMonitor.Functions.Helpers;
|
||||
using AutopilotMonitor.Functions.Services;
|
||||
using AutopilotMonitor.Shared.DataAccess;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -16,16 +17,16 @@ namespace AutopilotMonitor.Functions.Functions.Progress;
|
||||
public class ProgressPortalFunction
|
||||
{
|
||||
private readonly ILogger<ProgressPortalFunction> _logger;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly ISessionRepository _sessionRepo;
|
||||
private readonly GlobalAdminService _globalAdminService;
|
||||
|
||||
public ProgressPortalFunction(
|
||||
ILogger<ProgressPortalFunction> logger,
|
||||
TableStorageService storageService,
|
||||
ISessionRepository sessionRepo,
|
||||
GlobalAdminService globalAdminService)
|
||||
{
|
||||
_logger = logger;
|
||||
_storageService = storageService;
|
||||
_sessionRepo = sessionRepo;
|
||||
_globalAdminService = globalAdminService;
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ProgressPortalFunction
|
||||
|
||||
_logger.LogInformation("ProgressGetSessions: Fetching sessions for tenant {TenantId}", tenantId);
|
||||
|
||||
var page = await _storageService.GetSessionsAsync(tenantId, maxResults: 100);
|
||||
var page = await _sessionRepo.GetSessionsAsync(tenantId, maxResults: 100);
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
await response.WriteAsJsonAsync(new
|
||||
@@ -137,7 +138,7 @@ public class ProgressPortalFunction
|
||||
sessionPrefix, userIdentifier, requestedTenantId);
|
||||
}
|
||||
|
||||
var events = await _storageService.GetSessionEventsAsync(requestedTenantId, sessionId);
|
||||
var events = await _sessionRepo.GetSessionEventsAsync(requestedTenantId, sessionId);
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
await response.WriteAsJsonAsync(new
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Net;
|
||||
using System.Web;
|
||||
using AutopilotMonitor.Functions.Helpers;
|
||||
using AutopilotMonitor.Functions.Services;
|
||||
using AutopilotMonitor.Shared.DataAccess;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -16,18 +17,24 @@ namespace AutopilotMonitor.Functions.Functions.Rules
|
||||
public class GetRuleResultsFunction
|
||||
{
|
||||
private readonly ILogger<GetRuleResultsFunction> _logger;
|
||||
private readonly TableStorageService _storageService;
|
||||
private readonly IRuleRepository _ruleRepo;
|
||||
private readonly IMaintenanceRepository _maintenanceRepo;
|
||||
private readonly ISessionRepository _sessionRepo;
|
||||
private readonly AnalyzeRuleService _analyzeRuleService;
|
||||
private readonly GlobalAdminService _globalAdminService;
|
||||
|
||||
public GetRuleResultsFunction(
|
||||
ILogger<GetRuleResultsFunction> logger,
|
||||
TableStorageService storageService,
|
||||
IRuleRepository ruleRepo,
|
||||
IMaintenanceRepository maintenanceRepo,
|
||||
ISessionRepository sessionRepo,
|
||||
AnalyzeRuleService analyzeRuleService,
|
||||
GlobalAdminService globalAdminService)
|
||||
{
|
||||
_logger = logger;
|
||||
_storageService = storageService;
|
||||
_ruleRepo = ruleRepo;
|
||||
_maintenanceRepo = maintenanceRepo;
|
||||
_sessionRepo = sessionRepo;
|
||||
_analyzeRuleService = analyzeRuleService;
|
||||
_globalAdminService = globalAdminService;
|
||||
}
|
||||
@@ -66,15 +73,15 @@ namespace AutopilotMonitor.Functions.Functions.Rules
|
||||
{
|
||||
try
|
||||
{
|
||||
var ruleEngine = new RuleEngine(_analyzeRuleService, _storageService, _logger);
|
||||
var ruleEngine = new RuleEngine(_analyzeRuleService, _ruleRepo, _sessionRepo, _logger);
|
||||
var freshResults = await ruleEngine.AnalyzeSessionAsync(effectiveTenantId, sessionId, reanalyze: true);
|
||||
|
||||
// Delete existing results so stale entries don't persist after re-analysis
|
||||
await _storageService.DeleteSessionRuleResultsAsync(effectiveTenantId, sessionId);
|
||||
await _maintenanceRepo.DeleteSessionRuleResultsAsync(effectiveTenantId, sessionId);
|
||||
|
||||
foreach (var result in freshResults)
|
||||
{
|
||||
await _storageService.StoreRuleResultAsync(result);
|
||||
await _ruleRepo.StoreRuleResultAsync(result);
|
||||
}
|
||||
|
||||
_logger.LogInformation($"On-demand re-analysis for session {sessionId}: {freshResults.Count} issue(s) detected");
|
||||
@@ -85,7 +92,7 @@ namespace AutopilotMonitor.Functions.Functions.Rules
|
||||
}
|
||||
}
|
||||
|
||||
var results = await _storageService.GetRuleResultsAsync(effectiveTenantId, sessionId);
|
||||
var results = await _ruleRepo.GetRuleResultsAsync(effectiveTenantId, sessionId);
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
await response.WriteAsJsonAsync(new
|
||||
|
||||
Reference in New Issue
Block a user