up
This commit is contained in:
172
src/Policy/StellaOps.Policy.Engine/Events/ProfileEventModels.cs
Normal file
172
src/Policy/StellaOps.Policy.Engine/Events/ProfileEventModels.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using StellaOps.Policy.RiskProfile.Lifecycle;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for profile lifecycle events.
|
||||
/// </summary>
|
||||
public abstract record ProfileEvent(
|
||||
[property: JsonPropertyName("event_id")] string EventId,
|
||||
[property: JsonPropertyName("event_type")] ProfileEventType EventType,
|
||||
[property: JsonPropertyName("profile_id")] string ProfileId,
|
||||
[property: JsonPropertyName("profile_version")] string ProfileVersion,
|
||||
[property: JsonPropertyName("timestamp")] DateTimeOffset Timestamp,
|
||||
[property: JsonPropertyName("actor")] string? Actor,
|
||||
[property: JsonPropertyName("correlation_id")] string? CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Type of profile event.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(JsonStringEnumConverter<ProfileEventType>))]
|
||||
public enum ProfileEventType
|
||||
{
|
||||
[JsonPropertyName("profile_created")]
|
||||
ProfileCreated,
|
||||
|
||||
[JsonPropertyName("profile_published")]
|
||||
ProfilePublished,
|
||||
|
||||
[JsonPropertyName("profile_activated")]
|
||||
ProfileActivated,
|
||||
|
||||
[JsonPropertyName("profile_deprecated")]
|
||||
ProfileDeprecated,
|
||||
|
||||
[JsonPropertyName("profile_archived")]
|
||||
ProfileArchived,
|
||||
|
||||
[JsonPropertyName("severity_threshold_changed")]
|
||||
SeverityThresholdChanged,
|
||||
|
||||
[JsonPropertyName("weight_changed")]
|
||||
WeightChanged,
|
||||
|
||||
[JsonPropertyName("override_added")]
|
||||
OverrideAdded,
|
||||
|
||||
[JsonPropertyName("override_removed")]
|
||||
OverrideRemoved,
|
||||
|
||||
[JsonPropertyName("scope_attached")]
|
||||
ScopeAttached,
|
||||
|
||||
[JsonPropertyName("scope_detached")]
|
||||
ScopeDetached
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when a profile is created.
|
||||
/// </summary>
|
||||
public sealed record ProfileCreatedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("content_hash")] string ContentHash,
|
||||
[property: JsonPropertyName("description")] string? Description)
|
||||
: ProfileEvent(EventId, ProfileEventType.ProfileCreated, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when a profile is published/activated.
|
||||
/// </summary>
|
||||
public sealed record ProfilePublishedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("content_hash")] string ContentHash,
|
||||
[property: JsonPropertyName("previous_active_version")] string? PreviousActiveVersion)
|
||||
: ProfileEvent(EventId, ProfileEventType.ProfilePublished, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when a profile is deprecated.
|
||||
/// </summary>
|
||||
public sealed record ProfileDeprecatedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("reason")] string? Reason,
|
||||
[property: JsonPropertyName("successor_version")] string? SuccessorVersion)
|
||||
: ProfileEvent(EventId, ProfileEventType.ProfileDeprecated, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when a profile is archived.
|
||||
/// </summary>
|
||||
public sealed record ProfileArchivedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId)
|
||||
: ProfileEvent(EventId, ProfileEventType.ProfileArchived, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when severity thresholds change.
|
||||
/// </summary>
|
||||
public sealed record SeverityThresholdChangedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("changes")] IReadOnlyList<ThresholdChange> Changes)
|
||||
: ProfileEvent(EventId, ProfileEventType.SeverityThresholdChanged, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Details of a threshold change.
|
||||
/// </summary>
|
||||
public sealed record ThresholdChange(
|
||||
[property: JsonPropertyName("threshold_name")] string ThresholdName,
|
||||
[property: JsonPropertyName("old_value")] double? OldValue,
|
||||
[property: JsonPropertyName("new_value")] double? NewValue);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when weights change.
|
||||
/// </summary>
|
||||
public sealed record WeightChangedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("signal_name")] string SignalName,
|
||||
[property: JsonPropertyName("old_weight")] double OldWeight,
|
||||
[property: JsonPropertyName("new_weight")] double NewWeight)
|
||||
: ProfileEvent(EventId, ProfileEventType.WeightChanged, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event emitted when a scope is attached.
|
||||
/// </summary>
|
||||
public sealed record ScopeAttachedEvent(
|
||||
string EventId,
|
||||
string ProfileId,
|
||||
string ProfileVersion,
|
||||
DateTimeOffset Timestamp,
|
||||
string? Actor,
|
||||
string? CorrelationId,
|
||||
[property: JsonPropertyName("scope_type")] string ScopeType,
|
||||
[property: JsonPropertyName("scope_id")] string ScopeId,
|
||||
[property: JsonPropertyName("attachment_id")] string AttachmentId)
|
||||
: ProfileEvent(EventId, ProfileEventType.ScopeAttached, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId);
|
||||
|
||||
/// <summary>
|
||||
/// Event subscription request.
|
||||
/// </summary>
|
||||
public sealed record EventSubscription(
|
||||
[property: JsonPropertyName("subscription_id")] string SubscriptionId,
|
||||
[property: JsonPropertyName("event_types")] IReadOnlyList<ProfileEventType> EventTypes,
|
||||
[property: JsonPropertyName("profile_filter")] string? ProfileFilter,
|
||||
[property: JsonPropertyName("webhook_url")] string? WebhookUrl,
|
||||
[property: JsonPropertyName("created_at")] DateTimeOffset CreatedAt,
|
||||
[property: JsonPropertyName("created_by")] string? CreatedBy);
|
||||
Reference in New Issue
Block a user