Framework/Models/AzSdkSettings.ps1
# # AzSdkSettings.ps1 # Set-StrictMode -Version Latest class AzSdkSettings { [string] $OMSWorkspaceId; [string] $OMSSharedKey; [string] $OMSType; [string] $OMSSource; [string] $EventHubNamespace; [string] $EventHubName; [string] $EventHubSendKeyName; [string] $EventHubSendKey; [string] $EventHubType; [string] $EventHubSource; [string] $WebhookUrl; [string] $WebhookAuthZHeaderName; [string] $WebhookAuthZHeaderValue; [string] $WebhookType; [string] $WebhookSource; [bool] $EnableAADAuthForOnlinePolicyStore; [bool] $UseOnlinePolicyStore; [string] $OnlinePolicyStoreUrl; [string] $UsageTelemetryLevel; [string] $LocalControlTelemetryKey; [bool] $LocalEnableControlTelemetry; hidden static [AzSdkSettings] $Instance = $null; hidden static [string] $FileName = "AzSdkSettings.json"; hidden AzSdkSettings() { $this.OMSWorkspaceId = "" $this.OMSSharedKey = "" $this.OMSType = "AzSDK" $this.OMSSource = "SDL" $this.EventHubNamespace = "" $this.EventHubName = "" $this.EventHubSendKeyName = "" $this.EventHubSendKey = "" $this.EventHubType = "AzSDK" $this.EventHubSource = "SDL" $this.WebhookUrl = "" $this.WebhookAuthZHeaderName = "" $this.WebhookAuthZHeaderValue = "" $this.WebhookType = "AzSDK" $this.WebhookSource = "SDL" } static [AzSdkSettings] GetInstance() { if (-not [AzSdkSettings]::Instance) { [AzSdkSettings]::Instance = [AzSdkSettings]::new(); [AzSdkSettings]::Instance.LoadAzSdkSettings(); } return [AzSdkSettings]::Instance } hidden [void] LoadAzSdkSettings() { #Filename will be static. #For AzSDK Settings, never use online policy store. Its assumed that file will be available offline $localSettings = [ConfigurationHelper]::LoadOfflineConfigFile([AzSdkSettings]::FileName) #Validate settings content is not null if ($localSettings) { try { # Try parsing the object [AzSdkSettings]::Instance = [AzSdkSettings] $localSettings } catch { # Any error occurred while converting local json file indicates change in schema #Load v2 AzSDKSettings from modules folder [AzSdkSettings]::Instance = [ConfigurationHelper]::LoadModuleJsonFile([AzSdkSettings]::FileName) $migratedPropNames = @(); [AzSdkSettings]::Instance | Get-Member -MemberType Properties | ForEach-Object { $propertyName = $_.Name; if([Helpers]::CheckMember($localSettings, $propertyName)) { [AzSdkSettings]::Instance.$propertyName = $localSettings.$propertyName; $migratedPropNames += $propertyName; } }; if($migratedPropNames.Count -ne 0) { [AzSdkSettings]::Instance.Update() [EventBase]::PublishGenericCustomMessage("Local AzSDK settings file was not compatible with the latest version. `r`nMigrated the existing values for properties: [$([string]::Join(", ", $migratedPropNames))] ", [MessageType]::Warning); } } } } [void] Update() { if (-not (Test-Path $([Constants]::AzSdkAppFolderPath))) { mkdir -Path $([Constants]::AzSdkAppFolderPath) -ErrorAction Stop | Out-Null } #persisting back to file [AzSdkSettings]::Instance | ConvertTo-Json | Out-File -Force -FilePath ([Constants]::AzSdkAppFolderPath + "\" + [AzSdkSettings]::FileName) } #TODO: Replace OMSSource with framework level source hidden [string] GetScanSource() { return $this.OMSSource } } |