Skip to content

Commit

Permalink
Merge pull request #116 from tobvil/master and !Deploy
Browse files Browse the repository at this point in the history
Adds ability to use basic authentication
  • Loading branch information
RamblingCookieMonster authored Jun 30, 2020
2 parents 6f490b4 + ae6451d commit 4c2f9ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
19 changes: 16 additions & 3 deletions BuildHelpers/Public/Find-NugetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function Find-NugetPackage {
PSGallery Module URL: https://www.powershellgallery.com/api/v2/ (default)
PSGallery Script URL: https://www.powershellgallery.com/api/v2/items/psscript/
.PARAMETER Credential
Use if repository requires basic authentication
.EXAMPLE
Find-NugetPackage PSDepend -IsLatest
Expand Down Expand Up @@ -65,7 +68,9 @@ function Find-NugetPackage {
#If specified takes precedence over version
[switch]$IsLatest,

[string]$Version
[string]$Version,

[PSCredential]$Credential
)

#Ugly way to do this. Prefer islatest, otherwise look for version, otherwise grab all matching modules
Expand All @@ -84,8 +89,16 @@ function Find-NugetPackage {
Write-Verbose "Searching for all versions of [$name] module"
$URI = Join-Part -Separator / -Parts $PackageSourceUrl ,"Packages?`$filter=Id eq '$name'"
}

$params = @{
Uri = $Uri
}

if($PSBoundParameters.ContainsKey('Credential')){
$Params.add('Credential', $Credential)
}

Invoke-RestMethod $URI |
Invoke-RestMethod @params |
Select-Object @{n='Name';ex={$_.title.('#text')}},
@{n='Author';ex={$_.author.name}},
@{n='Version';ex={
Expand All @@ -98,4 +111,4 @@ function Find-NugetPackage {
@{n='Uri';ex={$_.Content.src}},
@{n='Description';ex={$_.properties.Description}},
@{n='Properties';ex={$_.properties}}
}
}
15 changes: 13 additions & 2 deletions BuildHelpers/Public/Get-NextNugetPackageVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
PSGallery Module URL: https://www.powershellgallery.com/api/v2/ (default)
PSGallery Script URL: https://www.powershellgallery.com/api/v2/items/psscript/
.PARAMETER Credential
Use if repository requires basic authentication
.EXAMPLE
Get-NextNugetPackageVersion PSDeploy
Expand All @@ -40,16 +43,24 @@
[parameter(ValueFromPipelineByPropertyName=$True)]
[string[]]$Name,

[string]$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/'
[string]$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/',

[PSCredential]$Credential
)
Process
{
foreach($Item in $Name)
{
Try
{
$params = @{
Name = $Item
}
if($PSBoundParameters.ContainsKey('Credential')){
$Params.add('Credential', $Credential)
}
$Existing = $null
$Existing = Find-NugetPackage -Name $Item -PackageSourceUrl $PackageSourceUrl -IsLatest -ErrorAction Stop
$Existing = Find-NugetPackage @params -PackageSourceUrl $PackageSourceUrl -Credential $Credential -IsLatest -ErrorAction Stop
}
Catch
{
Expand Down

0 comments on commit 4c2f9ef

Please sign in to comment.