-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from AtlassianPS/develop
- Loading branch information
Showing
19 changed files
with
279 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function Test-ServerResponse { | ||
[CmdletBinding()] | ||
<# | ||
.SYNOPSIS | ||
Evauluate the response of the API call | ||
.LINK | ||
https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/bc/security/login/LoginReason.html | ||
#> | ||
param ( | ||
# Response of Invoke-WebRequest | ||
[Parameter( ValueFromPipeline )] | ||
[PSObject]$InputObject, | ||
|
||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCmdlet] | ||
$Cmdlet = $PSCmdlet | ||
) | ||
|
||
begin { | ||
$loginReasonKey = "X-Seraph-LoginReason" | ||
} | ||
|
||
process { | ||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Checking response headers for authentication errors" | ||
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Investigating `$InputObject.Headers['$loginReasonKey']" | ||
|
||
if ($InputObject.Headers -and $InputObject.Headers[$loginReasonKey]) { | ||
$loginReason = $InputObject.Headers[$loginReasonKey] -split "," | ||
|
||
switch ($true) { | ||
{$loginReason -contains "AUTHENTICATED_FAILED"} { | ||
$errorParameter = @{ | ||
ExceptionType = "System.Net.Http.HttpRequestException" | ||
Message = "The user could not be authenticated." | ||
ErrorId = "AuthenticationFailed" | ||
Category = "AuthenticationError" | ||
Cmdlet = $Cmdlet | ||
} | ||
ThrowError @errorParameter | ||
} | ||
{$loginReason -contains "AUTHENTICATION_DENIED"} { | ||
$errorParameter = @{ | ||
ExceptionType = "System.Net.Http.HttpRequestException" | ||
Message = "For security reasons Jira requires you to log on to the website before continuing." | ||
ErrorId = "AuthenticaionDenied" | ||
Category = "AuthenticationError" | ||
Cmdlet = $Cmdlet | ||
} | ||
ThrowError @errorParameter | ||
} | ||
{$loginReason -contains "AUTHORISATION_FAILED"} { | ||
$errorParameter = @{ | ||
ExceptionType = "System.Net.Http.HttpRequestException" | ||
Message = "The user could not be authorised." | ||
ErrorId = "AuthorisationFailed" | ||
Category = "AuthenticationError" | ||
Cmdlet = $Cmdlet | ||
} | ||
ThrowError @errorParameter | ||
} | ||
{$loginReason -contains "OK"} {} # The login was OK | ||
{$loginReason -contains "OUT"} {} # This indicates that person has in fact logged "out" | ||
} | ||
} | ||
} | ||
|
||
end { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function ThrowError { | ||
<# | ||
.SYNOPSIS | ||
Utility to throw a terminating errorrecord | ||
.NOTES | ||
Thanks to Jaykul: | ||
https://github.com/PoshCode/Configuration/blob/master/Source/Metadata.psm1 | ||
#> | ||
param | ||
( | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCmdlet] | ||
$Cmdlet = $((Get-Variable -Scope 1 PSCmdlet).Value), | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | ||
[Parameter(ParameterSetName = "NewException")] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Exception] | ||
$Exception, | ||
|
||
[Parameter(ParameterSetName = "NewException", Position = 2)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ExceptionType = "System.Management.Automation.RuntimeException", | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 3)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Message, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[System.Object] | ||
$TargetObject, | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 10)] | ||
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 10)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ErrorId, | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 11)] | ||
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 11)] | ||
[ValidateNotNull()] | ||
[System.Management.Automation.ErrorCategory] | ||
$Category, | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "Rethrow", Position = 1)] | ||
[System.Management.Automation.ErrorRecord]$ErrorRecord | ||
) | ||
process { | ||
if (!$ErrorRecord) { | ||
if ($PSCmdlet.ParameterSetName -eq "NewException") { | ||
if ($Exception) { | ||
$Exception = New-Object $ExceptionType $Message, $Exception | ||
} | ||
else { | ||
$Exception = New-Object $ExceptionType $Message | ||
} | ||
} | ||
$errorRecord = New-Object System.Management.Automation.ErrorRecord $Exception, $ErrorId, $Category, $TargetObject | ||
} | ||
$Cmdlet.ThrowTerminatingError($errorRecord) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function WriteError { | ||
<# | ||
.SYNOPSIS | ||
Utility to write an errorrecord to the errstd | ||
.NOTES | ||
Thanks to Jaykul: | ||
https://github.com/PoshCode/Configuration/blob/master/Source/Metadata.psm1 | ||
#> | ||
param | ||
( | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCmdlet] | ||
$Cmdlet = $((Get-Variable -Scope 1 PSCmdlet).Value), | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | ||
[Parameter(ParameterSetName = "NewException")] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Exception] | ||
$Exception, | ||
|
||
[Parameter(ParameterSetName = "NewException", Position = 2)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ExceptionType = "System.Management.Automation.RuntimeException", | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 3)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Message, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[System.Object] | ||
$TargetObject, | ||
|
||
[Parameter(Mandatory = $true, Position = 10)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$ErrorId, | ||
|
||
[Parameter(Mandatory = $true, Position = 11)] | ||
[ValidateNotNull()] | ||
[System.Management.Automation.ErrorCategory] | ||
$Category, | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "Rethrow", Position = 1)] | ||
[System.Management.Automation.ErrorRecord]$ErrorRecord | ||
) | ||
process { | ||
if (!$ErrorRecord) { | ||
if ($PSCmdlet.ParameterSetName -eq "NewException") { | ||
if ($Exception) { | ||
$Exception = New-Object $ExceptionType $Message, $Exception | ||
} | ||
else { | ||
$Exception = New-Object $ExceptionType $Message | ||
} | ||
} | ||
$errorRecord = New-Object System.Management.Automation.ErrorRecord $Exception, $ErrorId, $Category, $TargetObject | ||
} | ||
$Cmdlet.WriteError($errorRecord) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.