Framework/Models/SVT/SVTEvent.ps1
Set-StrictMode -Version Latest class SVTEvent { #First level event #Command level event static [string] $CommandStarted = "AzSdk.SVT.Command.Started"; #Initialize listeners #Function execution started static [string] $CommandCompleted = "AzSdk.SVT.Command.Completed"; #Cleanup listeners #Function execution completed static [string] $CommandError = "AzSdk.SVT.Command.Error"; #Second level event for every resource static [string] $EvaluationStarted = "AzSdk.SVT.Evaluation.Started"; #Individual Resource execution started static [string] $EvaluationCompleted = "AzSdk.SVT.Evaluation.Completed"; #Individual Resource execution completed static [string] $EvaluationError = "AzSdk.SVT.Evaluation.Error"; #Control level events static [string] $ControlStarted = "AzSdk.SVT.Control.Started"; #No DataObject static [string] $ControlCompleted = "AzSdk.SVT.Control.Completed"; #All DataObjects static [string] $ControlError = "AzSdk.SVT.Control.Error"; static [string] $ControlDisabled = "AzSdk.SVT.Control.Disabled"; #No DataObject #static [string] $ControlProcessing = "AzSdk.SVT.Control.Processing"; #Individual DataObject } class ResourceContext { [string] $ResourceId ="" [string] $ResourceGroupName = "" [string] $ResourceName = "" [string] $ResourceType = "" [hashtable] $ResourceMetadata = @{} [string] $ResourceTypeName = "" } class ControlResult { [string] $ChildResourceName = ""; [VerificationResult] $VerificationResult = [VerificationResult]::Manual; [VerificationResult] $ActualVerificationResult = [VerificationResult]::Manual; [AttestationStatus] $AttestationStatus = [AttestationStatus]::None; [StateManagement] $StateManagement = [StateManagement]::new(); hidden [PSObject] $FixControlParameters = $null; hidden [bool] $EnableFixControl = $false; [MessageData[]] $Messages = @(); [void] AddMessage([MessageData] $messageData) { if((-not [string]::IsNullOrEmpty($messageData.Message)) -or ($null -ne $messageData.DataObject)) { $this.Messages += $messageData; } } [void] AddMessage([VerificationResult] $result, [MessageData] $messageData) { $this.VerificationResult = $result; $this.AddMessage($messageData); } [void] AddMessage([VerificationResult] $result, [string] $message, [PSObject] $dataObject) { $this.VerificationResult = $result; $this.AddMessage([MessageData]::new($message, $dataObject)); } [void] AddMessage([string] $message, [PSObject] $dataObject) { $this.AddMessage([MessageData]::new($message, $dataObject)); } [void] AddMessage([PSObject] $dataObject) { $this.AddMessage([MessageData]::new($dataObject)); } [void] AddMessage([string] $message) { $this.AddMessage([MessageData]::new($message)); } [void] AddError([System.Management.Automation.ErrorRecord] $exception) { $this.AddMessage([MessageData]::new($exception, [MessageType]::Error)); } [void] SetStateData([string] $message, [PSObject] $dataObject) { $this.StateManagement.CurrentStateData = [StateData]::new($message, $dataObject); } } class StateManagement { [StateData] $AttestedStateData; [StateData] $CurrentStateData; } class Metadata { [string] $Reference = "" } class StateData: MessageDataBase { [string] $Justification = ""; [string] $AttestedBy ="" [DateTime] $AttestedDate StateData() { } StateData([string] $message, [PSObject] $dataObject) : Base($message, $dataObject) { } } class SVTEventContext: AzSdkRootEventArgument { [string] $FeatureName = "" [Metadata] $Metadata [ResourceContext] $ResourceContext; [ControlItem] $ControlItem; [ControlResult[]] $ControlResults = @(); [bool] IsResource() { if($this.ResourceContext) { return $true; } else { return $false; } } [string] GetUniqueId() { $uniqueId = ""; if($this.IsResource()) { $uniqueId = $this.ResourceContext.ResourceId; } else { $uniqueId = $this.SubscriptionContext.Scope; } # Unique Id validation if([string]::IsNullOrWhiteSpace($uniqueId)) { throw "Error while evaluating Unique Id. The parameter 'ResourceContext.ResourceId' OR 'SubscriptionContext.Scope' is null or empty." } return $uniqueId; } } |