From 3d4f53ddc7136d6baec204ad55606e5e34922cff Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 20 Sep 2022 15:01:05 +0200 Subject: [PATCH] adds pinguinfuss contributed fix (#73) #### :book: Summary - redo PR from @pinguinfuss - fix error message - fix string quotation #### :bookmark_tabs: Test Plan > :bulb: Select your test plan for the code changes. - [x] Tested via Drone.io pipeline - [ ] Custom test - [ ] No test plan ##### Details / Justification #### :books: Additional Notes - just redo #72. - there was an issue caused by git config `core.autocrl` displaying / diffin the wrong line ending sequence Co-authored-by: OCram85 Reviewed-on: https://gitea.ocram85.com/OCram85/PSCredentialStore/pulls/73 --- src/Item/New-CredentialStoreItem.Tests.ps1 | 2 +- src/Item/New-CredentialStoreItem.ps1 | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Item/New-CredentialStoreItem.Tests.ps1 b/src/Item/New-CredentialStoreItem.Tests.ps1 index 4bc582e..fcbc336 100644 --- a/src/Item/New-CredentialStoreItem.Tests.ps1 +++ b/src/Item/New-CredentialStoreItem.Tests.ps1 @@ -102,7 +102,7 @@ Describe "New-CredentialStoreItem" { It "Missing CredentialStore should throw" { { New-CredentialStoreItem -Shared -Path '/tmp/missingStore.json' -RemoteHost 'notrelevant' - } | Should -Throw "Could not add anything into the given CredentialStore." + } | Should -Throw "The given credential store (/tmp/missingStore.json) does not exist!" } } Context "Testing pipeline paramter" { diff --git a/src/Item/New-CredentialStoreItem.ps1 b/src/Item/New-CredentialStoreItem.ps1 index 957897a..6e159cb 100644 --- a/src/Item/New-CredentialStoreItem.ps1 +++ b/src/Item/New-CredentialStoreItem.ps1 @@ -32,7 +32,7 @@ function New-CredentialStoreItem { [None] .EXAMPLE - New-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" + New-CredentialStoreItem -Path 'C:\TMP\mystore.json' -RemoteHost esx01.myside.local' #> [CmdletBinding(DefaultParameterSetName = 'Private')] @@ -68,7 +68,7 @@ function New-CredentialStoreItem { begin { # Set the CredentialStore for private, shared or custom mode. - Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName) + Write-Debug ('ParameterSetName: {0}' -f $PSCmdlet.ParameterSetName) if ($PSCmdlet.ParameterSetName -eq 'Private') { $Path = Get-DefaultCredentialStorePath } @@ -84,9 +84,9 @@ function New-CredentialStoreItem { if (-not(Test-CredentialStore -Shared -Path $Path)) { $MessageParams = @{ Exception = [System.IO.FileNotFoundException]::new( - 'Could not add anything into the given CredentialStore.' + 'The given credential store ({0}) does not exist!' -f $Path ) - ErrorAction = "Stop" + ErrorAction = 'Stop' } Write-Error @MessageParams } @@ -95,8 +95,8 @@ function New-CredentialStoreItem { $CurrentDate = Get-Date -Format 'u' - if ($Identifier -ne "") { - $CredentialName = $RemoteHost = "{0}/{1}" -f $Identifier, $RemoteHost + if ($Identifier -ne '') { + $CredentialName = $RemoteHost = '{0}/{1}' -f $Identifier, $RemoteHost } else { $CredentialName = $RemoteHost