AutoMate Technisch Help

API Plugins

AutoMate.API gebruikt een plugin architectuur voor loosely coupled uitbreidingen. Plugins zijn aparte projecten onder /API/AutoMate.API.Plugins.* die eigen endpoints, services en models bevatten. Ze worden gerefereerd door het hoofd-API project en registreren hun dependencies via extension methods op IServiceCollection.

Plugin structuur

Een plugin project:

  • Bevat eigen FastEndpoints endpoints die automatisch ontdekt worden door de assembly filter

  • Registreert dependencies via een RegisterDependencies extension method

  • Wordt geregistreerd in Program.cs van de hoofd-API

// Program.cs (hoofd-API) builder.Services.RegisterMsGraphPlugin(); builder.Services.AddAutomateEmail(builder.Configuration); builder.Services.AddAutomateAuditLog(builder.Configuration);

AuditLog Plugin

Project: API/AutoMate.API.Plugins.AuditLog

Doel: Audit logging met meerdere backends, configureerbaar per tenant.

Providers

De plugin ondersteunt twee sink backends:

Sink

Klasse

Registratie key

Seq

SeqAuditLogSink

"seq"

Azure Table Storage

AzureTableAuditLogSink

"azure-table"

Beide sinks zijn geregistreerd als KeyedSingleton<IAuditLogSink>. Welke sink actief is voor een tenant wordt bepaald door IAuditLogProviderResolver.

Provider resolver

public interface IAuditLogProviderResolver { Task<AuditLogProvider?> GetProviderForTenantAsync(Guid tenantId, CancellationToken ct = default); }

De plugin registreert DefaultAuditLogProviderResolver als standaard implementatie, die null teruggeeft (het systeem valt dan terug op de geconfigureerde DefaultProvider in AuditLogOptions). De hoofd-API overschrijft dit met TenantAuditLogProviderResolver, die de provider opzoekt in de tenant tabel.

// Overschrijf de default resolver vanuit Program.cs builder.Services.AddScoped<IAuditLogProviderResolver, TenantAuditLogProviderResolver>();

AuditLog configuratie

{ "AuditLog": { "DefaultProvider": "seq", "Seq": { "Url": "http://seq:5341", "ApiKey": "" }, "AzureTable": { "ConnectionString": "" }, "Cleanup": { "RetentionDays": 90 } } }

De Azure Table connection string wordt ook automatisch opgehaald via de Aspire connection string AuditLogsTables.

AuditLog achtergrondverwerking

AuditLogCleanupScheduler is een IHostedService die via Hangfire periodiek oude audit logs opschoont. De cleanup wordt uitgevoerd door CleanupJobRunner die CleanupAuditLogsCommandHandler aanroept.

AuditLog endpoints

  • GET /api/audit-logs — Audit logs ophalen met filtering (GetAuditLogsEndpoint)

  • GET /api/audit-logs/download — Audit logs downloaden als bestand (DownloadAuditLogsEndpoint)

AuditLog interfaces

Naam

Type

Doel

IAuditLog

Interface

Audit events loggen

AuditLogService

Implementatie

Kiest provider via resolver, delegeert naar sink

IAuditLogSink

Interface

Backend-specifieke write operatie

SeqAuditLogSink

Implementatie

HTTP POST naar Seq via named HttpClient "SeqAudit"

AzureTableAuditLogSink

Implementatie

Schrijft naar Azure Table Storage

Email Plugin

Project: API/AutoMate.API.Plugins.Email

Doel: Transactionele email verzending via SendGrid.

Email configuratie

{ "SendGrid": { "ApiKey": "<sendgrid-api-key>", "FromAddress": "noreply@automate365.cloud", "FromName": "AutoMate" } }

EU data residency via SetDataResidency("eu") vereist een SendGrid Pro account. Dit is momenteel uitgecommentarieerd in de plugin — activeer alleen als Pro abonnement beschikbaar is.

Email interfaces

Naam

Type

Doel

IEmailSender

Interface

Email verzenden

SendGridEmailSender

Implementatie

Gebruikt ISendGridClient voor verzending

ISendGridClient

Interface

SendGrid API client (Singleton)

IEmailMessageRepository

Interface

Email message persistentie

IEmailEventRepository

Interface

Email delivery event persistentie

IEmailTemplateRepository

Interface

Email template beheer

Email endpoints

  • POST /api/email/webhook — SendGrid delivery status webhook (EmailStatusWebhookEndpoint)

Email achtergrondverwerking

EmailStatusJob is een Hangfire job die email delivery statussen verwerkt.

MsGraph Plugin

Project: API/AutoMate.API.Plugins.MsGraph

Doel: Microsoft Graph API integratie met multi-tenant certificaat authenticatie en batch support.

Authenticatie

De plugin gebruikt certificate-based authenticatie (client credentials) met certificaten uit Azure Key Vault. Configuratie via GraphCertificateAuthOptions (config section: GraphCertificate):

{ "GraphCertificate": { "ClientId": "<app-registration-client-id>", "CertificateName": "<keyvault-certificate-name>", "KeyVaultUri": "https://<keyvault-name>.vault.azure.net/", "Modules": { "Branding": { "ClientId": "<branding-client-id>", "CertificateName": "<branding-cert-name>", "KeyVaultUri": "https://<keyvault-name>.vault.azure.net/" } }, "TenantModuleRouting": { "<tenant-guid>": { "Branding": "Branding" } } } }

De plugin ondersteunt module-specifieke certificaat profielen (bijv. Branding, IAM). Via TenantModuleRouting kan per tenant en per module een specifiek profiel geconfigureerd worden. Zonder routing valt de plugin terug op het Default profiel, of op de legacy top-level properties.

Retry policy

De GraphService HttpClient ("GraphService") heeft een Polly retry policy met exponential backoff:

  • 3 retries bij transient HTTP errors

  • Ook bij 401 Unauthorized en 403 Forbidden

  • Wachttijd: 2^n seconden (2s, 4s, 8s)

var retryPolicy = HttpPolicyExtensions .HandleTransientHttpError() .OrResult(msg => msg.StatusCode == HttpStatusCode.Unauthorized || msg.StatusCode == HttpStatusCode.Forbidden) .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

MsGraph interfaces

Naam

Lifetime

Doel

IGraphService

Singleton

Core Graph client, token caching per tenant via MSAL

IEntraUserService

Singleton

User queries via Graph (ophalen, zoeken)

IEntraUserBatchService

Singleton

Bulk create/update/disable via Graph $batch API

IKeyVaultCertificateProvider

Singleton

Certificaten laden uit Azure Key Vault

IGraphService, IEntraUserService en IEntraUserBatchService zijn Singleton omdat MSAL's IConfidentialClientApplication thread-safe is en token caching per tenant automatisch beheert.

Batch operaties

IEntraUserBatchService biedt:

  • EntraCreateUserInput — Bulk aanmaken van Entra users

  • EntraUpdateUserInput — Bulk bijwerken van Entra users

  • EntraDisableUserInput — Bulk uitschakelen van Entra accounts

Resultaten worden teruggegeven via EntraBatchResults.

GraphModule

GraphModule is een enum die de beschikbare modules definieert (bijv. Branding, IAM). Dit wordt gebruikt bij GetProfileForTenantModule() om het juiste certificaat profiel op te zoeken voor een specifieke tenant-module combinatie.

Last modified: 24 March 2026