Skip to content

Commit adb0628

Browse files
authored
Release v2.5
Merge pull request #167 from lipkau/release/v2.5
2 parents e894bbb + 7bfbf51 commit adb0628

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+752
-350
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
.
1313

14+
## [2.5] 2019-03-27
15+
16+
### Added
17+
18+
- Added support for authenticating with X509Certificate (#164, [@ritzcrackr])
19+
20+
### Fixed
21+
22+
- Conversion of pageID attribute of Attachments to `[Int]` (#166, [@lipkau])
23+
- Fixed generation of headers in tables when using `ConvertTo-ConfluenceTable` (#163, [@lipkau])
24+
1425
## [2.4] 2018-12-12
1526

1627
### Added
@@ -189,4 +200,5 @@ No changelog available for version `1.0` of ConfluencePS. `1.0` was created in l
189200
[@lipkau]: https://github.com/lipkau
190201
[@lukhase]: https://github.com/lukhase
191202
[@padgers]: https://github.com/padgers
203+
[@ritzcrackr]: https://github.com/ritzcrackr
192204
[@ThePSAdmin]: https://github.com/ThePSAdmin

ConfluencePS/ConfluencePS.Types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class Attachment {
8686
public String Title { get; set; }
8787
public String Filename { get; set; }
8888
public String MediaType { get; set; }
89-
public Int32 FileSize { get; set; }
89+
public UInt64 FileSize { get; set; }
9090
public String Comment { get; set; }
9191
public String SpaceKey { get; set; }
9292
public Int32 PageID { get; set; }

ConfluencePS/ConfluencePS.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'ConfluencePS.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.4'
15+
ModuleVersion = '2.5'
1616

1717
# ID used to uniquely identify this module
1818
GUID = '20d32089-48ef-464d-ba73-6ada240e26b3'

ConfluencePS/Private/ConvertTo-Attachment.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ function ConvertTo-Attachment {
2020
$PageId = $_.container.id
2121
}
2222
else {
23-
$PageID = $_._expandable.container -replace '^.*\/content\/', ''
24-
$PageID = [convert]::ToInt32($PageID, 10)
23+
[UInt32]$PageID = $_._expandable.container -replace '^.*\/content\/', ''
2524
}
2625

2726
[ConfluencePS.Attachment](ConvertTo-Hashtable -InputObject ($object | Select-Object `
2827
@{Name = "id"; Expression = {
29-
$ID = $_.id -replace 'att', ''
30-
[convert]::ToInt32($ID, 10)
28+
[UInt32]($_.id -replace 'att', '')
3129
}
3230
},
3331
status,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Copy-CommonParameter {
2+
<#
3+
.SYNOPSIS
4+
This is a helper function to assist in creating a hashtable for splatting parameters to inner function calls.
5+
6+
.DESCRIPTION
7+
This command copies all of the keys of a hashtable to a new hashtable if the key name matches the DefaultParameter
8+
or the AdditionalParameter values. This function is designed to help select only function parameters that have been
9+
set, so they can be passed to inner functions if and only if they have been set.
10+
11+
.EXAMPLE
12+
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters
13+
14+
Returns a hashtable that contains all of the bound default parameters.
15+
16+
.EXAMPLE
17+
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri"
18+
19+
Returns a hashtable that contains all of the bound default parameters and the "ApiUri" parameter.
20+
#>
21+
[CmdletBinding( SupportsShouldProcess = $false )]
22+
[OutputType(
23+
[hashtable]
24+
)]
25+
param
26+
(
27+
[Parameter(Mandatory = $true)]
28+
[hashtable]$InputObject,
29+
30+
[Parameter(Mandatory = $false)]
31+
[string[]]$AdditionalParameter,
32+
33+
[Parameter(Mandatory = $false)]
34+
[string[]]$DefaultParameter = @("Credential", "Certificate")
35+
)
36+
37+
[hashtable]$ht = @{}
38+
foreach ($key in $InputObject.Keys) {
39+
if ($key -in ($DefaultParameter + $AdditionalParameter)) {
40+
$ht[$key] = $InputObject[$key]
41+
}
42+
}
43+
44+
return $ht
45+
}

ConfluencePS/Public/Add-Attachment.ps1

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ function Add-Attachment {
66
[OutputType([ConfluencePS.Attachment])]
77
param(
88
[Parameter( Mandatory = $true )]
9-
[URi]$apiURi,
9+
[uri]$ApiUri,
1010

11-
[Parameter( Mandatory = $true )]
11+
[Parameter( Mandatory = $false )]
1212
[PSCredential]$Credential,
1313

14+
[Parameter( Mandatory = $false )]
15+
[ValidateNotNull()]
16+
[System.Security.Cryptography.X509Certificates.X509Certificate]
17+
$Certificate,
18+
1419
[Parameter(
1520
Position = 0,
1621
Mandatory = $true,
@@ -46,27 +51,23 @@ function Add-Attachment {
4651

4752
begin {
4853
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
49-
50-
$resourceApi = "$apiURi/content/{0}/child/attachment"
5154
}
5255

5356
process {
5457
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
5558
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"
5659

57-
$parameter = @{
58-
URI = $resourceApi -f $PageID
59-
Method = "POST"
60-
Credential = $Credential
61-
OutputType = [ConfluencePS.Attachment]
62-
Verbose = $false
63-
}
60+
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
61+
$iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $PageID
62+
$iwParameters['Method'] = 'Post'
63+
$iwParameters['OutputType'] = [ConfluencePS.Attachment]
64+
6465
foreach ($file in $FilePath) {
65-
$parameter["InFile"] = $file
66+
$iwParameters["InFile"] = $file
6667

6768
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking Add Attachment Method with `$parameter"
6869
if ($PSCmdlet.ShouldProcess($PageID, "Adding attachment(s) '$($file)'.")) {
69-
Invoke-Method @parameter
70+
Invoke-Method @iwParameters
7071
}
7172
}
7273
}

ConfluencePS/Public/Add-Label.ps1

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ function Add-Label {
66
[OutputType([ConfluencePS.ContentLabelSet])]
77
param (
88
[Parameter( Mandatory = $true )]
9-
[URi]$apiURi,
9+
[uri]$ApiUri,
1010

11-
[Parameter( Mandatory = $true )]
11+
[Parameter( Mandatory = $false )]
1212
[PSCredential]$Credential,
1313

14+
[Parameter( Mandatory = $false )]
15+
[ValidateNotNull()]
16+
[System.Security.Cryptography.X509Certificates.X509Certificate]
17+
$Certificate,
18+
1419
[Parameter(
1520
Position = 0,
1621
ValueFromPipeline = $true,
@@ -32,7 +37,7 @@ function Add-Label {
3237
BEGIN {
3338
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
3439

35-
$resourceApi = "$apiURi/content/{0}/label"
40+
$resourceApi = "$ApiUri/content/{0}/label"
3641
}
3742

3843
PROCESS {
@@ -71,13 +76,9 @@ function Add-Label {
7176
Throw $exception
7277
}
7378

74-
$iwParameters = @{
75-
Uri = ""
76-
Method = 'Post'
77-
Body = ""
78-
OutputType = [ConfluencePS.Label]
79-
Credential = $Credential
80-
}
79+
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
80+
$iwParameters['Method'] = 'Post'
81+
$iwParameters['OutputType'] = [ConfluencePS.Label]
8182

8283
# Extract name if an Object is provided
8384
if (($Label -is [ConfluencePS.Label]) -or $Label -is [ConfluencePS.Label[]]) {
@@ -92,14 +93,15 @@ function Add-Label {
9293
$InputObject = $_.Page
9394
}
9495
else {
95-
$InputObject = Get-Page -PageID $_page -ApiURi $apiURi -Credential $Credential
96+
$authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri"
97+
$InputObject = Get-Page -PageID $_page @authAndApiUri
9698
}
9799

98100
$iwParameters["Uri"] = $resourceApi -f $_page
99101
$iwParameters["Body"] = ($Label | Foreach-Object {@{prefix = 'global'; name = $_}}) | ConvertTo-Json
100102

101103
Write-Debug "[$($MyInvocation.MyCommand.Name)] Content to be sent: $($iwParameters["Body"] | Out-String)"
102-
If ($PSCmdlet.ShouldProcess("Label $Label, PageID $_page")) {
104+
if ($PSCmdlet.ShouldProcess("Label $Label, PageID $_page")) {
103105
$output = [ConfluencePS.ContentLabelSet]@{ Page = $InputObject }
104106
$output.Labels += (Invoke-Method @iwParameters)
105107
$output

ConfluencePS/Public/ConvertTo-StorageFormat.ps1

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ function ConvertTo-StorageFormat {
33
[OutputType([String])]
44
param (
55
[Parameter( Mandatory = $true )]
6-
[URi]$apiURi,
6+
[uri]$ApiUri,
77

8-
[Parameter( Mandatory = $true )]
8+
[Parameter( Mandatory = $false )]
99
[PSCredential]$Credential,
1010

11+
[Parameter( Mandatory = $false )]
12+
[ValidateNotNull()]
13+
[System.Security.Cryptography.X509Certificates.X509Certificate]
14+
$Certificate,
15+
1116
[Parameter(
1217
Position = 0,
1318
Mandatory = $true,
@@ -24,16 +29,15 @@ function ConvertTo-StorageFormat {
2429
Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
2530
Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"
2631

32+
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
33+
$iwParameters['Uri'] = "$ApiUri/contentbody/convert/storage"
34+
$iwParameters['Method'] = 'Post'
35+
2736
foreach ($_content in $Content) {
28-
$iwParameters = @{
29-
Uri = "$apiURi/contentbody/convert/storage"
30-
Method = 'Post'
31-
Body = @{
32-
value = "$_content"
33-
representation = 'wiki'
34-
} | ConvertTo-Json
35-
Credential = $Credential
36-
}
37+
$iwParameters['Body'] = @{
38+
value = "$_content"
39+
representation = 'wiki'
40+
} | ConvertTo-Json
3741

3842
Write-Debug "[$($MyInvocation.MyCommand.Name)] Content to be sent: $($_content | Out-String)"
3943
(Invoke-Method @iwParameters).value

ConfluencePS/Public/ConvertTo-Table.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ function ConvertTo-Table {
2727

2828
# This ForEach needed if the content wasn't piped in
2929
$Content | ForEach-Object {
30-
If ($Vertical) {
31-
If ($HeaderGenerated) {$pipe = '|'}
32-
Else {$pipe = '||'}
30+
if ($Vertical) {
31+
if ($HeaderGenerated) {$pipe = '|'}
32+
else {$pipe = '||'}
3333

3434
# Put an empty row between multiple tables (objects)
35-
If ($Spacer) {
35+
if ($Spacer) {
3636
$null = $sb.AppendLine('')
3737
}
3838

@@ -42,9 +42,10 @@ function ConvertTo-Table {
4242
}
4343

4444
$Spacer = $true
45-
} Else {
45+
}
46+
else {
4647
# Header row enclosed by ||
47-
If (-not $HeaderGenerated) {
48+
if (-not $HeaderGenerated) {
4849
$null = $sb.AppendLine("|| {0} ||" -f ($_.PSObject.Properties.Name -join " || "))
4950
$HeaderGenerated = $true
5051
}

ConfluencePS/Public/Get-Attachment.ps1

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ function Get-Attachment {
33
[OutputType([ConfluencePS.Attachment])]
44
param (
55
[Parameter( Mandatory = $true )]
6-
[URi]$apiURi,
6+
[uri]$ApiUri,
77

8-
[Parameter( Mandatory = $true )]
8+
[Parameter( Mandatory = $false )]
99
[PSCredential]$Credential,
1010

11+
[Parameter( Mandatory = $false )]
12+
[ValidateNotNull()]
13+
[System.Security.Cryptography.X509Certificates.X509Certificate]
14+
$Certificate,
15+
1116
[Parameter(
1217
Position = 0,
1318
Mandatory = $true,
@@ -28,7 +33,6 @@ function Get-Attachment {
2833

2934
BEGIN {
3035
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"
31-
$resourceApi = "$apiURi/content/{0}/child/attachment"
3236
}
3337

3438
PROCESS {
@@ -41,30 +45,29 @@ function Get-Attachment {
4145
Throw $exception
4246
}
4347

48+
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
49+
$iwParameters['Method'] = 'Get'
50+
$iwParameters['GetParameters'] = @{
51+
expand = "version"
52+
limit = $PageSize
53+
}
54+
$iwParameters['OutputType'] = [ConfluencePS.Attachment]
55+
56+
if ($FileNameFilter) {
57+
$iwParameters["GetParameters"]["filename"] = $FileNameFilter
58+
}
59+
60+
if ($MediaTypeFilter) {
61+
$iwParameters["GetParameters"]["mediaType"] = $MediaTypeFilter
62+
}
63+
64+
# Paging
65+
($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object {
66+
$iwParameters[$_] = $PSCmdlet.PagingParameters.$_
67+
}
68+
4469
foreach ($_PageID in $PageID) {
45-
$iwParameters = @{
46-
Uri = $resourceApi -f $_PageID
47-
Method = 'Get'
48-
GetParameters = @{
49-
expand = "version"
50-
limit = $PageSize
51-
}
52-
OutputType = [ConfluencePS.Attachment]
53-
Credential = $Credential
54-
}
55-
56-
if ($FileNameFilter) {
57-
$iwParameters["GetParameters"]["filename"] = $FileNameFilter
58-
}
59-
60-
if ($MediaTypeFilter) {
61-
$iwParameters["GetParameters"]["mediaType"] = $MediaTypeFilter
62-
}
63-
64-
# Paging
65-
($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object {
66-
$iwParameters[$_] = $PSCmdlet.PagingParameters.$_
67-
}
70+
$iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $_PageID
6871

6972
Invoke-Method @iwParameters
7073
}

0 commit comments

Comments
 (0)