Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous and certificate authentication #164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
19a1bc3
Initial Commit to add Certificate and Anonymous Authentication support.
ritzcrackr Feb 10, 2019
f795893
Add Support for Certificate and Annoymous Auth to Get-Page
ritzcrackr Feb 10, 2019
09c9d7f
Add Support for Certificate and Annoymous Auth to Get-ChildPage
ritzcrackr Feb 10, 2019
6d4834c
Add Support for Certificate and Annoymous Auth to Add-Attachment
ritzcrackr Feb 11, 2019
6c1e6df
Add Support for Certificate and Annoymous Auth to Add-Label
ritzcrackr Feb 11, 2019
6b846be
Add Support for Certificate and Annoymous Auth to ConvertTo-StorageFo…
ritzcrackr Feb 11, 2019
32df6eb
Add Support for Certificate and Annoymous Auth to Get-Attachment
ritzcrackr Feb 11, 2019
f8addda
Add Support for Certificate and Annoymous Auth to Get-AttachmentFile
ritzcrackr Feb 11, 2019
c39b066
Add Support for Certificate and Annoymous Auth to Get-Label
ritzcrackr Feb 11, 2019
0cf671d
Add Support for Certificate and Annoymous Auth to Get-Space
ritzcrackr Feb 11, 2019
431fbb9
Add Support for Certificate and Annoymous Auth to New-Page
ritzcrackr Feb 11, 2019
8947377
Add Support for Certificate and Annoymous Auth to New-Space
ritzcrackr Feb 11, 2019
1dc60ab
Add Support for Certificate and Annoymous Auth to Remove-Attachment
ritzcrackr Feb 11, 2019
79f871b
Add Support for Certificate and Annoymous Auth to Remove-Label
ritzcrackr Feb 11, 2019
9cbaacd
Add Support for Certificate and Annoymous Auth to Remove-Page
ritzcrackr Feb 11, 2019
0bb5840
Add Support for Certificate and Annoymous Auth to Remove-Space
ritzcrackr Feb 11, 2019
99566c2
Add Support for Certificate and Annoymous Auth to Set-Attachment
ritzcrackr Feb 11, 2019
4a45788
Add Support for Certificate and Annoymous Auth to Set-Label
ritzcrackr Feb 11, 2019
5eeaad8
Add Support for Certificate and Annoymous Auth to Set-Page
ritzcrackr Feb 11, 2019
d47ed30
Fixed casing on 'ApiUri' and '[uri]'
ritzcrackr Feb 11, 2019
bea5ee8
Missing update of variable rename
ritzcrackr Feb 11, 2019
aa2ff0f
Merge branch 'develop' into AnonymousAndCertificateAuthentication
ritzcrackr Feb 11, 2019
9324d34
Merge branch 'develop' into AnonymousAndCertificateAuthentication
lipkau Feb 21, 2019
c2536e8
Fixes for PR comments
ritzcrackr Feb 22, 2019
9fd7a16
Applied formatting
ritzcrackr Feb 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ConfluencePS/Private/Copy-CommonParameter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Copy-CommonParameter {
<#
.SYNOPSIS
This is a helper function to assist in creating a hashtable for splatting parameters to inner function calls.

.DESCRIPTION
This command copies all of the keys of a hashtable to a new hashtable if the key name matches the DefaultParameter
or the AdditionalParameter values. This function is designed to help select only function parameters that have been
set, so they can be passed to inner functions if and only if they have been set.

.EXAMPLE
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters

Returns a hashtable that contains all of the bound default parameters.

.EXAMPLE
PS C:\> Copy-CommonParameter -InputObject $PSBoundParameters -AdditionalParameter "ApiUri"

Returns a hashtable that contains all of the bound default parameters and the "ApiUri" parameter.
#>
[CmdletBinding( SupportsShouldProcess = $false )]
[OutputType(
[hashtable]
)]
param
(
[Parameter(Mandatory = $true)]
[hashtable]$InputObject,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Invoke-Method @iwParameters
}
Expand Down
29 changes: 13 additions & 16 deletions ConfluencePS/Public/Get-AttachmentFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading