|
| 1 | +function Get-ProtonAuthenticator { |
| 2 | + <# |
| 3 | + #> |
| 4 | + [OutputType([System.Management.Automation.PSObject])] |
| 5 | + [CmdletBinding(SupportsShouldProcess = $false)] |
| 6 | + param ( |
| 7 | + [Parameter(Mandatory = $false, Position = 0)] |
| 8 | + [ValidateNotNull()] |
| 9 | + [System.Management.Automation.PSObject] |
| 10 | + $res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1]) |
| 11 | + ) |
| 12 | + |
| 13 | + # Read the update source |
| 14 | + $params = @{ |
| 15 | + Uri = $res.Get.Update.Uri |
| 16 | + } |
| 17 | + $Updates = Invoke-EvergreenRestMethod @params |
| 18 | + |
| 19 | + # Convert the update JSON string |
| 20 | + if ($Updates -is [System.String]) { |
| 21 | + try { |
| 22 | + $Updates = $Updates | ConvertFrom-Json -ErrorAction "Continue" |
| 23 | + } |
| 24 | + catch { |
| 25 | + # Update feed may include duplicate keys in the JSON |
| 26 | + $Updates = $Updates -creplace $res.Get.Update.ReplaceString, "" | ConvertFrom-Json -ErrorAction "Stop" |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + # Simplify access to releases |
| 31 | + $Releases = $Updates.Releases |
| 32 | + |
| 33 | + # Process each category |
| 34 | + foreach ($Category in ($Releases.CategoryName | Select-Object -Unique)) { |
| 35 | + Write-Verbose -Message "$($MyInvocation.MyCommand): Processing category: $Category" |
| 36 | + |
| 37 | + # Sort for the latest version |
| 38 | + $LatestVersion = $Releases | Where-Object { $_.CategoryName -eq $Category } | ` |
| 39 | + Sort-Object -Property @{ Expression = { [System.Version]$_.Version }; Descending = $true } -ErrorAction "SilentlyContinue" | ` |
| 40 | + Select-Object -First 1 |
| 41 | + Write-Verbose -Message "$($MyInvocation.MyCommand): Latest version in category '$Category' is $($LatestVersion.Version)" |
| 42 | + |
| 43 | + # Construct the output; Return the custom object to the pipeline |
| 44 | + $PSObject = [PSCustomObject] @{ |
| 45 | + Version = $LatestVersion.Version |
| 46 | + Date = ConvertTo-DateTime -DateTime $LatestVersion.ReleaseDate -Pattern $res.Get.Update.DatePattern |
| 47 | + Release = $LatestVersion.CategoryName |
| 48 | + Sha512 = $LatestVersion.File.Sha512CheckSum |
| 49 | + Type = Get-FileType -File $LatestVersion.File.Url |
| 50 | + URI = $LatestVersion.File.Url |
| 51 | + } |
| 52 | + Write-Output -InputObject $PSObject |
| 53 | + } |
| 54 | +} |
0 commit comments