From 5abece49b68cae76457eba1dbc1a2a19ddc88d43 Mon Sep 17 00:00:00 2001 From: Mikey O'Toole Date: Tue, 19 Dec 2023 21:50:11 +0000 Subject: [PATCH] Add -AsBase64 to Get-HaloAttachment. 1.17.0. --- .github/workflows/githubreleaser.yml | 0 CHANGELOG.md | 4 ++++ HaloAPI.build.ps1 | 8 +++++--- HaloAPI.code-workspace | 2 +- HaloAPI.psd1 | 4 ++-- Public/Get/Get-HaloAttachment.ps1 | 10 ++++++++-- Public/Invoke-HaloRequest.ps1 | 18 +++++++++++------- 7 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/githubreleaser.yml diff --git a/.github/workflows/githubreleaser.yml b/.github/workflows/githubreleaser.yml new file mode 100644 index 0000000..e69de29 diff --git a/CHANGELOG.md b/CHANGELOG.md index a154d85..d21709c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2023-12-19 - Version 1.17.0 + +* Add `-AsBase64` parameter to `Get-HaloAttachment` to allow fetching single attachments as base64 encoded strings. + ## 2023-11-17 - Version 1.16.0 * Refactor variables in `Invoke-HaloRequest` to avoid scope confusion. diff --git a/HaloAPI.build.ps1 b/HaloAPI.build.ps1 index 50a26e9..9b7582d 100644 --- a/HaloAPI.build.ps1 +++ b/HaloAPI.build.ps1 @@ -214,9 +214,11 @@ if ($UpdateManifest) { Import-Module -Name PlatyPS # Find Latest Version in Change log. - $CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md" + $CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md" -Raw $MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new() - [regex]$Regex = '\d\.\d\.\d' + [regex]$ReleaseRegex = '#{2}.*\d*\.\d*\.\d*$/m' + $Releases = ($ReleaseRegex.Matches($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text)) + [regex]$VersionRegex = '\d*\.\d*\.\d*' $Versions = $Regex.Matches($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) | ForEach-Object { $_.Value } $ChangeLogVersion = ($Versions | Measure-Object -Maximum).Maximum @@ -236,7 +238,7 @@ if ($UpdateManifest) { # Update Manifest file with Release Notes $CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md" $MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new() - $ReleaseNotes = ((($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) -Match '\d\.\d\.\d') -Split ' - ')[1] + $ReleaseNotes = ((($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) -Match '#{2}.*\d*\.\d*\.\d') -Split ' - ')[1] # Update Module with new version Update-ModuleManifest -ModuleVersion $ChangeLogVersion -Path "$($PSScriptRoot)\$ModuleName.psd1" -ReleaseNotes $ReleaseNotes diff --git a/HaloAPI.code-workspace b/HaloAPI.code-workspace index 903ae22..80b0757 100644 --- a/HaloAPI.code-workspace +++ b/HaloAPI.code-workspace @@ -27,7 +27,7 @@ "powershell.codeFormatting.whitespaceBetweenParameters": false, "powershell.codeFormatting.whitespaceInsideBrace": true, "editor.codeActionsOnSave": { - "source.fixAll.markdownlint": true + "source.fixAll.markdownlint": "explicit" } } } \ No newline at end of file diff --git a/HaloAPI.psd1 b/HaloAPI.psd1 index ec43a78..36bac45 100644 --- a/HaloAPI.psd1 +++ b/HaloAPI.psd1 @@ -12,7 +12,7 @@ RootModule = '.\HaloAPI.psm1' # Version number of this module. - ModuleVersion = '1.16.0' + ModuleVersion = '1.17.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -268,7 +268,7 @@ IconUri = 'https://3c3br937rz386088k2z3qqdi-wpengine.netdna-ssl.com/wp-content/uploads/2020/04/HaloIcon-300x300.png' # ReleaseNotes of this module - ReleaseNotes = 'Refactor `Invoke-HaloRequest` to avoid reusing variable names and keep the scope clearer. Fixes breakage with PowerShell 7.4.0.' + ReleaseNotes = 'Add -AsBase64 to Get-HaloAttachment to return the attachment as a base64 encoded string.' # Prerelease string of this module # Prerelease = 'Beta1' diff --git a/Public/Get/Get-HaloAttachment.ps1 b/Public/Get/Get-HaloAttachment.ps1 index 2f69e7b..68f4b25 100644 --- a/Public/Get/Get-HaloAttachment.ps1 +++ b/Public/Get/Get-HaloAttachment.ps1 @@ -40,7 +40,10 @@ function Get-HaloAttachment { [String]$OutFile, # Allow Writing Directly to File, using the specified path and the original file name eg c:\temp\ [Parameter( ParameterSetName = 'SinglePath', Mandatory = $True )] - [String]$OutPath + [String]$OutPath, + # Return the attachment as a base64 encoded string + [Parameter( ParameterSetName = 'Single' )] + [Switch]$AsBase64 ) Invoke-HaloPreFlightCheck $CommandName = $MyInvocation.MyCommand.Name @@ -88,11 +91,14 @@ function Get-HaloAttachment { Write-Verbose "Attempting to output to file $OutFile" $Path = $OutFile } - Write-Verbose "Writing File $Path" $File = [System.IO.FileStream]::new($Path, [System.IO.FileMode]::Create) $File.write($AttachmentResults.Content, 0, $AttachmentResults.RawContentLength) $File.close() + } elseif ($AsBase64) { + Write-Verbose 'Returning base64 encoded string' + $Base64String = [System.Convert]::ToBase64String($AttachmentResults.Content) + Return $Base64String } else { return $AttachmentResults.Content } diff --git a/Public/Invoke-HaloRequest.ps1 b/Public/Invoke-HaloRequest.ps1 index d3e9927..f016589 100644 --- a/Public/Invoke-HaloRequest.ps1 +++ b/Public/Invoke-HaloRequest.ps1 @@ -52,14 +52,18 @@ function Invoke-HaloRequest { try { Write-Verbose "Making a $($WebRequestParams.Method) request to $($WebRequestParams.Uri)" $Response = Invoke-WebRequest @WebRequestParams -Headers $RequestHeaders -ContentType 'application/json; charset=utf-8' - Write-Debug "Response headers: $($Response.Headers | Out-String)" - Write-Debug "Raw Response: $($Response | Out-String)" - Write-Debug "Response Members: $($Response | Get-Member | Out-String)" - $Success = $True - if ($RawResult) { - $Results = $Response + if ($Response) { + Write-Debug "Response headers: $($Response.Headers | Out-String)" + Write-Debug "Raw Response: $($Response | Out-String)" + Write-Debug "Response Members: $($Response | Get-Member | Out-String)" + $Success = $True + if ($RawResult) { + $Results = $Response + } else { + $Results = ($Response.Content | ConvertFrom-Json -Depth 100) + } } else { - $Results = ($Response.Content | ConvertFrom-Json -Depth 100) + Write-Debug 'Response was null.' } } catch [Microsoft.PowerShell.Commands.HttpResponseException] { $Success = $False