Skip to content

Commit

Permalink
Merge pull request #198 from mdg1-uo/master
Browse files Browse the repository at this point in the history
Adding the Personal Access Token to Set-ConfluenceInfo
  • Loading branch information
lipkau authored Jan 11, 2022
2 parents 4492f32 + 78cac87 commit c86f787
Show file tree
Hide file tree
Showing 44 changed files with 611 additions and 99 deletions.
2 changes: 1 addition & 1 deletion ConfluencePS/Private/Copy-CommonParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Copy-CommonParameter {
[string[]]$AdditionalParameter,

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

[hashtable]$ht = @{}
Expand Down
10 changes: 10 additions & 0 deletions ConfluencePS/Private/Invoke-WebRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function Invoke-WebRequest {
[System.Management.Automation.CredentialAttribute()]
${Credential},

[string]
${PersonalAccessToken},

[switch]
${UseDefaultCredentials},

Expand Down Expand Up @@ -101,6 +104,11 @@ function Invoke-WebRequest {
$null = $PSBoundParameters.Remove("Credential")
}

if ($PersonalAccessToken) {
$PSBoundParameters["Headers"]["Authorization"] = "Bearer $PersonalAccessToken"
$null = $PSBoundParameters.Remove("PersonalAccessToken")
}

if ($InFile) {
$boundary = [System.Guid]::NewGuid().ToString()
$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
Expand Down Expand Up @@ -296,6 +304,8 @@ if ($PSVersionTable.PSVersion.Major -ge 6) {
begin {
if ($Credential -and (-not ($Authentication))) {
$PSBoundParameters["Authentication"] = "Basic"
} elseif ($PersonalAccessToken -and (-not ($Authentication))) {
$PSBoundParameters["Authentication"] = "Bearer"
}
if ($InFile) {
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
Expand Down
12 changes: 10 additions & 2 deletions ConfluencePS/Public/Add-Attachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ function Add-Attachment {
[OutputType([ConfluencePS.Attachment])]
param(
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -26,7 +30,11 @@ function Add-Attachment {
[Alias('ID')]
[UInt64]$PageID,

[Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )]
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)]
[ValidateScript(
{
if (-not (Test-Path $_ -PathType Leaf)) {
Expand Down
6 changes: 5 additions & 1 deletion ConfluencePS/Public/Add-Label.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ function Add-Label {
[OutputType([ConfluencePS.ContentLabelSet])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand Down
8 changes: 6 additions & 2 deletions ConfluencePS/Public/ConvertTo-StorageFormat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ function ConvertTo-StorageFormat {
[OutputType([String])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -18,7 +22,7 @@ function ConvertTo-StorageFormat {
Mandatory = $true,
ValueFromPipeline = $true
)]
[string[]]$Content
[String[]]$Content
)

BEGIN {
Expand Down
4 changes: 2 additions & 2 deletions ConfluencePS/Public/ConvertTo-Table.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function ConvertTo-Table {
# This ForEach needed if the content wasn't piped in
$Content | ForEach-Object {
if ($Vertical) {
if ($HeaderGenerated) {$pipe = '|'}
else {$pipe = '||'}
if ($HeaderGenerated) { $pipe = '|' }
else { $pipe = '||' }

# Put an empty row between multiple tables (objects)
if ($Spacer) {
Expand Down
6 changes: 5 additions & 1 deletion ConfluencePS/Public/Get-Attachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ function Get-Attachment {
[OutputType([ConfluencePS.Attachment])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand Down
10 changes: 7 additions & 3 deletions ConfluencePS/Public/Get-AttachmentFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ function Get-AttachmentFile {
[OutputType([Bool])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand Down Expand Up @@ -59,8 +63,8 @@ function Get-AttachmentFile {

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}
$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
10 changes: 7 additions & 3 deletions ConfluencePS/Public/Get-ChildPage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ function Get-ChildPage {
[OutputType([ConfluencePS.Page])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -23,12 +27,12 @@ function Get-ChildPage {
[Alias('ID')]
[UInt64]$PageID,

[switch]$Recurse,
[Switch]$Recurse,

[ValidateRange(1, [UInt32]::MaxValue)]
[UInt32]$PageSize = 25,

[switch]$ExcludePageBody
[Switch]$ExcludePageBody
)

BEGIN {
Expand Down
6 changes: 5 additions & 1 deletion ConfluencePS/Public/Get-Label.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ function Get-Label {
[OutputType([ConfluencePS.ContentLabelSet])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand Down
16 changes: 10 additions & 6 deletions ConfluencePS/Public/Get-Page.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ function Get-Page {
[OutputType([ConfluencePS.Page])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -34,7 +38,7 @@ function Get-Page {
ParameterSetName = "bySpaceObject"
)]
[Alias('Name')]
[string]$Title,
[String]$Title,

[Parameter(
Mandatory = $true,
Expand All @@ -44,7 +48,7 @@ function Get-Page {
ParameterSetName = "byLabel"
)]
[Alias('Key')]
[string]$SpaceKey,
[String]$SpaceKey,

[Parameter(
Mandatory = $true,
Expand All @@ -62,19 +66,19 @@ function Get-Page {
Mandatory = $true,
ParameterSetName = "byLabel"
)]
[string[]]$Label,
[String[]]$Label,

[Parameter(
Position = 0,
Mandatory = $true,
ParameterSetName = "byQuery"
)]
[string]$Query,
[String]$Query,

[ValidateRange(1, [UInt32]::MaxValue)]
[UInt32]$PageSize = 25,

[switch]$ExcludePageBody
[Switch]$ExcludePageBody
)

BEGIN {
Expand Down
8 changes: 6 additions & 2 deletions ConfluencePS/Public/Get-Space.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ function Get-Space {
[OutputType([ConfluencePS.Space])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -19,7 +23,7 @@ function Get-Space {
Position = 0
)]
[Alias('Key')]
[string[]]$SpaceKey,
[String[]]$SpaceKey,

[ValidateRange(1, [UInt32]::MaxValue)]
[UInt32]$PageSize = 25
Expand Down
11 changes: 9 additions & 2 deletions ConfluencePS/Public/Invoke-Method.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ function Invoke-Method {
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( "PSAvoidUsingEmptyCatchBlock", "" )]
param (
[Parameter(Mandatory = $true)]
[uri]$Uri,
[Parameter(
Position = 0,
Mandatory = $true
)]
[Uri]$Uri,

[Microsoft.PowerShell.Commands.WebRequestMethod]$Method = "GET",

Expand Down Expand Up @@ -44,6 +47,10 @@ function Invoke-Method {
[Parameter( Mandatory = $false )]
[PSCredential]$Credential,

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand Down
16 changes: 11 additions & 5 deletions ConfluencePS/Public/New-Page.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ function New-Page {
[OutputType([ConfluencePS.Page])]
param (
[Parameter( Mandatory = $true )]
[uri]$ApiUri,
[Uri]$ApiUri,

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

[Parameter( Mandatory = $false )]
[String]
$PersonalAccessToken,

[Parameter( Mandatory = $false )]
[ValidateNotNull()]
[System.Security.Cryptography.X509Certificates.X509Certificate]
Expand All @@ -30,24 +34,26 @@ function New-Page {
ParameterSetName = 'byParameters'
)]
[Alias('Name')]
[string]$Title,
[String]$Title,

[Parameter(ParameterSetName = 'byParameters')]
[ValidateRange(1, [UInt64]::MaxValue)]
[UInt64]$ParentID,

[Parameter(ParameterSetName = 'byParameters')]
[ConfluencePS.Page]$Parent,

[Parameter(ParameterSetName = 'byParameters')]
[string]$SpaceKey,
[String]$SpaceKey,

[Parameter(ParameterSetName = 'byParameters')]
[ConfluencePS.Space]$Space,

[Parameter(ParameterSetName = 'byParameters')]
[string]$Body,
[String]$Body,

[Parameter(ParameterSetName = 'byParameters')]
[switch]$Convert
[Switch]$Convert
)

BEGIN {
Expand Down
Loading

0 comments on commit c86f787

Please sign in to comment.