Framework/Models/AzSdkConfig.ps1
Set-StrictMode -Version Latest class AzSdkConfig { [string] $MaintenanceMessage [Environment] $Environment [string] $AzSDKRGName [string] $AzSDKRepoURL [string] $AzSDKServerVersion [string[]] $SubscriptionMandatoryTags = @() [string] $ERvNetResourceGroupNames [string] $UpdateCompatibleCCVersion [string] $AzSDKApiBaseURL; [bool] $PublishVulnDataToApi; [string] $ControlTelemetryKey; [bool] $EnableControlTelemetry; [string] $PolicyMessage; [string] $InstallationCommand; [string] $PublicPSGalleryUrl; hidden static [AzSdkConfig] $Instance = $null; static [AzSdkConfig] GetInstance([bool] $useOnlinePolicyStore, [string] $onlineStoreUri, [bool] $enableAADAuthForOnlinePolicyStore) { if ( $null -eq [AzSdkConfig]::Instance) { [AzSdkConfig]::Instance = [AzSdkConfig]::LoadRootConfiguration($useOnlinePolicyStore,$onlineStoreUri,$enableAADAuthForOnlinePolicyStore) } return [AzSdkConfig]::Instance } hidden static [AzSdkConfig] LoadRootConfiguration([bool] $useOnlinePolicyStore, [string] $onlineStoreUri, [bool] $enableAADAuthForOnlinePolicyStore) { #Filename will be static. return [AzSdkConfig] ([ConfigurationHelper]::LoadServerConfigFile("AzSdk.json", $useOnlinePolicyStore, $onlineStoreUri, $enableAADAuthForOnlinePolicyStore)); } hidden [string] GetLatestAzSDKVersion([string] $moduleName) { if([string]::IsNullOrWhiteSpace($this.AzSDKServerVersion)) { $this.AzSDKServerVersion = "0.0.0.0"; try { $repoUrl = $this.AzSDKRepoURL; #Searching for the module in the repo $Url = "$repoUrl/api/v2/Search()?`$filter=IsLatestVersion&searchTerm=%27$moduleName%27&includePrerelease=false&`$skip=0&`$top=40" [System.Uri] $validatedUri = $null; if([System.Uri]::TryCreate($Url, [System.UriKind]::Absolute, [ref] $validatedUri)) { $SearchResult = Invoke-RestMethod -Method Get -Uri $validatedUri -UseBasicParsing if($SearchResult.Length -and $SearchResult.Length -gt 1) { #filter latest module $SearchResult = $SearchResult | Where-Object -FilterScript { return $_.title.'#text' -eq $moduleName } $moduleName = $SearchResult.title.'#text' # get correct casing for the module name $PackageDetails = Invoke-RestMethod -Method Get -UseBasicParsing -Uri $SearchResult.id $this.AzSDKServerVersion = $PackageDetails.entry.properties.version } } } catch { $this.AzSDKServerVersion = "0.0.0.0"; } } return $this.AzSDKServerVersion; } } |