Skip to content

Commit

Permalink
Release v2.5
Browse files Browse the repository at this point in the history
Merge pull request #167 from lipkau/release/v2.5
  • Loading branch information
lipkau authored Mar 28, 2019
2 parents e894bbb + 7bfbf51 commit adb0628
Show file tree
Hide file tree
Showing 49 changed files with 752 additions and 350 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

.

## [2.5] 2019-03-27

### Added

- Added support for authenticating with X509Certificate (#164, [@ritzcrackr])

### Fixed

- Conversion of pageID attribute of Attachments to `[Int]` (#166, [@lipkau])
- Fixed generation of headers in tables when using `ConvertTo-ConfluenceTable` (#163, [@lipkau])

## [2.4] 2018-12-12

### Added
Expand Down Expand Up @@ -189,4 +200,5 @@ No changelog available for version `1.0` of ConfluencePS. `1.0` was created in l
[@lipkau]: https://github.com/lipkau
[@lukhase]: https://github.com/lukhase
[@padgers]: https://github.com/padgers
[@ritzcrackr]: https://github.com/ritzcrackr
[@ThePSAdmin]: https://github.com/ThePSAdmin
2 changes: 1 addition & 1 deletion ConfluencePS/ConfluencePS.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class Attachment {
public String Title { get; set; }
public String Filename { get; set; }
public String MediaType { get; set; }
public Int32 FileSize { get; set; }
public UInt64 FileSize { get; set; }
public String Comment { get; set; }
public String SpaceKey { get; set; }
public Int32 PageID { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ConfluencePS/ConfluencePS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'ConfluencePS.psm1'

# Version number of this module.
ModuleVersion = '2.4'
ModuleVersion = '2.5'

# ID used to uniquely identify this module
GUID = '20d32089-48ef-464d-ba73-6ada240e26b3'
Expand Down
6 changes: 2 additions & 4 deletions ConfluencePS/Private/ConvertTo-Attachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ function ConvertTo-Attachment {
$PageId = $_.container.id
}
else {
$PageID = $_._expandable.container -replace '^.*\/content\/', ''
$PageID = [convert]::ToInt32($PageID, 10)
[UInt32]$PageID = $_._expandable.container -replace '^.*\/content\/', ''
}

[ConfluencePS.Attachment](ConvertTo-Hashtable -InputObject ($object | Select-Object `
@{Name = "id"; Expression = {
$ID = $_.id -replace 'att', ''
[convert]::ToInt32($ID, 10)
[UInt32]($_.id -replace 'att', '')
}
},
status,
Expand Down
45 changes: 45 additions & 0 deletions ConfluencePS/Private/Copy-CommonParameter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Copy-CommonParameter {
<#
.SYNOPSIS
This is a helper function to assist in creating a hashtable for splatting parameters to inner function calls.
.DESCRIPTION
This command copies all of the keys of a hashtable to a new hashtable if the key name matches the DefaultParameter
or the AdditionalParameter values. This function is designed to help select only function parameters that have been
set, so they can be passed to inner functions if and only if they have been set.
.EXAMPLE
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters
Returns a hashtable that contains all of the bound default parameters.
.EXAMPLE
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri"
Returns a hashtable that contains all of the bound default parameters and the "ApiUri" parameter.
#>
[CmdletBinding( SupportsShouldProcess = $false )]
[OutputType(
[hashtable]
)]
param
(
[Parameter(Mandatory = $true)]
[hashtable]$InputObject,

[Parameter(Mandatory = $false)]
[string[]]$AdditionalParameter,

[Parameter(Mandatory = $false)]
[string[]]$DefaultParameter = @("Credential", "Certificate")
)

[hashtable]$ht = @{}
foreach ($key in $InputObject.Keys) {
if ($key -in ($DefaultParameter + $AdditionalParameter)) {
$ht[$key] = $InputObject[$key]
}
}

return $ht
}
27 changes: 14 additions & 13 deletions ConfluencePS/Public/Add-Attachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ function Add-Attachment {
[OutputType([ConfluencePS.Attachment])]
param(
[Parameter( Mandatory = $true )]
[URi]$apiURi,
[uri]$ApiUri,

[Parameter( Mandatory = $true )]
[Parameter( Mandatory = $false )]
[PSCredential]$Credential,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,

[Parameter(
Position = 0,
Mandatory = $true,
Expand Down Expand Up @@ -46,27 +51,23 @@ function Add-Attachment {

begin {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

$resourceApi = "$apiURi/content/{0}/child/attachment"
}

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

$parameter = @{
URI = $resourceApi -f $PageID
Method = "POST"
Credential = $Credential
OutputType = [ConfluencePS.Attachment]
Verbose = $false
}
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
$iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $PageID
$iwParameters['Method'] = 'Post'
$iwParameters['OutputType'] = [ConfluencePS.Attachment]

foreach ($file in $FilePath) {
$parameter["InFile"] = $file
$iwParameters["InFile"] = $file

Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking Add Attachment Method with `$parameter"
if ($PSCmdlet.ShouldProcess($PageID, "Adding attachment(s) '$($file)'.")) {
Invoke-Method @parameter
Invoke-Method @iwParameters
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions ConfluencePS/Public/Add-Label.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ function Add-Label {
[OutputType([ConfluencePS.ContentLabelSet])]
param (
[Parameter( Mandatory = $true )]
[URi]$apiURi,
[uri]$ApiUri,

[Parameter( Mandatory = $true )]
[Parameter( Mandatory = $false )]
[PSCredential]$Credential,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,

[Parameter(
Position = 0,
ValueFromPipeline = $true,
Expand All @@ -32,7 +37,7 @@ function Add-Label {
BEGIN {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

$resourceApi = "$apiURi/content/{0}/label"
$resourceApi = "$ApiUri/content/{0}/label"
}

PROCESS {
Expand Down Expand Up @@ -71,13 +76,9 @@ function Add-Label {
Throw $exception
}

$iwParameters = @{
Uri = ""
Method = 'Post'
Body = ""
OutputType = [ConfluencePS.Label]
Credential = $Credential
}
$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
$iwParameters['Method'] = 'Post'
$iwParameters['OutputType'] = [ConfluencePS.Label]

# Extract name if an Object is provided
if (($Label -is [ConfluencePS.Label]) -or $Label -is [ConfluencePS.Label[]]) {
Expand All @@ -92,14 +93,15 @@ function Add-Label {
$InputObject = $_.Page
}
else {
$InputObject = Get-Page -PageID $_page -ApiURi $apiURi -Credential $Credential
$authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri"
$InputObject = Get-Page -PageID $_page @authAndApiUri
}

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

Write-Debug "[$($MyInvocation.MyCommand.Name)] Content to be sent: $($iwParameters["Body"] | Out-String)"
If ($PSCmdlet.ShouldProcess("Label $Label, PageID $_page")) {
if ($PSCmdlet.ShouldProcess("Label $Label, PageID $_page")) {
$output = [ConfluencePS.ContentLabelSet]@{ Page = $InputObject }
$output.Labels += (Invoke-Method @iwParameters)
$output
Expand Down
26 changes: 15 additions & 11 deletions ConfluencePS/Public/ConvertTo-StorageFormat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ function ConvertTo-StorageFormat {
[OutputType([String])]
param (
[Parameter( Mandatory = $true )]
[URi]$apiURi,
[uri]$ApiUri,

[Parameter( Mandatory = $true )]
[Parameter( Mandatory = $false )]
[PSCredential]$Credential,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,

[Parameter(
Position = 0,
Mandatory = $true,
Expand All @@ -24,16 +29,15 @@ function ConvertTo-StorageFormat {
Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
$iwParameters['Uri'] = "$ApiUri/contentbody/convert/storage"
$iwParameters['Method'] = 'Post'

foreach ($_content in $Content) {
$iwParameters = @{
Uri = "$apiURi/contentbody/convert/storage"
Method = 'Post'
Body = @{
value = "$_content"
representation = 'wiki'
} | ConvertTo-Json
Credential = $Credential
}
$iwParameters['Body'] = @{
value = "$_content"
representation = 'wiki'
} | ConvertTo-Json

Write-Debug "[$($MyInvocation.MyCommand.Name)] Content to be sent: $($_content | Out-String)"
(Invoke-Method @iwParameters).value
Expand Down
13 changes: 7 additions & 6 deletions ConfluencePS/Public/ConvertTo-Table.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ function ConvertTo-Table {

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

# Put an empty row between multiple tables (objects)
If ($Spacer) {
if ($Spacer) {
$null = $sb.AppendLine('')
}

Expand All @@ -42,9 +42,10 @@ function ConvertTo-Table {
}

$Spacer = $true
} Else {
}
else {
# Header row enclosed by ||
If (-not $HeaderGenerated) {
if (-not $HeaderGenerated) {
$null = $sb.AppendLine("|| {0} ||" -f ($_.PSObject.Properties.Name -join " || "))
$HeaderGenerated = $true
}
Expand Down
55 changes: 29 additions & 26 deletions ConfluencePS/Public/Get-Attachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ function Get-Attachment {
[OutputType([ConfluencePS.Attachment])]
param (
[Parameter( Mandatory = $true )]
[URi]$apiURi,
[uri]$ApiUri,

[Parameter( Mandatory = $true )]
[Parameter( Mandatory = $false )]
[PSCredential]$Credential,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,

[Parameter(
Position = 0,
Mandatory = $true,
Expand All @@ -28,7 +33,6 @@ function Get-Attachment {

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

PROCESS {
Expand All @@ -41,30 +45,29 @@ function Get-Attachment {
Throw $exception
}

$iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters
$iwParameters['Method'] = 'Get'
$iwParameters['GetParameters'] = @{
expand = "version"
limit = $PageSize
}
$iwParameters['OutputType'] = [ConfluencePS.Attachment]

if ($FileNameFilter) {
$iwParameters["GetParameters"]["filename"] = $FileNameFilter
}

if ($MediaTypeFilter) {
$iwParameters["GetParameters"]["mediaType"] = $MediaTypeFilter
}

# Paging
($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object {
$iwParameters[$_] = $PSCmdlet.PagingParameters.$_
}

foreach ($_PageID in $PageID) {
$iwParameters = @{
Uri = $resourceApi -f $_PageID
Method = 'Get'
GetParameters = @{
expand = "version"
limit = $PageSize
}
OutputType = [ConfluencePS.Attachment]
Credential = $Credential
}

if ($FileNameFilter) {
$iwParameters["GetParameters"]["filename"] = $FileNameFilter
}

if ($MediaTypeFilter) {
$iwParameters["GetParameters"]["mediaType"] = $MediaTypeFilter
}

# Paging
($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object {
$iwParameters[$_] = $PSCmdlet.PagingParameters.$_
}
$iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $_PageID

Invoke-Method @iwParameters
}
Expand Down
Loading

0 comments on commit adb0628

Please sign in to comment.