From 19a1bc3cfb3540df11e97f7b6ae106883ca7f057 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 15:34:07 -0500 Subject: [PATCH 01/23] Initial Commit to add Certificate and Anonymous Authentication support. Copy-CommonParameter.ps1 -This function simplifies the propagating of parameters for splatting. -The default parameters are just the auth parameters Invoke-Method.ps1 -Updated to support pass Certificate to Invoke-WebRequest. -Rename $Uri to have a consistent case both inside and from callers. -Leveraged Copy-CommonParameters to simplify the code -Simplified the appending of the query parameter logic. -Fixed passing 'Body' to in the paginated results code path. Invoke-Method.md -Update docs to include the new Certificate Parameter. --- ConfluencePS/Private/Copy-CommonParameter.ps1 | 30 ++++++++++ ConfluencePS/Public/Invoke-Method.ps1 | 60 ++++++++----------- docs/en-US/commands/Invoke-Method.md | 24 +++++++- 3 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 ConfluencePS/Private/Copy-CommonParameter.ps1 diff --git a/ConfluencePS/Private/Copy-CommonParameter.ps1 b/ConfluencePS/Private/Copy-CommonParameter.ps1 new file mode 100644 index 0000000..83429f5 --- /dev/null +++ b/ConfluencePS/Private/Copy-CommonParameter.ps1 @@ -0,0 +1,30 @@ +function Copy-CommonParameter +{ + [CmdletBinding( SupportsShouldProcess = $false )] + [OutputType( + [hashtable] + )] + #[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] + 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 +} diff --git a/ConfluencePS/Public/Invoke-Method.ps1 b/ConfluencePS/Public/Invoke-Method.ps1 index fb2c031..62bcf4c 100644 --- a/ConfluencePS/Public/Invoke-Method.ps1 +++ b/ConfluencePS/Public/Invoke-Method.ps1 @@ -13,7 +13,7 @@ function Invoke-Method { [Diagnostics.CodeAnalysis.SuppressMessageAttribute( "PSAvoidUsingEmptyCatchBlock", "" )] param ( [Parameter(Mandatory = $true)] - [Uri]$URi, + [Uri]$Uri, [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = "GET", @@ -41,9 +41,14 @@ function Invoke-Method { )] [System.Type]$OutputType, - [Parameter(Mandatory = $true)] + [Parameter( Mandatory = $false )] [PSCredential]$Credential, + [Parameter( Mandatory = $false )] + [ValidateNotNull()] + [System.Security.Cryptography.X509Certificates.X509Certificate] + $Certificate, + $Caller = $PSCmdlet ) @@ -55,7 +60,7 @@ function Invoke-Method { # Sanitize double slash `//` # Happens when the BaseUri is the domain name # [Uri]"http://google.com" vs [Uri]"http://google.com/foo" - $URi = $URi -replace '(? Date: Sun, 10 Feb 2019 15:51:04 -0500 Subject: [PATCH 02/23] Add Support for Certificate and Annoymous Auth to Get-Page Get-Page.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Get-Page.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Get-Page.ps1 | 31 +++++++++++++++++-------------- docs/en-US/commands/Get-Page.md | 20 +++++++++++++++++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ConfluencePS/Public/Get-Page.ps1 b/ConfluencePS/Public/Get-Page.ps1 index 0ee184c..0c4d3bb 100644 --- a/ConfluencePS/Public/Get-Page.ps1 +++ b/ConfluencePS/Public/Get-Page.ps1 @@ -6,11 +6,16 @@ function Get-Page { [OutputType([ConfluencePS.Page])] 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, @@ -73,7 +78,16 @@ function Get-Page { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content{0}" + $resourceApi = "$ApiUri/content{0}" + + #setup defaults that don't change based on the pipeline or the parameter set + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Get' + $iwParameters['GetParameters'] = @{ + expand = "space,version,body.storage,ancestors" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Page] } PROCESS { @@ -84,17 +98,6 @@ function Get-Page { $SpaceKey = $Space.Key } - $iwParameters = @{ - Uri = "" - Method = 'Get' - GetParameters = @{ - expand = "space,version,body.storage,ancestors" - limit = $PageSize - } - OutputType = [ConfluencePS.Page] - Credential = $Credential - } - # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { $iwParameters[$_] = $PSCmdlet.PagingParameters.$_ diff --git a/docs/en-US/commands/Get-Page.md b/docs/en-US/commands/Get-Page.md index 3aee43e..332f9ea 100644 --- a/docs/en-US/commands/Get-Page.md +++ b/docs/en-US/commands/Get-Page.md @@ -125,7 +125,25 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate to use for the authentication with the REST Api. + +If no sessions is available, the request will be executed anonymously. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 09c9d7f884d564b45d736f329a4ce2e8a79112e6 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 16:18:04 -0500 Subject: [PATCH 03/23] Add Support for Certificate and Annoymous Auth to Get-ChildPage Get-ChildPage.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. -Simplified the "Recurse" logic. -Identified issue handling ConfluencePS.Page objects via pipeline. Get-ChildPage.md -Added Certificate Parameter -Made Credential Parameter not mandatory Get-Page.md -Fixed 'ApiUri' casing in documentation --- ConfluencePS/Public/Get-ChildPage.ps1 | 35 +++++++++++++++------------ docs/en-US/commands/Get-ChildPage.md | 20 +++++++++++++-- docs/en-US/commands/Get-Page.md | 2 +- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/ConfluencePS/Public/Get-ChildPage.ps1 b/ConfluencePS/Public/Get-ChildPage.ps1 index 7e866d8..bfa1cb8 100644 --- a/ConfluencePS/Public/Get-ChildPage.ps1 +++ b/ConfluencePS/Public/Get-ChildPage.ps1 @@ -3,11 +3,16 @@ function Get-ChildPage { [OutputType([ConfluencePS.Page])] 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, @@ -26,35 +31,35 @@ function Get-ChildPage { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - - $depthLevel = "child" } PROCESS { Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" + #Fix: See fix statement below. These two fix statements are tied together if (($_) -and -not($_ -is [ConfluencePS.Page] -or $_ -is [int])) { $message = "The Object in the pipe is not a Page." $exception = New-Object -TypeName System.ArgumentException -ArgumentList $message Throw $exception } + #Fix: This doesn't get called since there are no parameter sets for this function. It must be + #copy paste from another function. This function doesn't really accept ConfluencePS.Page objects, it only + #works due to powershell grabbing the 'ID' from ConfluencePS.Page using the + #'ValueFromPipelineByPropertyName = $true' and '[Alias('ID')]' on the PageID Parameter. if ($PsCmdlet.ParameterSetName -eq "byObject") { $PageID = $InputObject.ID } - if ($Recurse) { $depthLevel = "descendant" } # depth = ALL - $iwParameters = @{ - Uri = "$apiURi/content/{0}/{1}/page" -f $PageID, $depthLevel - Method = 'Get' - GetParameters = @{ - expand = "space,version,body.storage,ancestors" - limit = $PageSize - } - OutputType = [ConfluencePS.Page] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Uri'] = if ($Recurse.IsPresent) {"$ApiUri/content/{0}/descendant/page" -f $PageID} else {"$ApiUri/content/{0}/child/page" -f $PageID} + $iwParameters['Method'] = 'Get' + $iwParameters['GetParameters'] = @{ + expand = "space,version,body.storage,ancestors" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Page] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { diff --git a/docs/en-US/commands/Get-ChildPage.md b/docs/en-US/commands/Get-ChildPage.md index 4209a10..6b7cce2 100644 --- a/docs/en-US/commands/Get-ChildPage.md +++ b/docs/en-US/commands/Get-ChildPage.md @@ -48,7 +48,7 @@ return grandchildren, great-grandchildren, and so on. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -75,7 +75,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False diff --git a/docs/en-US/commands/Get-Page.md b/docs/en-US/commands/Get-Page.md index 332f9ea..0167cc6 100644 --- a/docs/en-US/commands/Get-Page.md +++ b/docs/en-US/commands/Get-Page.md @@ -98,7 +98,7 @@ Return all pages matching the query. ## PARAMETERS -### -ApiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. From 6d4834c3f3b453607e57ac79aa3305a2f7460d26 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:09:02 -0500 Subject: [PATCH 04/23] Add Support for Certificate and Annoymous Auth to Add-Attachment Add-Attachment.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Add-Attachment.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Add-Attachment.ps1 | 27 +++++++++++++------------- docs/en-US/commands/Add-Attachment.md | 22 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ConfluencePS/Public/Add-Attachment.ps1 b/ConfluencePS/Public/Add-Attachment.ps1 index fefa572..05af08a 100644 --- a/ConfluencePS/Public/Add-Attachment.ps1 +++ b/ConfluencePS/Public/Add-Attachment.ps1 @@ -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, @@ -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 } } } diff --git a/docs/en-US/commands/Add-Attachment.md b/docs/en-US/commands/Add-Attachment.md index 746a9e0..e63338a 100644 --- a/docs/en-US/commands/Add-Attachment.md +++ b/docs/en-US/commands/Add-Attachment.md @@ -16,7 +16,7 @@ Add a new attachment to an existing Confluence page. ## SYNTAX ```powershell -Add-ConfluenceAttachment -apiURi -Credential [[-PageID] ] -FilePath [-WhatIf] [-Confirm] +Add-ConfluenceAttachment -ApiUri -Credential [[-PageID] ] -FilePath [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -48,7 +48,7 @@ Simulates adding the Attachment test.png to all pages in the space with key SRV. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-Info. @@ -75,7 +75,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 6c1e6dfb02dcc24af93f5433427583d6b1845098 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:11:05 -0500 Subject: [PATCH 05/23] Add Support for Certificate and Annoymous Auth to Add-Label Add-Label.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Add-Label.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Add-Label.ps1 | 26 ++++++++++++++------------ docs/en-US/commands/Get-Label.md | 22 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/ConfluencePS/Public/Add-Label.ps1 b/ConfluencePS/Public/Add-Label.ps1 index 9748dae..c3c31cc 100644 --- a/ConfluencePS/Public/Add-Label.ps1 +++ b/ConfluencePS/Public/Add-Label.ps1 @@ -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, @@ -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 { @@ -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[]]) { @@ -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 diff --git a/docs/en-US/commands/Get-Label.md b/docs/en-US/commands/Get-Label.md index 700d512..39439ca 100644 --- a/docs/en-US/commands/Get-Label.md +++ b/docs/en-US/commands/Get-Label.md @@ -16,7 +16,7 @@ Retrieve all labels applied to the given object(s). ## SYNTAX ```powershell -Get-ConfluenceLabel -apiURi -Credential [-PageID] [-PageSize ] +Get-ConfluenceLabel -ApiUri -Credential [-PageID] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` @@ -46,7 +46,7 @@ return the full list of labels found on each page. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -73,7 +73,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 6b846beebf977b0c1c96aa63bac271b4f55f0e51 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:12:21 -0500 Subject: [PATCH 06/23] Add Support for Certificate and Annoymous Auth to ConvertTo-StorageFormat ConvertTo-StorageFormat.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. ConvertTo-StorageFormat.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- .../Public/ConvertTo-StorageFormat.ps1 | 26 +++++++++++-------- .../en-US/commands/ConvertTo-StorageFormat.md | 22 +++++++++++++--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 b/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 index cbcf8b3..c450ca5 100644 --- a/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 +++ b/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 @@ -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, @@ -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 diff --git a/docs/en-US/commands/ConvertTo-StorageFormat.md b/docs/en-US/commands/ConvertTo-StorageFormat.md index 9c9b659..06c8a22 100644 --- a/docs/en-US/commands/ConvertTo-StorageFormat.md +++ b/docs/en-US/commands/ConvertTo-StorageFormat.md @@ -16,7 +16,7 @@ Convert your content to Confluence's storage format. ## SYNTAX ```powershell -ConvertTo-ConfluenceStorageFormat -apiURi -Credential [-Content] +ConvertTo-ConfluenceStorageFormat -ApiUri -Credential [-Content] ``` ## DESCRIPTION @@ -45,7 +45,7 @@ Pipe the current date/time in sortable format, returning the converted string. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -72,7 +72,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 32df6eb383468de9f314e66807a2e191f0ebfdff Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:14:22 -0500 Subject: [PATCH 07/23] Add Support for Certificate and Annoymous Auth to Get-Attachment Get-Attachment.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Get-Attachment.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Get-Attachment.ps1 | 55 ++++++++++++++------------ docs/en-US/commands/Get-Attachment.md | 22 +++++++++-- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/ConfluencePS/Public/Get-Attachment.ps1 b/ConfluencePS/Public/Get-Attachment.ps1 index b7d2d62..28dbb8e 100644 --- a/ConfluencePS/Public/Get-Attachment.ps1 +++ b/ConfluencePS/Public/Get-Attachment.ps1 @@ -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, @@ -28,7 +33,6 @@ function Get-Attachment { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}/child/attachment" } PROCESS { @@ -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 } diff --git a/docs/en-US/commands/Get-Attachment.md b/docs/en-US/commands/Get-Attachment.md index 94e535d..89875e8 100644 --- a/docs/en-US/commands/Get-Attachment.md +++ b/docs/en-US/commands/Get-Attachment.md @@ -16,7 +16,7 @@ Retrieve the child Attachments of a given wiki Page. ## SYNTAX ```powershell -Get-ConfluenceAttachment -apiURi -Credential [-PageID] [-FileNameFilter ] [-MediaTypeFilter ] [-Skip ] [-First ] [-PageSize ] [-IncludeTotalCount] +Get-ConfluenceAttachment -ApiUri -Credential [-PageID] [-FileNameFilter ] [-MediaTypeFilter ] [-Skip ] [-First ] [-PageSize ] [-IncludeTotalCount] ``` ## DESCRIPTION @@ -63,7 +63,7 @@ Returns any attachments of mime type image/png from Page 123456. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -90,7 +90,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From f8adddad3e11a08a618663edc69e98a276b7f5f1 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:15:16 -0500 Subject: [PATCH 08/23] Add Support for Certificate and Annoymous Auth to Get-AttachmentFile Get-AttachmentFile.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Get-AttachmentFile.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Get-AttachmentFile.ps1 | 29 ++++++++++------------ docs/en-US/commands/Get-AttachmentFile.md | 22 +++++++++++++--- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/ConfluencePS/Public/Get-AttachmentFile.ps1 b/ConfluencePS/Public/Get-AttachmentFile.ps1 index 0524698..b0e92df 100644 --- a/ConfluencePS/Public/Get-AttachmentFile.ps1 +++ b/ConfluencePS/Public/Get-AttachmentFile.ps1 @@ -3,11 +3,16 @@ function Get-AttachmentFile { [OutputType([Bool])] 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, @@ -49,21 +54,13 @@ function Get-AttachmentFile { Throw $exception } - foreach ($_Attachment in $Attachment) { - if ($Path) { - $filename = Join-Path $Path $_Attachment.Filename - } - else { - $filename = $_Attachment.Filename - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Get' - $iwParameters = @{ - Uri = $_Attachment.URL - Method = 'Get' - Headers = @{"Accept" = $_Attachment.MediaType} - OutFile = $filename - Credential = $Credential - } + foreach ($_Attachment in $Attachment) { + $iwParameters['Uri'] = $_Attachment.URL + $iwParameters['Headers'] = @{"Accept" = $_Attachment.MediaType} + $iwParameters['OutFile'] = if ($Path) {Join-Path -Path $Path -ChildPath $_Attachment.Filename} else {$_Attachment.Filename} $result = Invoke-Method @iwParameters (-not $result) diff --git a/docs/en-US/commands/Get-AttachmentFile.md b/docs/en-US/commands/Get-AttachmentFile.md index 1d08be3..d844f72 100644 --- a/docs/en-US/commands/Get-AttachmentFile.md +++ b/docs/en-US/commands/Get-AttachmentFile.md @@ -16,7 +16,7 @@ Retrieves the binary Attachment for a given Attachment object. ## SYNTAX ```powershell -Get-ConfluenceAttachmentFile -apiURi -Credential [-Attachment] [-Path ] +Get-ConfluenceAttachmentFile -ApiUri -Credential [-Attachment] [-Path ] ``` ## DESCRIPTION @@ -48,7 +48,7 @@ with the page ID and the attachment filename. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -75,7 +75,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From c39b0667ff07c56705f7f62446b6804f07640ce7 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:18:38 -0500 Subject: [PATCH 09/23] Add Support for Certificate and Annoymous Auth to Get-Label Get-Lebal.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Get-Label.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Get-Label.ps1 | 29 ++++++++++++++++------------- docs/en-US/commands/Add-Label.md | 22 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ConfluencePS/Public/Get-Label.ps1 b/ConfluencePS/Public/Get-Label.ps1 index 388786a..4f8f7d1 100644 --- a/ConfluencePS/Public/Get-Label.ps1 +++ b/ConfluencePS/Public/Get-Label.ps1 @@ -5,11 +5,16 @@ function Get-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, Mandatory = $true, @@ -27,7 +32,7 @@ function Get-Label { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}/label" + $resourceApi = "$ApiUri/content/{0}/label" } PROCESS { @@ -40,15 +45,12 @@ function Get-Label { Throw $exception } - $iwParameters = @{ - Uri = "" - Method = 'Get' - GetParameters = @{ - limit = $PageSize - } - OutputType = [ConfluencePS.Label] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Get' + $iwParameters['GetParameters'] = @{ + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Label] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { @@ -60,7 +62,8 @@ function Get-Label { $InputObject = $_ } 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 $output = New-Object -TypeName ConfluencePS.ContentLabelSet diff --git a/docs/en-US/commands/Add-Label.md b/docs/en-US/commands/Add-Label.md index 58da178..e378990 100644 --- a/docs/en-US/commands/Add-Label.md +++ b/docs/en-US/commands/Add-Label.md @@ -16,7 +16,7 @@ Add a new global label to an existing Confluence page. ## SYNTAX ```powershell -Add-ConfluenceLabel -apiURi -Credential [[-PageID] ] -Label [-WhatIf] [-Confirm] +Add-ConfluenceLabel -ApiUri -Credential [[-PageID] ] -Label [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -57,7 +57,7 @@ Applies the label "abc" to all pages in the space with key DEMO. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-Info. @@ -84,7 +84,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 0cf671d1f776c89da848437282bb76bf1ec09f94 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:23:56 -0500 Subject: [PATCH 10/23] Add Support for Certificate and Annoymous Auth to Get-Space Get-Space.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Get-Space.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Get-Space.ps1 | 28 +++++++++++++++------------- docs/en-US/commands/Get-Space.md | 24 ++++++++++++++++++++---- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/ConfluencePS/Public/Get-Space.ps1 b/ConfluencePS/Public/Get-Space.ps1 index 99e9d6a..7287302 100644 --- a/ConfluencePS/Public/Get-Space.ps1 +++ b/ConfluencePS/Public/Get-Space.ps1 @@ -5,11 +5,16 @@ function Get-Space { [OutputType([ConfluencePS.Space])] 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 )] @@ -23,23 +28,20 @@ function Get-Space { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/space{0}" + $resourceApi = "$ApiUri/space{0}" } PROCESS { Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" - $iwParameters = @{ - Uri = "" - Method = 'Get' - GetParameters = @{ - expand = "description.plain,icon,homepage,metadata.labels" - limit = $PageSize - } - OutputType = [ConfluencePS.Space] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Get' + $iwParameters['GetParameters'] = @{ + expand = "description.plain,icon,homepage,metadata.labels" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Space] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { diff --git a/docs/en-US/commands/Get-Space.md b/docs/en-US/commands/Get-Space.md index 15d46a5..f66b201 100644 --- a/docs/en-US/commands/Get-Space.md +++ b/docs/en-US/commands/Get-Space.md @@ -17,7 +17,7 @@ Retrieve a listing of spaces in your Confluence instance. ## SYNTAX ```powershell -Get-ConfluenceSpace -apiURi -Credential [[-SpaceKey] ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluenceSpace -ApiUri -Credential [[-SpaceKey] ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ## DESCRIPTION @@ -47,7 +47,7 @@ Return only the space with key "HOTH" (case-insensitive). ### -------------------------- EXAMPLE 3 -------------------------- ```powershell -Get-ConfluenceSpace -ApiURi "https://myserver.com/wiki" -Credential $cred +Get-ConfluenceSpace -ApiUri "https://myserver.com/wiki" -Credential $cred ``` Manually specifying a server and authentication credentials, list all @@ -56,7 +56,7 @@ unnecessary, unless you are actively maintaining multiple instances. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -83,7 +83,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 431fbb938d0efa5f59143ef7ed3f3c48fc019ed6 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:25:04 -0500 Subject: [PATCH 11/23] Add Support for Certificate and Annoymous Auth to New-Page New-Page.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. New-Page.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/New-Page.ps1 | 33 ++++++++++++++++++-------------- docs/en-US/commands/New-Page.md | 24 +++++++++++++++++++---- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/ConfluencePS/Public/New-Page.ps1 b/ConfluencePS/Public/New-Page.ps1 index 2f10c7c..17caeb7 100644 --- a/ConfluencePS/Public/New-Page.ps1 +++ b/ConfluencePS/Public/New-Page.ps1 @@ -7,11 +7,16 @@ function New-Page { [OutputType([ConfluencePS.Page])] 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( Mandatory = $true, ValueFromPipeline = $true, @@ -48,20 +53,18 @@ function New-Page { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content" + $resourceApi = "$ApiUri/content" } PROCESS { Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" - $iwParameters = @{ - Uri = $resourceApi - Method = 'Post' - Body = "" - OutputType = [ConfluencePS.Page] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Uri'] = $resourceApi + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Page] + $Content = [PSObject]@{ type = "page" space = [PSObject]@{ key = ""} @@ -91,15 +94,17 @@ function New-Page { $SpaceKey = $Space.Key } - If (($ParentID) -and !($SpaceKey)) { + if (($ParentID) -and !($SpaceKey)) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] SpaceKey not specified. Retrieving from Get-ConfluencePage -PageID $ParentID" - $SpaceKey = (Get-Page -PageID $ParentID -ApiURi $apiURi -Credential $Credential).Space.Key + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" + $SpaceKey = (Get-Page -PageID $ParentID @authAndApiUri).Space.Key } # If -Convert is flagged, call ConvertTo-ConfluenceStorageFormat against the -Body - If ($Convert) { + if ($Convert) { Write-Verbose '[$($MyInvocation.MyCommand.Name)] -Convert flag active; converting content to Confluence storage format' - $Body = ConvertTo-StorageFormat -Content $Body -ApiURi $apiURi -Credential $Credential + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" + $Body = ConvertTo-StorageFormat -Content $Body @authAndApiUri } $Content.title = $Title diff --git a/docs/en-US/commands/New-Page.md b/docs/en-US/commands/New-Page.md index f38d7c0..83dea54 100644 --- a/docs/en-US/commands/New-Page.md +++ b/docs/en-US/commands/New-Page.md @@ -18,13 +18,13 @@ Create a new page on your Confluence instance. ### byParameters (Default) ```powershell -New-ConfluencePage -apiURi -Credential -Title [-ParentID ] [-Parent ] [-SpaceKey ] [-Space ] [-Body ] [-Convert] [-WhatIf] [-Confirm] +New-ConfluencePage -ApiUri -Credential -Title [-ParentID ] [-Parent ] [-SpaceKey ] [-Space ] [-Body ] [-Convert] [-WhatIf] [-Confirm] ``` ### byObject ```powershell -New-ConfluencePage -apiURi -Credential -InputObject [-WhatIf] [-Confirm] +New-ConfluencePage -ApiUri -Credential -InputObject [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -104,7 +104,7 @@ Both examples should return identical results. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -131,7 +131,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 8947377ce56b4b8ae5fa85aaeab1b63661cd0c4a Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:25:45 -0500 Subject: [PATCH 12/23] Add Support for Certificate and Annoymous Auth to New-Space New-Space.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. New-Space.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/New-Space.ps1 | 23 +++++++++++++---------- docs/en-US/commands/New-Space.md | 24 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ConfluencePS/Public/New-Space.ps1 b/ConfluencePS/Public/New-Space.ps1 index cde9cfb..8a485c4 100644 --- a/ConfluencePS/Public/New-Space.ps1 +++ b/ConfluencePS/Public/New-Space.ps1 @@ -7,11 +7,16 @@ function New-Space { [OutputType([ConfluencePS.Space])] 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( Mandatory = $true, ParameterSetName = "byObject", @@ -41,7 +46,7 @@ function New-Space { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/space" + $resourceApi = "$ApiUri/space" } PROCESS { @@ -54,13 +59,11 @@ function New-Space { $Description = $InputObject.Description } - $iwParameters = @{ - Uri = $resourceApi - Method = 'Post' - Body = "" - OutputType = [ConfluencePS.Space] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Uri'] = $resourceApi + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Space] + $Body = @{ key = $SpaceKey name = $Name diff --git a/docs/en-US/commands/New-Space.md b/docs/en-US/commands/New-Space.md index 9a7a39f..62a6019 100644 --- a/docs/en-US/commands/New-Space.md +++ b/docs/en-US/commands/New-Space.md @@ -18,13 +18,13 @@ Create a new blank space on your Confluence instance. ### byObject (Default) ```powershell -New-ConfluenceSpace -apiURi -Credential -InputObject [-WhatIf] [-Confirm] +New-ConfluenceSpace -ApiUri -Credential -InputObject [-WhatIf] [-Confirm] ``` ### byProperties ```powershell -New-ConfluenceSpace -apiURi -Credential -SpaceKey -Name +New-ConfluenceSpace -ApiUri -Credential -SpaceKey -Name [-Description ] [-WhatIf] [-Confirm] ``` @@ -65,7 +65,7 @@ Both examples should return identical results. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -92,7 +92,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 1dc60ab7e06a0640674707c343e4f84acb223edf Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:26:34 -0500 Subject: [PATCH 13/23] Add Support for Certificate and Annoymous Auth to Remove-Attachment Remove-Attachment.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Remove-Attachment.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Remove-Attachment.ps1 | 20 +++++++++++--------- docs/en-US/commands/Remove-Attachment.md | 22 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/ConfluencePS/Public/Remove-Attachment.ps1 b/ConfluencePS/Public/Remove-Attachment.ps1 index ce2aa58..868fe70 100644 --- a/ConfluencePS/Public/Remove-Attachment.ps1 +++ b/ConfluencePS/Public/Remove-Attachment.ps1 @@ -6,11 +6,16 @@ function Remove-Attachment { [OutputType([Bool])] 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, @@ -22,23 +27,20 @@ function Remove-Attachment { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}" + $resourceApi = "$ApiUri/content/{0}" } PROCESS { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" - $iwParameters = @{ - Uri = "" - Method = 'Delete' - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Delete' foreach ($_attachment in $Attachment) { $iwParameters["Uri"] = $resourceApi -f $_attachment.ID - If ($PSCmdlet.ShouldProcess("Attachment $($_attachment.ID), PageID $($_attachment.PageID)")) { + if ($PSCmdlet.ShouldProcess("Attachment $($_attachment.ID), PageID $($_attachment.PageID)")) { Invoke-Method @iwParameters } } diff --git a/docs/en-US/commands/Remove-Attachment.md b/docs/en-US/commands/Remove-Attachment.md index 20d8676..1e2fe2a 100644 --- a/docs/en-US/commands/Remove-Attachment.md +++ b/docs/en-US/commands/Remove-Attachment.md @@ -16,7 +16,7 @@ Remove an Attachment. ## SYNTAX ```powershell -Remove-ConfluenceAttachment -apiURi -Credential [-Attachment] [-WhatIf] [-Confirm] +Remove-ConfluenceAttachment -ApiUri -Credential [-Attachment] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -57,7 +57,7 @@ Remove all Attachments on page 123456. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -84,7 +84,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 79f871bec8090e48f5112cdd9b074071467ca7ad Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:30:33 -0500 Subject: [PATCH 14/23] Add Support for Certificate and Annoymous Auth to Remove-Label Remove-Label.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Remove-Label.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Remove-Label.ps1 | 23 +++++++++++++---------- docs/en-US/commands/Remove-Label.md | 22 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ConfluencePS/Public/Remove-Label.ps1 b/ConfluencePS/Public/Remove-Label.ps1 index 741e714..241b1d0 100644 --- a/ConfluencePS/Public/Remove-Label.ps1 +++ b/ConfluencePS/Public/Remove-Label.ps1 @@ -6,11 +6,16 @@ function Remove-Label { [OutputType([Bool])] 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, @@ -28,7 +33,7 @@ function Remove-Label { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}/label?name={1}" + $resourceApi = "$ApiUri/content/{0}/label?name={1}" } PROCESS { @@ -41,17 +46,15 @@ function Remove-Label { Throw $exception } - $iwParameters = @{ - Uri = "" - Method = 'Delete' - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Delete' foreach ($_page in $PageID) { $_labels = $Label if (!$_labels) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Collecting all Labels for page $_page" - $allLabels = Get-Label -PageID $_page -ApiURi $apiURi -Credential $Credential + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" + $allLabels = Get-Label -PageID $_page @authAndApiUri if ($allLabels.Labels) { $_labels = $allLabels.Labels | Select-Object -ExpandProperty Name } @@ -61,7 +64,7 @@ function Remove-Label { foreach ($_label in $_labels) { $iwParameters["Uri"] = $resourceApi -f $_page, $_label - If ($PSCmdlet.ShouldProcess("Label $_label, PageID $_page")) { + if ($PSCmdlet.ShouldProcess("Label $_label, PageID $_page")) { Invoke-Method @iwParameters } } diff --git a/docs/en-US/commands/Remove-Label.md b/docs/en-US/commands/Remove-Label.md index 07095a6..505c43e 100644 --- a/docs/en-US/commands/Remove-Label.md +++ b/docs/en-US/commands/Remove-Label.md @@ -16,7 +16,7 @@ Remove a label from existing Confluence content. ## SYNTAX ```powershell -Remove-ConfluenceLabel -apiURi -Credential [-PageID] [-Label ] [-WhatIf] [-Confirm] +Remove-ConfluenceLabel -ApiUri -Credential [-PageID] [-Label ] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -57,7 +57,7 @@ For all wiki pages immediately below page 123456, remove all labels from each pa ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -84,7 +84,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 9cbaacde17f95aacd23076a35c731433bda0696f Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:31:36 -0500 Subject: [PATCH 15/23] Add Support for Certificate and Annoymous Auth to Remove-Page Remove-Page.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Remove-Page.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Remove-Page.ps1 | 18 ++++++++++-------- docs/en-US/commands/Remove-Page.md | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ConfluencePS/Public/Remove-Page.ps1 b/ConfluencePS/Public/Remove-Page.ps1 index c243d99..1d5a7bc 100644 --- a/ConfluencePS/Public/Remove-Page.ps1 +++ b/ConfluencePS/Public/Remove-Page.ps1 @@ -6,11 +6,16 @@ function Remove-Page { [OutputType([Bool])] 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, @@ -25,7 +30,7 @@ function Remove-Page { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}" + $resourceApi = "$ApiUri/content/{0}" } PROCESS { @@ -38,11 +43,8 @@ function Remove-Page { Throw $exception } - $iwParameters = @{ - Uri = "" - Method = 'Delete' - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Delete' foreach ($_page in $PageID) { $iwParameters["Uri"] = $resourceApi -f $_page diff --git a/docs/en-US/commands/Remove-Page.md b/docs/en-US/commands/Remove-Page.md index 4e3bf9a..fe6958e 100644 --- a/docs/en-US/commands/Remove-Page.md +++ b/docs/en-US/commands/Remove-Page.md @@ -16,7 +16,7 @@ Trash an existing Confluence page. ## SYNTAX ```powershell -Remove-ConfluencePage -apiURi -Credential [-PageID] [-WhatIf] [-Confirm] +Remove-ConfluencePage -ApiUri -Credential [-PageID] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -57,7 +57,7 @@ For all wiki pages with the label "deleteMe" applied, trash each page. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -84,7 +84,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 0bb58409327fae7105b7eab450f1fd8dfac78dc8 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:32:31 -0500 Subject: [PATCH 16/23] Add Support for Certificate and Annoymous Auth to Remove-Space Remove-Space.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Remove-Space.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Remove-Space.ps1 | 18 ++++++++++-------- docs/en-US/commands/Remove-Space.md | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ConfluencePS/Public/Remove-Space.ps1 b/ConfluencePS/Public/Remove-Space.ps1 index dcfa284..dac66e6 100644 --- a/ConfluencePS/Public/Remove-Space.ps1 +++ b/ConfluencePS/Public/Remove-Space.ps1 @@ -7,11 +7,16 @@ function Remove-Space { [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssignments', '')] 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, @@ -29,7 +34,7 @@ function Remove-Space { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/space/{0}" + $resourceApi = "$ApiUri/space/{0}" if ($Force) { Write-Debug "[$($MyInvocation.MyCommand.Name)] -Force was passed. Backing up current ConfirmPreference [$ConfirmPreference] and setting to None" @@ -48,11 +53,8 @@ function Remove-Space { Throw $exception } - $iwParameters = @{ - Uri = "" - Method = 'Delete' - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Delete' foreach ($_space in $SpaceKey) { $iwParameters["Uri"] = $resourceApi -f $_space diff --git a/docs/en-US/commands/Remove-Space.md b/docs/en-US/commands/Remove-Space.md index a70f1bf..612bf10 100644 --- a/docs/en-US/commands/Remove-Space.md +++ b/docs/en-US/commands/Remove-Space.md @@ -16,7 +16,7 @@ Remove an existing Confluence space. ## SYNTAX ```powershell -Remove-ConfluenceSpace -apiURi -Credential [-SpaceKey] [-Force] [-WhatIf] [-Confirm] +Remove-ConfluenceSpace -ApiUri -Credential [-SpaceKey] [-Force] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -49,7 +49,7 @@ By default, you will be prompted to confirm removal. ("Are you sure? Y/N") ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -76,7 +76,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 99566c2faeacd0d115c5365144b14de173f859d8 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:33:47 -0500 Subject: [PATCH 17/23] Add Support for Certificate and Annoymous Auth to Set-Attachment Set-Attachment.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Set-Attachment.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Set-Attachment.ps1 | 25 ++++++++++++++----------- docs/en-US/commands/Set-Attachment.md | 22 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ConfluencePS/Public/Set-Attachment.ps1 b/ConfluencePS/Public/Set-Attachment.ps1 index 4bfc601..19d90d4 100644 --- a/ConfluencePS/Public/Set-Attachment.ps1 +++ b/ConfluencePS/Public/Set-Attachment.ps1 @@ -6,11 +6,16 @@ function Set-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, @@ -43,21 +48,19 @@ function Set-Attachment { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}/child/attachment/{1}/data" + $resourceApi = "$ApiUri/content/{0}/child/attachment/{1}/data" } PROCESS { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" - $parameter = @{ - URI = $resourceApi -f $Attachment.PageID, $Attachment.ID - Method = "POST" - InFile = $FilePath - Credential = $Credential - OutputType = [ConfluencePS.Attachment] - Verbose = $false - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Uri'] = $resourceApi -f $Attachment.PageID, $Attachment.ID + $iwParameters['Method'] = 'Post' + $iwParameters['InFile'] = $FilePath + $iwParameters['OutputType'] = [ConfluencePS.Attachment] + Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking Set Attachment Method with `$parameter" if ($PSCmdlet.ShouldProcess($Attachment.PageID, "Updating attachment '$($Attachment.Title)'.")) { Invoke-Method @parameter diff --git a/docs/en-US/commands/Set-Attachment.md b/docs/en-US/commands/Set-Attachment.md index c4d99f0..938b020 100644 --- a/docs/en-US/commands/Set-Attachment.md +++ b/docs/en-US/commands/Set-Attachment.md @@ -16,7 +16,7 @@ Updates an existing attachment with a new file. ## SYNTAX ```powershell -Set-Attachment -apiURi -Credential [-Attachment] -FilePath [-WhatIf] [-Confirm] +Set-Attachment -ApiUri -Credential [-Attachment] -FilePath [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -45,7 +45,7 @@ Would replace the attachment test.png to the page with ID 123456. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -72,7 +72,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 4a457888e7c3749671150d4ee92924bdae7009e2 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:35:07 -0500 Subject: [PATCH 18/23] Add Support for Certificate and Annoymous Auth to Set-Label Set-Label.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Set-Label.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Set-Label.ps1 | 28 +++++++++++++++------------- docs/en-US/commands/Set-Label.md | 22 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ConfluencePS/Public/Set-Label.ps1 b/ConfluencePS/Public/Set-Label.ps1 index 090ccaa..b1a6fbc 100644 --- a/ConfluencePS/Public/Set-Label.ps1 +++ b/ConfluencePS/Public/Set-Label.ps1 @@ -6,11 +6,16 @@ function Set-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, Mandatory = $true, @@ -28,7 +33,7 @@ function Set-Label { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}/label" + $resourceApi = "$ApiUri/content/{0}/label" } PROCESS { @@ -41,30 +46,27 @@ function Set-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] + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" foreach ($_page in $PageID) { if ($_ -is [ConfluencePS.Page]) { $InputObject = $_ } else { - $InputObject = Get-Page -PageID $_page -ApiURi $apiURi -Credential $Credential + $InputObject = Get-Page -PageID $_page @authAndApiUri } Write-Verbose "[$($MyInvocation.MyCommand.Name)] Removing all previous labels" - Remove-Label -PageID $_page -ApiURi $apiURi -Credential $Credential | Out-Null + Remove-Label -PageID $_page @authAndApiUri | Out-Null $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 diff --git a/docs/en-US/commands/Set-Label.md b/docs/en-US/commands/Set-Label.md index 2f927ec..06d8ec7 100644 --- a/docs/en-US/commands/Set-Label.md +++ b/docs/en-US/commands/Set-Label.md @@ -16,7 +16,7 @@ Set the labels applied to existing Confluence content. ## SYNTAX ```powershell -Set-Label -apiURi -Credential [-PageID] -Label [-WhatIf] [-Confirm] +Set-Label -ApiUri -Credential [-PageID] -Label [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -48,7 +48,7 @@ Would remove all labels and apply only the label "123" to all pages in the ABC s ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -75,7 +75,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From 5eeaad8a33f083f6e843ae2d2a1bd81a5870fd42 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:43:01 -0500 Subject: [PATCH 19/23] Add Support for Certificate and Annoymous Auth to Set-Page Set-Page.ps1 -Added Certificate Parameter -Made Credential Parameter not mandatory -Rename $ApiUri to have proper casing. -Simplified the propagating of the the splatted parameters. Set-Page.md -Added Certificate Parameter -Made Credential Parameter not mandatory --- ConfluencePS/Public/Set-Page.ps1 | 29 ++++++++++++++++------------- docs/en-US/commands/Set-Page.md | 24 ++++++++++++++++++++---- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/ConfluencePS/Public/Set-Page.ps1 b/ConfluencePS/Public/Set-Page.ps1 index 7818f60..78acd87 100644 --- a/ConfluencePS/Public/Set-Page.ps1 +++ b/ConfluencePS/Public/Set-Page.ps1 @@ -7,11 +7,16 @@ function Set-Page { [OutputType([ConfluencePS.Page])] 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( Mandatory = $true, ValueFromPipeline = $true, @@ -49,12 +54,13 @@ function Set-Page { BEGIN { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" - $resourceApi = "$apiURi/content/{0}" + $resourceApi = "$ApiUri/content/{0}" + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" # If -Convert is flagged, call ConvertTo-ConfluenceStorageFormat against the -Body - If ($Convert) { + if ($Convert) { Write-Verbose '[$($MyInvocation.MyCommand.Name)] -Convert flag active; converting content to Confluence storage format' - $Body = ConvertTo-StorageFormat -Content $Body -ApiURi $apiURi -Credential $Credential + $Body = ConvertTo-StorageFormat -Content $Body @authAndApiUri } } @@ -62,13 +68,10 @@ function Set-Page { Write-Debug "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" - $iwParameters = @{ - Uri = "" - Method = 'Put' - Body = "" - OutputType = [ConfluencePS.Page] - Credential = $Credential - } + $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters + $iwParameters['Method'] = 'Put' + $iwParameters['OutputType'] = [ConfluencePS.Page] + $Content = [PSObject]@{ type = "page" title = "" @@ -96,7 +99,7 @@ function Set-Page { } "byParameters" { $iwParameters["Uri"] = $resourceApi -f $PageID - $originalPage = Get-Page -PageID $PageID -ApiURi $apiURi -Credential $Credential + $originalPage = Get-Page -PageID $PageID @authAndApiUri if (($Parent -is [ConfluencePS.Page]) -and ($Parent.ID)) { $ParentID = $Parent.ID diff --git a/docs/en-US/commands/Set-Page.md b/docs/en-US/commands/Set-Page.md index e7361c4..c27c300 100644 --- a/docs/en-US/commands/Set-Page.md +++ b/docs/en-US/commands/Set-Page.md @@ -18,13 +18,13 @@ Edit an existing Confluence page. ### byParameters (Default) ```powershell -Set-ConfluencePage -apiURi -Credential -PageID [-Title ] [-Body ] [-Convert] [-ParentID ] [-Parent ] [-WhatIf] [-Confirm] +Set-ConfluencePage -ApiUri -Credential -PageID [-Title ] [-Body ] [-Convert] [-ParentID ] [-Parent ] [-WhatIf] [-Confirm] ``` ### byObject ```powershell -Set-ConfluencePage -apiURi -Credential -InputObject [-WhatIf] [-Confirm] +Set-ConfluencePage -ApiUri -Credential -InputObject [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -77,7 +77,7 @@ object. ## PARAMETERS -### -apiURi +### -ApiUri The URi of the API interface. Value can be set persistently with Set-ConfluenceInfo. @@ -104,7 +104,23 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +Certificate for authentication. + +```yaml +Type: X509Certificate +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False From d47ed30fc1c3de6ba64a45493287e68589c2358f Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Sun, 10 Feb 2019 22:45:34 -0500 Subject: [PATCH 20/23] Fixed casing on 'ApiUri' and '[uri]' --- ConfluencePS/Public/Get-ChildPage.ps1 | 2 +- ConfluencePS/Public/Invoke-Method.ps1 | 2 +- ConfluencePS/Public/Set-Info.ps1 | 4 ++-- Tests/Help.Tests.ps1 | 2 +- Tests/Integration.Tests.ps1 | 8 ++++---- Tools/BuildTools.psm1 | 2 +- docs/en-US/commands/Get-ChildPage.md | 2 +- docs/en-US/commands/Get-Page.md | 10 +++++----- docs/en-US/commands/Set-Info.md | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ConfluencePS/Public/Get-ChildPage.ps1 b/ConfluencePS/Public/Get-ChildPage.ps1 index bfa1cb8..fbbaa35 100644 --- a/ConfluencePS/Public/Get-ChildPage.ps1 +++ b/ConfluencePS/Public/Get-ChildPage.ps1 @@ -3,7 +3,7 @@ function Get-ChildPage { [OutputType([ConfluencePS.Page])] param ( [Parameter( Mandatory = $true )] - [URi]$ApiUri, + [uri]$ApiUri, [Parameter( Mandatory = $false )] [PSCredential]$Credential, diff --git a/ConfluencePS/Public/Invoke-Method.ps1 b/ConfluencePS/Public/Invoke-Method.ps1 index 62bcf4c..f360f4b 100644 --- a/ConfluencePS/Public/Invoke-Method.ps1 +++ b/ConfluencePS/Public/Invoke-Method.ps1 @@ -13,7 +13,7 @@ function Invoke-Method { [Diagnostics.CodeAnalysis.SuppressMessageAttribute( "PSAvoidUsingEmptyCatchBlock", "" )] param ( [Parameter(Mandatory = $true)] - [Uri]$Uri, + [uri]$Uri, [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = "GET", diff --git a/ConfluencePS/Public/Set-Info.ps1 b/ConfluencePS/Public/Set-Info.ps1 index 36be80f..8a34bc0 100644 --- a/ConfluencePS/Public/Set-Info.ps1 +++ b/ConfluencePS/Public/Set-Info.ps1 @@ -5,7 +5,7 @@ function Set-Info { [Parameter( HelpMessage = 'Example = https://brianbunke.atlassian.net/wiki (/wiki for Cloud instances)' )] - [Uri]$BaseURi, + [uri]$BaseURi, [PSCredential]$Credential, @@ -48,7 +48,7 @@ function Set-Info { PROCESS { foreach ($command in $moduleCommands) { - $parameter = "ApiURi" + $parameter = "ApiUri" if ($BaseURi -and ($command.Parameters.Keys -contains $parameter)) { Add-ConfluenceDefaultParameter -Command $command -Parameter $parameter -Value ($BaseURi.AbsoluteUri.TrimEnd('/') + '/rest/api') } diff --git a/Tests/Help.Tests.ps1 b/Tests/Help.Tests.ps1 index fc8af97..5c5d41f 100644 --- a/Tests/Help.Tests.ps1 +++ b/Tests/Help.Tests.ps1 @@ -83,7 +83,7 @@ Describe "Help tests" -Tag Documentation { } It "has a link to the 'Online Version'" { - [Uri]$onlineLink = ($help.relatedLinks.navigationLink | Where-Object linkText -eq "Online Version:").Uri + [uri]$onlineLink = ($help.relatedLinks.navigationLink | Where-Object linkText -eq "Online Version:").Uri $onlineLink.Authority | Should -Be "atlassianps.org" $onlineLink.Scheme | Should -Be "https" diff --git a/Tests/Integration.Tests.ps1 b/Tests/Integration.Tests.ps1 index ecbf615..6970b26 100644 --- a/Tests/Integration.Tests.ps1 +++ b/Tests/Integration.Tests.ps1 @@ -64,8 +64,8 @@ Describe 'Integration Tests' -Tag Integration { #TODO: extend this } It 'url is stored' { - $global:PSDefaultParameterValues["Get-ConfluencePage:ApiURi"] | Should BeOfType [String] - $global:PSDefaultParameterValues["Get-ConfluencePage:ApiURi"] -match "^https?://.*\/rest\/api$" | Should Be $true + $global:PSDefaultParameterValues["Get-ConfluencePage:ApiUri"] | Should BeOfType [String] + $global:PSDefaultParameterValues["Get-ConfluencePage:ApiUri"] -match "^https?://.*\/rest\/api$" | Should Be $true } } @@ -862,7 +862,7 @@ Describe 'Integration Tests' -Tag Integration { $result1.Version | Should BeOfType [ConfluencePS.Version] $result1.Version.Number | Should Be 1 $result1.URL | Should Not BeNullOrEmpty - ([Uri]$result1.URL).AbsoluteUri | Should Not BeNullOrEmpty + ([uri]$result1.URL).AbsoluteUri | Should Not BeNullOrEmpty } It 'throws if the file does not exist' { { Add-ConfluenceAttachment -PageId $Page1.Id -FilePath "$PSScriptRoot/non-existing.file" } | Should Throw @@ -1016,7 +1016,7 @@ Describe 'Integration Tests' -Tag Integration { $result1.SpaceKey | Should Not BeNullOrEmpty $result1.PageID | Should Not BeNullOrEmpty $result1.URL | Should Not BeNullOrEmpty - ([Uri]$result1.URL).AbsoluteUri | Should Not BeNullOrEmpty + ([uri]$result1.URL).AbsoluteUri | Should Not BeNullOrEmpty } It 'throws if the file does not exist' { { Set-ConfluenceAttachment -Attachment $Attachment -FilePath "non-existing.file" } | Should Throw diff --git a/Tools/BuildTools.psm1 b/Tools/BuildTools.psm1 index 5cf3c3d..3917eb0 100644 --- a/Tools/BuildTools.psm1 +++ b/Tools/BuildTools.psm1 @@ -180,7 +180,7 @@ function Publish-GithubReleaseArtifact { [Parameter( Mandatory )] [ValidateNotNullOrEmpty()] [String]$GITHUB_ACCESS_TOKEN, - [Uri]$Uri, + [uri]$Uri, [String]$Path ) diff --git a/docs/en-US/commands/Get-ChildPage.md b/docs/en-US/commands/Get-ChildPage.md index 6b7cce2..da12dc3 100644 --- a/docs/en-US/commands/Get-ChildPage.md +++ b/docs/en-US/commands/Get-ChildPage.md @@ -16,7 +16,7 @@ Retrieve the child pages of a given wiki page or pages. ## SYNTAX ```powershell -Get-ConfluenceChildPage -apiURi -Credential [-PageID] [-Recurse] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluenceChildPage -ApiUri -Credential [-PageID] [-Recurse] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ## DESCRIPTION diff --git a/docs/en-US/commands/Get-Page.md b/docs/en-US/commands/Get-Page.md index 0167cc6..337e22e 100644 --- a/docs/en-US/commands/Get-Page.md +++ b/docs/en-US/commands/Get-Page.md @@ -18,31 +18,31 @@ Retrieve a listing of pages in your Confluence instance. ### byId (Default) ```powershell -Get-ConfluencePage -ApiURi -Credential [-PageID] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluencePage -ApiUri -Credential [-PageID] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ### byLabel ```powershell -Get-ConfluencePage -ApiURi -Credential [-SpaceKey ] [-Space ] -Label [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluencePage -ApiUri -Credential [-SpaceKey ] [-Space ] -Label [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ### bySpace ```powershell -Get-ConfluencePage -ApiURi -Credential -SpaceKey [-Title ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluencePage -ApiUri -Credential -SpaceKey [-Title ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ### byQuery ```powershell -Get-ConfluencePage -ApiURi -Credential [-Query ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluencePage -ApiUri -Credential [-Query ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ### bySpaceObject ```powershell -Get-ConfluencePage -ApiURi -Credential -Space [-Title ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] +Get-ConfluencePage -ApiUri -Credential -Space [-Title ] [-PageSize ] [-IncludeTotalCount] [-Skip ] [-First ] ``` ## DESCRIPTION diff --git a/docs/en-US/commands/Set-Info.md b/docs/en-US/commands/Set-Info.md index 3a6d92e..5f3ef2b 100644 --- a/docs/en-US/commands/Set-Info.md +++ b/docs/en-US/commands/Set-Info.md @@ -24,7 +24,7 @@ Set-ConfluenceInfo [[-BaseURi] ] [[-Credential] ] [[-PageSize Set-ConfluenceInfo uses scoped variables and PSDefaultParameterValues to supply URI/auth info to all other functions in the module (e.g. Get-ConfluenceSpace). These session defaults can be overwritten on any single command, but using -Set-ConfluenceInfo avoids repetitively specifying -ApiURi and -Credential parameters. +Set-ConfluenceInfo avoids repetitively specifying -ApiUri and -Credential parameters. Confluence's REST API supports passing basic authentication in headers. (If you have a better suggestion for how to handle auth, please reach out on GitHub!) From bea5ee8f76f09cb04210d56ee2d88e887ce0fc2f Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Mon, 11 Feb 2019 07:52:26 -0500 Subject: [PATCH 21/23] Missing update of variable rename --- ConfluencePS/Public/Set-Attachment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfluencePS/Public/Set-Attachment.ps1 b/ConfluencePS/Public/Set-Attachment.ps1 index 19d90d4..9eee718 100644 --- a/ConfluencePS/Public/Set-Attachment.ps1 +++ b/ConfluencePS/Public/Set-Attachment.ps1 @@ -63,7 +63,7 @@ function Set-Attachment { Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking Set Attachment Method with `$parameter" if ($PSCmdlet.ShouldProcess($Attachment.PageID, "Updating attachment '$($Attachment.Title)'.")) { - Invoke-Method @parameter + Invoke-Method @iwParameters } } From c2536e800ac225a48555d62f048ca269ec84af2c Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Thu, 21 Feb 2019 20:51:17 -0500 Subject: [PATCH 22/23] Fixes for PR comments --- ConfluencePS/Private/Copy-CommonParameter.ps1 | 20 ++++++++++++++++++- ConfluencePS/Public/Get-ChildPage.ps1 | 12 +++++------ ConfluencePS/Public/New-Page.ps1 | 5 +++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ConfluencePS/Private/Copy-CommonParameter.ps1 b/ConfluencePS/Private/Copy-CommonParameter.ps1 index 83429f5..7ef810b 100644 --- a/ConfluencePS/Private/Copy-CommonParameter.ps1 +++ b/ConfluencePS/Private/Copy-CommonParameter.ps1 @@ -1,10 +1,28 @@ 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] )] - #[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] param ( [Parameter(Mandatory = $true)] diff --git a/ConfluencePS/Public/Get-ChildPage.ps1 b/ConfluencePS/Public/Get-ChildPage.ps1 index fbbaa35..c1aef2d 100644 --- a/ConfluencePS/Public/Get-ChildPage.ps1 +++ b/ConfluencePS/Public/Get-ChildPage.ps1 @@ -53,13 +53,13 @@ function Get-ChildPage { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = if ($Recurse.IsPresent) {"$ApiUri/content/{0}/descendant/page" -f $PageID} else {"$ApiUri/content/{0}/child/page" -f $PageID} - $iwParameters['Method'] = 'Get' + $iwParameters['Uri'] = if ($Recurse.IsPresent) {"$ApiUri/content/{0}/descendant/page" -f $PageID} else {"$ApiUri/content/{0}/child/page" -f $PageID} + $iwParameters['Method'] = 'Get' $iwParameters['GetParameters'] = @{ - expand = "space,version,body.storage,ancestors" - limit = $PageSize - } - $iwParameters['OutputType'] = [ConfluencePS.Page] + expand = "space,version,body.storage,ancestors" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Page] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { diff --git a/ConfluencePS/Public/New-Page.ps1 b/ConfluencePS/Public/New-Page.ps1 index 17caeb7..fb2fa62 100644 --- a/ConfluencePS/Public/New-Page.ps1 +++ b/ConfluencePS/Public/New-Page.ps1 @@ -54,6 +54,9 @@ function New-Page { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" $resourceApi = "$ApiUri/content" + + #this is the splat hashtable that passes the auth and uri to calls but not Invoke-Method, i.e. Get-Page + $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" } PROCESS { @@ -96,14 +99,12 @@ function New-Page { if (($ParentID) -and !($SpaceKey)) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] SpaceKey not specified. Retrieving from Get-ConfluencePage -PageID $ParentID" - $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" $SpaceKey = (Get-Page -PageID $ParentID @authAndApiUri).Space.Key } # If -Convert is flagged, call ConvertTo-ConfluenceStorageFormat against the -Body if ($Convert) { Write-Verbose '[$($MyInvocation.MyCommand.Name)] -Convert flag active; converting content to Confluence storage format' - $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" $Body = ConvertTo-StorageFormat -Content $Body @authAndApiUri } From 9fd7a16c4e284505b0e6bce37ca9ccd0e01747b7 Mon Sep 17 00:00:00 2001 From: ritzcrackr Date: Fri, 22 Feb 2019 08:22:27 -0500 Subject: [PATCH 23/23] Applied formatting --- ConfluencePS/Private/Copy-CommonParameter.ps1 | 9 +++------ ConfluencePS/Public/Add-Attachment.ps1 | 6 +++--- ConfluencePS/Public/Add-Label.ps1 | 4 ++-- ConfluencePS/Public/ConvertTo-StorageFormat.ps1 | 10 +++++----- ConfluencePS/Public/ConvertTo-Table.ps1 | 13 +++++++------ ConfluencePS/Public/Get-Attachment.ps1 | 10 +++++----- ConfluencePS/Public/Get-Label.ps1 | 8 ++++---- ConfluencePS/Public/Get-Page.ps1 | 9 +++++---- ConfluencePS/Public/Get-Space.ps1 | 10 +++++----- ConfluencePS/Public/Invoke-Method.ps1 | 8 ++++---- ConfluencePS/Public/New-Page.ps1 | 6 +++--- ConfluencePS/Public/New-Space.ps1 | 6 +++--- ConfluencePS/Public/Set-Attachment.ps1 | 6 +++--- ConfluencePS/Public/Set-Label.ps1 | 4 ++-- ConfluencePS/Public/Set-Page.ps1 | 2 +- 15 files changed, 55 insertions(+), 56 deletions(-) diff --git a/ConfluencePS/Private/Copy-CommonParameter.ps1 b/ConfluencePS/Private/Copy-CommonParameter.ps1 index 7ef810b..6a825e1 100644 --- a/ConfluencePS/Private/Copy-CommonParameter.ps1 +++ b/ConfluencePS/Private/Copy-CommonParameter.ps1 @@ -1,5 +1,4 @@ -function Copy-CommonParameter -{ +function Copy-CommonParameter { <# .SYNOPSIS This is a helper function to assist in creating a hashtable for splatting parameters to inner function calls. @@ -36,10 +35,8 @@ function Copy-CommonParameter ) [hashtable]$ht = @{} - foreach($key in $InputObject.Keys) - { - if ($key -in ($DefaultParameter + $AdditionalParameter)) - { + foreach ($key in $InputObject.Keys) { + if ($key -in ($DefaultParameter + $AdditionalParameter)) { $ht[$key] = $InputObject[$key] } } diff --git a/ConfluencePS/Public/Add-Attachment.ps1 b/ConfluencePS/Public/Add-Attachment.ps1 index 05af08a..fc234d0 100644 --- a/ConfluencePS/Public/Add-Attachment.ps1 +++ b/ConfluencePS/Public/Add-Attachment.ps1 @@ -58,9 +58,9 @@ function Add-Attachment { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $PageID - $iwParameters['Method'] = 'Post' - $iwParameters['OutputType'] = [ConfluencePS.Attachment] + $iwParameters['Uri'] = "$ApiUri/content/{0}/child/attachment" -f $PageID + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Attachment] foreach ($file in $FilePath) { $iwParameters["InFile"] = $file diff --git a/ConfluencePS/Public/Add-Label.ps1 b/ConfluencePS/Public/Add-Label.ps1 index c3c31cc..27e60cd 100644 --- a/ConfluencePS/Public/Add-Label.ps1 +++ b/ConfluencePS/Public/Add-Label.ps1 @@ -77,8 +77,8 @@ function Add-Label { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Post' - $iwParameters['OutputType'] = [ConfluencePS.Label] + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Label] # Extract name if an Object is provided if (($Label -is [ConfluencePS.Label]) -or $Label -is [ConfluencePS.Label[]]) { diff --git a/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 b/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 index c450ca5..7931ef3 100644 --- a/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 +++ b/ConfluencePS/Public/ConvertTo-StorageFormat.ps1 @@ -30,14 +30,14 @@ function ConvertTo-StorageFormat { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = "$ApiUri/contentbody/convert/storage" - $iwParameters['Method'] = 'Post' + $iwParameters['Uri'] = "$ApiUri/contentbody/convert/storage" + $iwParameters['Method'] = 'Post' foreach ($_content in $Content) { $iwParameters['Body'] = @{ - value = "$_content" - representation = 'wiki' - } | ConvertTo-Json + value = "$_content" + representation = 'wiki' + } | ConvertTo-Json Write-Debug "[$($MyInvocation.MyCommand.Name)] Content to be sent: $($_content | Out-String)" (Invoke-Method @iwParameters).value diff --git a/ConfluencePS/Public/ConvertTo-Table.ps1 b/ConfluencePS/Public/ConvertTo-Table.ps1 index c415460..5771872 100644 --- a/ConfluencePS/Public/ConvertTo-Table.ps1 +++ b/ConfluencePS/Public/ConvertTo-Table.ps1 @@ -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('') } @@ -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 } diff --git a/ConfluencePS/Public/Get-Attachment.ps1 b/ConfluencePS/Public/Get-Attachment.ps1 index 28dbb8e..e98605d 100644 --- a/ConfluencePS/Public/Get-Attachment.ps1 +++ b/ConfluencePS/Public/Get-Attachment.ps1 @@ -46,12 +46,12 @@ function Get-Attachment { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Get' + $iwParameters['Method'] = 'Get' $iwParameters['GetParameters'] = @{ - expand = "version" - limit = $PageSize - } - $iwParameters['OutputType'] = [ConfluencePS.Attachment] + expand = "version" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Attachment] if ($FileNameFilter) { $iwParameters["GetParameters"]["filename"] = $FileNameFilter diff --git a/ConfluencePS/Public/Get-Label.ps1 b/ConfluencePS/Public/Get-Label.ps1 index 4f8f7d1..99e6398 100644 --- a/ConfluencePS/Public/Get-Label.ps1 +++ b/ConfluencePS/Public/Get-Label.ps1 @@ -46,11 +46,11 @@ function Get-Label { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Get' + $iwParameters['Method'] = 'Get' $iwParameters['GetParameters'] = @{ - limit = $PageSize - } - $iwParameters['OutputType'] = [ConfluencePS.Label] + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Label] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { diff --git a/ConfluencePS/Public/Get-Page.ps1 b/ConfluencePS/Public/Get-Page.ps1 index 0c4d3bb..cc5c02a 100644 --- a/ConfluencePS/Public/Get-Page.ps1 +++ b/ConfluencePS/Public/Get-Page.ps1 @@ -84,9 +84,9 @@ function Get-Page { $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters $iwParameters['Method'] = 'Get' $iwParameters['GetParameters'] = @{ - expand = "space,version,body.storage,ancestors" - limit = $PageSize - } + expand = "space,version,body.storage,ancestors" + limit = $PageSize + } $iwParameters['OutputType'] = [ConfluencePS.Page] } @@ -112,7 +112,8 @@ function Get-Page { } break } - "bySpace" { # This includes 'bySpaceObject' + "bySpace" { + # This includes 'bySpaceObject' $iwParameters["Uri"] = $resourceApi -f '' $iwParameters["GetParameters"]["type"] = "page" if ($SpaceKey) { $iwParameters["GetParameters"]["spaceKey"] = $SpaceKey } diff --git a/ConfluencePS/Public/Get-Space.ps1 b/ConfluencePS/Public/Get-Space.ps1 index 7287302..a4b9f48 100644 --- a/ConfluencePS/Public/Get-Space.ps1 +++ b/ConfluencePS/Public/Get-Space.ps1 @@ -36,12 +36,12 @@ function Get-Space { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Get' + $iwParameters['Method'] = 'Get' $iwParameters['GetParameters'] = @{ - expand = "description.plain,icon,homepage,metadata.labels" - limit = $PageSize - } - $iwParameters['OutputType'] = [ConfluencePS.Space] + expand = "description.plain,icon,homepage,metadata.labels" + limit = $PageSize + } + $iwParameters['OutputType'] = [ConfluencePS.Space] # Paging ($PSCmdlet.PagingParameters | Get-Member -MemberType Property).Name | ForEach-Object { diff --git a/ConfluencePS/Public/Invoke-Method.ps1 b/ConfluencePS/Public/Invoke-Method.ps1 index f360f4b..4fb0447 100644 --- a/ConfluencePS/Public/Invoke-Method.ps1 +++ b/ConfluencePS/Public/Invoke-Method.ps1 @@ -80,11 +80,11 @@ function Invoke-Method { $PSDefaultParameterValues = $global:PSDefaultParameterValues $splatParameters = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter @("Uri", "Method", "InFile", "OutFile") - $splatParameters['Headers'] = $_headers - $splatParameters['ContentType'] = "application/json; charset=utf-8" + $splatParameters['Headers'] = $_headers + $splatParameters['ContentType'] = "application/json; charset=utf-8" $splatParameters['UseBasicParsing'] = $true - $splatParameters['ErrorAction'] = 'Stop' - $splatParameters['Verbose'] = $false # Overwrites verbose output + $splatParameters['ErrorAction'] = 'Stop' + $splatParameters['Verbose'] = $false # Overwrites verbose output #add 'start' query parameter if Paging with Skip is being used if (($PSCmdlet.PagingParameters) -and ($PSCmdlet.PagingParameters.Skip)) { diff --git a/ConfluencePS/Public/New-Page.ps1 b/ConfluencePS/Public/New-Page.ps1 index fb2fa62..9339ce0 100644 --- a/ConfluencePS/Public/New-Page.ps1 +++ b/ConfluencePS/Public/New-Page.ps1 @@ -64,9 +64,9 @@ function New-Page { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = $resourceApi - $iwParameters['Method'] = 'Post' - $iwParameters['OutputType'] = [ConfluencePS.Page] + $iwParameters['Uri'] = $resourceApi + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Page] $Content = [PSObject]@{ type = "page" diff --git a/ConfluencePS/Public/New-Space.ps1 b/ConfluencePS/Public/New-Space.ps1 index 8a485c4..12af165 100644 --- a/ConfluencePS/Public/New-Space.ps1 +++ b/ConfluencePS/Public/New-Space.ps1 @@ -60,9 +60,9 @@ function New-Space { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = $resourceApi - $iwParameters['Method'] = 'Post' - $iwParameters['OutputType'] = [ConfluencePS.Space] + $iwParameters['Uri'] = $resourceApi + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Space] $Body = @{ key = $SpaceKey diff --git a/ConfluencePS/Public/Set-Attachment.ps1 b/ConfluencePS/Public/Set-Attachment.ps1 index 9eee718..0b733bf 100644 --- a/ConfluencePS/Public/Set-Attachment.ps1 +++ b/ConfluencePS/Public/Set-Attachment.ps1 @@ -56,9 +56,9 @@ function Set-Attachment { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Uri'] = $resourceApi -f $Attachment.PageID, $Attachment.ID - $iwParameters['Method'] = 'Post' - $iwParameters['InFile'] = $FilePath + $iwParameters['Uri'] = $resourceApi -f $Attachment.PageID, $Attachment.ID + $iwParameters['Method'] = 'Post' + $iwParameters['InFile'] = $FilePath $iwParameters['OutputType'] = [ConfluencePS.Attachment] Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking Set Attachment Method with `$parameter" diff --git a/ConfluencePS/Public/Set-Label.ps1 b/ConfluencePS/Public/Set-Label.ps1 index b1a6fbc..f8fec6e 100644 --- a/ConfluencePS/Public/Set-Label.ps1 +++ b/ConfluencePS/Public/Set-Label.ps1 @@ -47,8 +47,8 @@ function Set-Label { } $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Post' - $iwParameters['OutputType'] = [ConfluencePS.Label] + $iwParameters['Method'] = 'Post' + $iwParameters['OutputType'] = [ConfluencePS.Label] $authAndApiUri = Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri" foreach ($_page in $PageID) { diff --git a/ConfluencePS/Public/Set-Page.ps1 b/ConfluencePS/Public/Set-Page.ps1 index 78acd87..d7b3cdd 100644 --- a/ConfluencePS/Public/Set-Page.ps1 +++ b/ConfluencePS/Public/Set-Page.ps1 @@ -69,7 +69,7 @@ function Set-Page { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $iwParameters = Copy-CommonParameter -InputObject $PSBoundParameters - $iwParameters['Method'] = 'Put' + $iwParameters['Method'] = 'Put' $iwParameters['OutputType'] = [ConfluencePS.Page] $Content = [PSObject]@{