Skip to content

Commit 4c2f9ef

Browse files
Merge pull request #116 from tobvil/master and !Deploy
Adds ability to use basic authentication
2 parents 6f490b4 + ae6451d commit 4c2f9ef

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

BuildHelpers/Public/Find-NugetPackage.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function Find-NugetPackage {
3333
PSGallery Module URL: https://www.powershellgallery.com/api/v2/ (default)
3434
PSGallery Script URL: https://www.powershellgallery.com/api/v2/items/psscript/
3535
36+
.PARAMETER Credential
37+
Use if repository requires basic authentication
38+
3639
.EXAMPLE
3740
Find-NugetPackage PSDepend -IsLatest
3841
@@ -65,7 +68,9 @@ function Find-NugetPackage {
6568
#If specified takes precedence over version
6669
[switch]$IsLatest,
6770

68-
[string]$Version
71+
[string]$Version,
72+
73+
[PSCredential]$Credential
6974
)
7075

7176
#Ugly way to do this. Prefer islatest, otherwise look for version, otherwise grab all matching modules
@@ -84,8 +89,16 @@ function Find-NugetPackage {
8489
Write-Verbose "Searching for all versions of [$name] module"
8590
$URI = Join-Part -Separator / -Parts $PackageSourceUrl ,"Packages?`$filter=Id eq '$name'"
8691
}
92+
93+
$params = @{
94+
Uri = $Uri
95+
}
96+
97+
if($PSBoundParameters.ContainsKey('Credential')){
98+
$Params.add('Credential', $Credential)
99+
}
87100

88-
Invoke-RestMethod $URI |
101+
Invoke-RestMethod @params |
89102
Select-Object @{n='Name';ex={$_.title.('#text')}},
90103
@{n='Author';ex={$_.author.name}},
91104
@{n='Version';ex={
@@ -98,4 +111,4 @@ function Find-NugetPackage {
98111
@{n='Uri';ex={$_.Content.src}},
99112
@{n='Description';ex={$_.properties.Description}},
100113
@{n='Properties';ex={$_.properties}}
101-
}
114+
}

BuildHelpers/Public/Get-NextNugetPackageVersion.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
PSGallery Module URL: https://www.powershellgallery.com/api/v2/ (default)
2424
PSGallery Script URL: https://www.powershellgallery.com/api/v2/items/psscript/
2525
26+
.PARAMETER Credential
27+
Use if repository requires basic authentication
28+
2629
.EXAMPLE
2730
Get-NextNugetPackageVersion PSDeploy
2831
@@ -40,16 +43,24 @@
4043
[parameter(ValueFromPipelineByPropertyName=$True)]
4144
[string[]]$Name,
4245

43-
[string]$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/'
46+
[string]$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/',
47+
48+
[PSCredential]$Credential
4449
)
4550
Process
4651
{
4752
foreach($Item in $Name)
4853
{
4954
Try
5055
{
56+
$params = @{
57+
Name = $Item
58+
}
59+
if($PSBoundParameters.ContainsKey('Credential')){
60+
$Params.add('Credential', $Credential)
61+
}
5162
$Existing = $null
52-
$Existing = Find-NugetPackage -Name $Item -PackageSourceUrl $PackageSourceUrl -IsLatest -ErrorAction Stop
63+
$Existing = Find-NugetPackage @params -PackageSourceUrl $PackageSourceUrl -Credential $Credential -IsLatest -ErrorAction Stop
5364
}
5465
Catch
5566
{

0 commit comments

Comments
 (0)