Skip to content

Commit

Permalink
Merge pull request #23 from pspete/issue-22
Browse files Browse the repository at this point in the history
CredentialRetriever 3.8
  • Loading branch information
pspete authored Jun 30, 2021
2 parents 2a79b36 + 0c39c7f commit 9b1be45
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CredentialRetriever Changelog

## 3.8.36

- Update to avoid an observed unexpected error behaviour.

## 3.7.34 (April 11th 2021)

- Update `Get-CCPCredential`
Expand Down
4 changes: 2 additions & 2 deletions CredentialRetriever/CredentialRetriever.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# CompanyName = ''

# Copyright statement for this module
Copyright = '(c) 2020 PSPETE LTD. All rights reserved.'
Copyright = '(c) 2018-2021 Pete Maan. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Retrieve Credentials from CyberArk Central Credential Provider Web Service, or Local Credential Provider using CLIPasswordSDK'
Description = 'Retrieve Credentials from CyberArk Central Credential Provider via REST, or Local Credential Provider using CLIPasswordSDK'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'
Expand Down
58 changes: 29 additions & 29 deletions CredentialRetriever/Functions/Get-AIMCredential.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Function Get-AIMCredential {
YourPass false YourUser DOMAIN.COM
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "Suppress alert from ToSecureString ScriptMethod")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Suppress alert from ToSecureString ScriptMethod')]
[CmdletBinding()]
Param(
# Unique ID of the application
Expand Down Expand Up @@ -137,7 +137,7 @@ Function Get-AIMCredential {
Mandatory = $false,
ValueFromPipelineByPropertyName = $true
)]
[ValidateSet("exact", "regexp")]
[ValidateSet('exact', 'regexp')]
[string]
$QueryFormat,

Expand Down Expand Up @@ -177,26 +177,26 @@ Function Get-AIMCredential {
Begin {
#Function Parameters which will form any query string
$QueryParameters = @(
"Safe",
"Folder",
"Object",
"UserName",
"Address",
"Database"
"PolicyID"
'Safe',
'Folder',
'Object',
'UserName',
'Address',
'Database'
'PolicyID'
)

$ConnectionParms = @(
"Port",
"Timeout"
'Port',
'Timeout'
)

#Array to hold the Properties to return
[array]$ReturnProps = @()
#Hashtable to hold the Results to Output
[hashtable]$Output = @{ }
#Delimiter for separating the output fields
$Separator = "#_-_#"
$Separator = '#_-_#'

}

Expand All @@ -206,48 +206,48 @@ Function Get-AIMCredential {
$Command = "/p AppDescs.AppID=`"$AppID`""

#Build array of query string properties
$PSBoundParameters.Add("Query", @())
$PSBoundParameters.Add('Query', @())
$QueryParameters | ForEach-Object {

If ($PSBoundParameters.ContainsKey("$_")) {


$PSBoundParameters["Query"] += "$_=$($PSBoundParameters["$_"])"
$PSBoundParameters['Query'] += "$_=$($PSBoundParameters["$_"])"
}

}

#Build Command String
switch ( $PSBoundParameters.Keys ) {

"Query" {
'Query' {

#Add Query to Command String
#"Property=Value;Property=Value;Property=Value"
$Command = "$Command /p Query=""$($PSBoundParameters["Query"] -join ";")"""
$Command = "$Command /p Query=""$($PSBoundParameters['Query'] -join ';')"""

}

"QueryFormat" {
'QueryFormat' {

#Add QueryFormat Command String
$Command = "$Command /p QueryFormat=$QueryFormat"

}

"RequiredProps" {
'RequiredProps' {

#Add RequiredProps to Command String
$RequiredProps | ForEach-Object {

$ReturnProps += "PassProps.$_"
}

$Command = "$Command /p RequiredProps=$($RequiredProps -join ",")"
$Command = "$Command /p RequiredProps=$($RequiredProps -join ',')"

}

"Reason" {
'Reason' {

#Add Reason to Command String
$Command = "$Command /p Reason=$Reason"
Expand All @@ -264,33 +264,33 @@ Function Get-AIMCredential {
}

#Add Password & PasswordChangeInProcess to output fields
$ReturnProps += "Password"
$ReturnProps += "PasswordChangeInProcess"
$ReturnProps += 'Password'
$ReturnProps += 'PasswordChangeInProcess'
#Create Output fields string PropX,PropY,PropZ, Password, PasswordChangeInProcess
$ReturnProps = $ReturnProps -join ","
$ReturnProps = $ReturnProps -join ','

#Build Command String
$Command = "$Command /o $ReturnProps /d $Separator"

#Add CommandParameters to $PSBoundParameters for Splat against Invoke-AIMClient
$PSBoundParameters.Add("CommandParameters", "$Command")
$PSBoundParameters.Add('CommandParameters', "$Command")

#Invoke Credential Provider
$Result = Invoke-AIMClient @PSBoundParameters

#Output on StdOut
If ($Result.StdOut) {
If ($null -ne $Result.StdOut) {

#split returned results at Separator
$Results = ($Result.StdOut) -Split $Separator

#use $returnProps to determine propertynames
$ReturnProps = $ReturnProps.Split(",")
$ReturnProps = $ReturnProps.Split(',')

For ($i = 0 ; $i -lt $ReturnProps.length ; $i++) {

#PropertyName=PropertyValue
$Output[$(($ReturnProps[$i]) -replace "PassProps.", "")] = ($Results[$i]).trim()
$Output[$(($ReturnProps[$i]) -replace 'PassProps.', '')] = ($Results[$i]).trim()

}

Expand All @@ -302,14 +302,14 @@ Function Get-AIMCredential {

$this.Password | ConvertTo-SecureString -AsPlainText -Force

}
} -Force

#Add ScriptMethod to output object to convert username & password to Credential Object
$OutputObject | Add-Member -MemberType ScriptMethod -Name ToCredential -Value {

New-Object System.Management.Automation.PSCredential($this.UserName, $this.ToSecureString())

}
} -Force

#Return the result from AIM CP
$OutputObject
Expand Down
34 changes: 29 additions & 5 deletions CredentialRetriever/Functions/Get-CCPCredential.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -610,27 +610,51 @@
} Catch {

try {

$err = $_ | ConvertFrom-Json -ErrorAction Stop
Write-Error -Message $err.ErrorMsg -ErrorId $err.ErrorCode
} catch { Write-Error -Message $RequestError.ErrorRecord.Exception -ErrorId $RequestError.ErrorRecord.FullyQualifiedErrorId -ErrorAction Stop }
$ErrorMessage = $err.ErrorMsg
$ErrorID = $err.ErrorCode

} catch {

$ErrorMessage = $RequestError.ErrorRecord.Exception
$ErrorID = $RequestError.ErrorRecord.FullyQualifiedErrorId

} Finally {

#throw the error
$PSCmdlet.ThrowTerminatingError(

[System.Management.Automation.ErrorRecord]::new(

$ErrorMessage,
$ErrorID,
[System.Management.Automation.ErrorCategory]::NotSpecified,
$PSItem

)

)

}

} Finally {

if ($result) {
if ($null -ne $result) {

#Add ScriptMethod to output object to convert password to Secure String
$result | Add-Member -MemberType ScriptMethod -Name ToSecureString -Value {

$this.Content | ConvertTo-SecureString -AsPlainText -Force

}
} -Force

#Add ScriptMethod to output object to convert username & password to Credential Object
$result | Add-Member -MemberType ScriptMethod -Name ToCredential -Value {

New-Object System.Management.Automation.PSCredential($this.UserName, $this.ToSecureString())

}
} -Force

#Return the result from CCP
$result
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# version format
version: 3.7.{build}
version: 3.8.{build}

environment:
#GIT_TRACE: 1
Expand Down

0 comments on commit 9b1be45

Please sign in to comment.