Skip to content

Commit 23838e2

Browse files
reubenmillerrmiller@nordex-online.comHeyItsGilbert
authored
Adding check for empty string as well as null (#102)
When using the -Credentials parameter when calling `Invoke-PSDepend` for dependencies that don't require credentials, would result in the erroneous warning `WARNING: No credential found for the specified name . Was the dependency misconfigured?` ### Example ```sh Invoke-PSDepend -Path "./depends.psd1" -Install -Import -Credentials @{ "repo1WithCredential" = (Get-Credential) } ``` #### File `depends.psd1` ```sh @{ "PSModule1" = @{ "Name" = "PSModule1" "Version" = "1.0.0" "DependencyType" = "PSGalleryModule" "Credential" = "repo1WithCredential" "Parameters" = @{ "Repository" = "repo1WithCredential" } } "PSModule2" = @{ "Name" = "PSModule2" "Version" = "2.1.0" "DependencyType" = "PSGalleryModule" "Parameters" = @{ "Repository" = "repo2WithoutCredential" } ``` Would generate the warning when processing the `PSModule2` dependency. ```sh WARNING: No credential found for the specified name . Was the dependency misconfigured? ``` ### Fix The -Name parameter in `Resolve-Credential` is cast from $null to an empty string "". So now both null and an empty string are checked. --------- Signed-off-by: Gilbert Sanchez <me@gilbertsanchez.com> Co-authored-by: rmiller@nordex-online.com <rmiller@nordex-online.com> Co-authored-by: Gilbert Sanchez <me@gilbertsanchez.com>
1 parent 62cb759 commit 23838e2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

PSDepend/Public/Get-Dependency.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ function Get-Dependency {
383383
}
384384
}
385385
}
386-
}
386+
}
387387

388388
# Helper to retrieve the credential for a dependency
389389
function Resolve-Credential {
@@ -393,7 +393,7 @@ function Get-Dependency {
393393
)
394394

395395
$credential = $null
396-
if (($null -ne $Name) -and ($null -ne $Credentials)) {
396+
if (![string]::IsNullOrEmpty($Name) -and ($null -ne $Credentials)) {
397397

398398
if ($Credentials.ContainsKey($Name)) {
399399
$credential = $Credentials[$Name]

0 commit comments

Comments
 (0)