AtlassianPS / ConfluencePS

Confluence REST API (including Cloud) via PowerShell
https://AtlassianPS.org/module/ConfluencePS
MIT License
149 stars 42 forks source link

Piping to Get-ConfluencePage #75

Closed brianbunke closed 7 years ago

brianbunke commented 7 years ago

Expected Behavior

Piping [ConfluencePS.Space] objects into Get-ConfluencePage should bind to the -Space parameter and filter page results accordingly.

Current Behavior

I receive an error when attempting this.

Steps to Reproduce (for bugs)

PS C:\> Get-ConfluenceSpace -SpaceKey KB | Get-ConfluencePage
WARNING: Confluence returned HTTP error 404 - NotFound
Invoke-Method : 
At [...]\ConfluencePS\Public\Get-Page.ps1:168 char:21
+                     Invoke-Method @iwParameters
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-Method

Your Environment

ConfluencePS develop branch, a689311e61c12de9de5ba5d4de9db3b44be9c58f

lipkau commented 7 years ago

The problem is this line: https://github.com/AtlassianPS/ConfluencePS/blob/develop/ConfluencePS/Public/Get-Page.ps1#L19

by allowing the parameter to by piped by property name, which is ID, piping a Space object (which also includes the id property), it thinks the Space is the PageID. We can:

brianbunke commented 7 years ago

Sorry, but would you please clarify your two suggestions?

lipkau commented 7 years ago
brianbunke commented 7 years ago

By changing this:

# Filter results by space object(s), typically from the pipeline
[Parameter(
    Mandatory = $true,
    ValueFromPipeline = $true,
    ParameterSetName = "bySpaceObject"
)]
[Parameter(
    ValueFromPipeline = $true,
    ParameterSetName = "byTitle"
)]
[Parameter(
    ValueFromPipeline = $true,
    ParameterSetName = "byLabel"
)]
[ConfluencePS.Space]$Space,

To this:

# Filter results by space object(s), typically from the pipeline
[Parameter(
    Mandatory = $true,
    ValueFromPipeline = $true,
    ValueFromPipelineByPropertyName = $true,
    ParameterSetName = "bySpaceObject"
)]
[Parameter(
    ValueFromPipeline = $true,
    ValueFromPipelineByPropertyName = $true,
    ParameterSetName = "byTitle"
)]
[Parameter(
    ValueFromPipeline = $true,
    ValueFromPipelineByPropertyName = $true,
    ParameterSetName = "byLabel"
)]
[ConfluencePS.Space]$Space,

The problem is fixed for me. We can clean things up, but at first glance, this appears to solve the issue without breaking PageID piping.

lipkau commented 7 years ago

That works indeed: if more than one parameter can be bound from the pipeline by property name, the argument with the same type hint as the $_ in the pipe will be preferred