Skip to content

Commit 5abece4

Browse files
committed
Add -AsBase64 to Get-HaloAttachment. 1.17.0.
1 parent b709978 commit 5abece4

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

.github/workflows/githubreleaser.yml

Whitespace-only changes.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2023-12-19 - Version 1.17.0
4+
5+
* Add `-AsBase64` parameter to `Get-HaloAttachment` to allow fetching single attachments as base64 encoded strings.
6+
37
## 2023-11-17 - Version 1.16.0
48

59
* Refactor variables in `Invoke-HaloRequest` to avoid scope confusion.

HaloAPI.build.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ if ($UpdateManifest) {
214214
Import-Module -Name PlatyPS
215215

216216
# Find Latest Version in Change log.
217-
$CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md"
217+
$CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md" -Raw
218218
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
219-
[regex]$Regex = '\d\.\d\.\d'
219+
[regex]$ReleaseRegex = '#{2}.*\d*\.\d*\.\d*$/m'
220+
$Releases = ($ReleaseRegex.Matches($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text))
221+
[regex]$VersionRegex = '\d*\.\d*\.\d*'
220222
$Versions = $Regex.Matches($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) | ForEach-Object { $_.Value }
221223
$ChangeLogVersion = ($Versions | Measure-Object -Maximum).Maximum
222224

@@ -236,7 +238,7 @@ if ($UpdateManifest) {
236238
# Update Manifest file with Release Notes
237239
$CHANGELOG = Get-Content -Path "$($PSScriptRoot)\CHANGELOG.md"
238240
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
239-
$ReleaseNotes = ((($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) -Match '\d\.\d\.\d') -Split ' - ')[1]
241+
$ReleaseNotes = ((($MarkdownObject.ParseString($CHANGELOG).Children.Spans.Text) -Match '#{2}.*\d*\.\d*\.\d') -Split ' - ')[1]
240242

241243
# Update Module with new version
242244
Update-ModuleManifest -ModuleVersion $ChangeLogVersion -Path "$($PSScriptRoot)\$ModuleName.psd1" -ReleaseNotes $ReleaseNotes

HaloAPI.code-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"powershell.codeFormatting.whitespaceBetweenParameters": false,
2828
"powershell.codeFormatting.whitespaceInsideBrace": true,
2929
"editor.codeActionsOnSave": {
30-
"source.fixAll.markdownlint": true
30+
"source.fixAll.markdownlint": "explicit"
3131
}
3232
}
3333
}

HaloAPI.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '.\HaloAPI.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.16.0'
15+
ModuleVersion = '1.17.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -268,7 +268,7 @@
268268
IconUri = 'https://3c3br937rz386088k2z3qqdi-wpengine.netdna-ssl.com/wp-content/uploads/2020/04/HaloIcon-300x300.png'
269269

270270
# ReleaseNotes of this module
271-
ReleaseNotes = 'Refactor `Invoke-HaloRequest` to avoid reusing variable names and keep the scope clearer. Fixes breakage with PowerShell 7.4.0.'
271+
ReleaseNotes = 'Add -AsBase64 to Get-HaloAttachment to return the attachment as a base64 encoded string.'
272272

273273
# Prerelease string of this module
274274
# Prerelease = 'Beta1'

Public/Get/Get-HaloAttachment.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ function Get-HaloAttachment {
4040
[String]$OutFile,
4141
# Allow Writing Directly to File, using the specified path and the original file name eg c:\temp\
4242
[Parameter( ParameterSetName = 'SinglePath', Mandatory = $True )]
43-
[String]$OutPath
43+
[String]$OutPath,
44+
# Return the attachment as a base64 encoded string
45+
[Parameter( ParameterSetName = 'Single' )]
46+
[Switch]$AsBase64
4447
)
4548
Invoke-HaloPreFlightCheck
4649
$CommandName = $MyInvocation.MyCommand.Name
@@ -88,11 +91,14 @@ function Get-HaloAttachment {
8891
Write-Verbose "Attempting to output to file $OutFile"
8992
$Path = $OutFile
9093
}
91-
9294
Write-Verbose "Writing File $Path"
9395
$File = [System.IO.FileStream]::new($Path, [System.IO.FileMode]::Create)
9496
$File.write($AttachmentResults.Content, 0, $AttachmentResults.RawContentLength)
9597
$File.close()
98+
} elseif ($AsBase64) {
99+
Write-Verbose 'Returning base64 encoded string'
100+
$Base64String = [System.Convert]::ToBase64String($AttachmentResults.Content)
101+
Return $Base64String
96102
} else {
97103
return $AttachmentResults.Content
98104
}

Public/Invoke-HaloRequest.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,18 @@ function Invoke-HaloRequest {
5252
try {
5353
Write-Verbose "Making a $($WebRequestParams.Method) request to $($WebRequestParams.Uri)"
5454
$Response = Invoke-WebRequest @WebRequestParams -Headers $RequestHeaders -ContentType 'application/json; charset=utf-8'
55-
Write-Debug "Response headers: $($Response.Headers | Out-String)"
56-
Write-Debug "Raw Response: $($Response | Out-String)"
57-
Write-Debug "Response Members: $($Response | Get-Member | Out-String)"
58-
$Success = $True
59-
if ($RawResult) {
60-
$Results = $Response
55+
if ($Response) {
56+
Write-Debug "Response headers: $($Response.Headers | Out-String)"
57+
Write-Debug "Raw Response: $($Response | Out-String)"
58+
Write-Debug "Response Members: $($Response | Get-Member | Out-String)"
59+
$Success = $True
60+
if ($RawResult) {
61+
$Results = $Response
62+
} else {
63+
$Results = ($Response.Content | ConvertFrom-Json -Depth 100)
64+
}
6165
} else {
62-
$Results = ($Response.Content | ConvertFrom-Json -Depth 100)
66+
Write-Debug 'Response was null.'
6367
}
6468
} catch [Microsoft.PowerShell.Commands.HttpResponseException] {
6569
$Success = $False

0 commit comments

Comments
 (0)