Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/DataAccess/DataAccessServiceExtensions.cs
T
Oliver Kieselbach 61892592e4 feat(rules): community rule submissions — submit custom rules from the portal, review via GA page or MCP, publish by repo commit + reseed (D-236)
Tenant admins submit references to their own gather/analyze rules; the server freezes the rule, records pre-flight findings and fire stats, and stores it under a 12-character id (RuleSubmissions, SessionReports layout). Attribution is the submitter's frozen choice (anonymous by default) and becomes the published author. Review (approve with reserved id / decline with comment) through /admin/reports/rule-submissions or the MCP tools list_rule_submissions, get_rule_submission, review_rule_submission, reseed_rules_from_github; published is derived from the global catalog, never stored. Analyze rules now get the same server-side author stamp as gather rules; ANALYZE-ID-001 carries author Community. Privacy page names the credit; bumps internal and .claude/commands gitlinks.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-09 22:53:32 +02:00

87 lines
5.1 KiB
C#

using AutopilotMonitor.Shared.DataAccess;
using AutopilotMonitor.Functions.DataAccess.TableStorage;
using Microsoft.Extensions.DependencyInjection;
namespace AutopilotMonitor.Functions.DataAccess
{
/// <summary>
/// Extension methods for registering Data Access Layer services.
/// Currently registers Azure Table Storage implementations.
/// To switch to Cosmos DB, replace the implementation registrations here.
/// </summary>
public static class DataAccessServiceExtensions
{
/// <summary>
/// Registers all Data Access Layer services with Table Storage implementations.
/// </summary>
public static IServiceCollection AddTableStorageDataAccess(this IServiceCollection services)
{
// Event publisher (no-op by default; replace with Event Hub/Service Bus implementation)
services.AddSingleton<IDataEventPublisher, NullDataEventPublisher>();
// Storage initializer
services.AddSingleton<IStorageInitializer, TableStorageInitializer>();
// Repository implementations (delegate to existing TableStorageService)
services.AddSingleton<ISessionRepository, TableSessionRepository>();
services.AddSingleton<IRuleRepository, TableRuleRepository>();
services.AddSingleton<IMetricsRepository, TableMetricsRepository>();
services.AddSingleton<IMaintenanceRepository, TableMaintenanceRepository>();
services.AddSingleton<IVulnerabilityRepository, TableVulnerabilityRepository>();
services.AddSingleton<IAdminRepository, TableAdminRepository>();
services.AddSingleton<IConfigRepository, TableConfigRepository>();
services.AddSingleton<IFeedbackRepository, TableFeedbackRepository>();
services.AddSingleton<ISessionAnnotationRepository, TableSessionAnnotationRepository>();
services.AddSingleton<IBootstrapRepository, TableBootstrapRepository>();
services.AddSingleton<INotificationRepository, TableNotificationRepository>();
services.AddSingleton<IRuleSubmissionRepository, TableRuleSubmissionRepository>();
services.AddSingleton<ITenantNotificationRepository, TableTenantNotificationRepository>();
services.AddSingleton<ISlaTenantStatusRepository, TableSlaTenantStatusRepository>();
// What's new notifier watermark (single platform row in the AdminConfiguration table).
services.AddSingleton<IWhatsNewNotificationStateRepository, TableWhatsNewNotificationStateRepository>();
services.AddSingleton<IHardwareRejectionNotificationTracker, TableHardwareRejectionNotificationTracker>();
services.AddSingleton<IDeviceSecurityRepository, TableDeviceSecurityRepository>();
services.AddSingleton<IUserUsageRepository, TableUserUsageRepository>();
services.AddSingleton<IDelegationInvitationRepository, TableDelegationInvitationRepository>();
services.AddSingleton<IDistressReportRepository, TableDistressReportRepository>();
services.AddSingleton<IOpsEventRepository, TableOpsEventRepository>();
// V2 Decision Engine repositories (Plan §M5).
services.AddSingleton<ISignalRepository, TableSignalRepository>();
services.AddSingleton<IDecisionTransitionRepository, TableDecisionTransitionRepository>();
// Tenant-offboarding audit (Marker / History / ByTenant pointer).
services.AddSingleton<IOffboardingAuditRepository, TableOffboardingAuditRepository>();
// Tenant-offboarding customs archive (PR3.B): snapshot of GatherRules /
// AnalyzeRules / ImeLogPatterns rows that were wiped during Phase 2.D-archive,
// surfaced via the Global Admin /admin/customs-archive page.
services.AddSingleton<ITenantCustomsArchiveRepository, TableTenantCustomsArchiveRepository>();
// Pre-write snapshots of TenantConfiguration/AdminConfiguration rows;
// constructor dependency of TableConfigRepository's save hook.
services.AddSingleton<IConfigBackupRepository, TableConfigBackupRepository>();
// Graph add-on permission feature: per-tenant cache of Intune script display names.
services.AddSingleton<IScriptNameCacheRepository, TableScriptNameCacheRepository>();
return services;
}
/// <summary>
/// Replaces the default NullDataEventPublisher with a custom implementation.
/// Call this AFTER AddTableStorageDataAccess() to override.
/// Example: services.AddEventStreaming&lt;EventHubPublisher&gt;();
/// </summary>
public static IServiceCollection AddEventStreaming<TPublisher>(this IServiceCollection services)
where TPublisher : class, IDataEventPublisher
{
// Remove existing registration and replace
var descriptor = services.FirstOrDefault(d => d.ServiceType == typeof(IDataEventPublisher));
if (descriptor != null)
services.Remove(descriptor);
services.AddSingleton<IDataEventPublisher, TPublisher>();
return services;
}
}
}