Skip to content

Commit

Permalink
fix query parameter includePrerelease so it does not return all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi committed Sep 13, 2023
1 parent 6f187ca commit edef53e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/code/V2ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public V2ServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, N
/// </summary>
public override FindResults FindAll(bool includePrerelease, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindAll()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindAll()");
errRecord = null;
List<string> responses = new List<string>();

Expand Down Expand Up @@ -156,7 +156,7 @@ public override FindResults FindAll(bool includePrerelease, ResourceType type, o
/// </summary>
public override FindResults FindTags(string[] tags, bool includePrerelease, ResourceType _type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindTags()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindTags()");
errRecord = null;
List<string> responses = new List<string>();

Expand Down Expand Up @@ -249,7 +249,7 @@ public override FindResults FindTags(string[] tags, bool includePrerelease, Reso
/// </summary>
public override FindResults FindCommandOrDscResource(string[] tags, bool includePrerelease, bool isSearchingForCommands, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindCommandOrDscResource()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindCommandOrDscResource()");
List<string> responses = new List<string>();
int skip = 0;

Expand Down Expand Up @@ -309,7 +309,7 @@ public override FindResults FindCommandOrDscResource(string[] tags, bool include
/// </summary>
public override FindResults FindName(string packageName, bool includePrerelease, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindName()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindName()");
// Make sure to include quotations around the package name
var prerelease = includePrerelease ? "IsAbsoluteLatestVersion" : "IsLatestVersion";

Expand Down Expand Up @@ -352,7 +352,7 @@ public override FindResults FindName(string packageName, bool includePrerelease,
/// </summary>
public override FindResults FindNameWithTag(string packageName, string[] tags, bool includePrerelease, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindNameWithTag()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindNameWithTag()");
// Make sure to include quotations around the package name
var prerelease = includePrerelease ? "IsAbsoluteLatestVersion" : "IsLatestVersion";

Expand Down Expand Up @@ -403,7 +403,7 @@ public override FindResults FindNameWithTag(string packageName, string[] tags, b
/// </summary>
public override FindResults FindNameGlobbing(string packageName, bool includePrerelease, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindNameGlobbing()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindNameGlobbing()");
List<string> responses = new List<string>();
int skip = 0;

Expand Down Expand Up @@ -456,7 +456,7 @@ public override FindResults FindNameGlobbing(string packageName, bool includePre
/// </summary>
public override FindResults FindNameGlobbingWithTag(string packageName, string[] tags, bool includePrerelease, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindNameGlobbingWithTag()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindNameGlobbingWithTag()");
List<string> responses = new List<string>();
int skip = 0;

Expand Down Expand Up @@ -511,7 +511,7 @@ public override FindResults FindNameGlobbingWithTag(string packageName, string[]
/// </summary>
public override FindResults FindVersionGlobbing(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, bool getOnlyLatest, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindVersionGlobbing()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindVersionGlobbing()");
List<string> responses = new List<string>();
int skip = 0;

Expand Down Expand Up @@ -565,7 +565,7 @@ public override FindResults FindVersionGlobbing(string packageName, VersionRange
/// </summary>
public override FindResults FindVersion(string packageName, string version, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindVersion()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindVersion()");
// https://www.powershellgallery.com/api/v2/FindPackagesById()?id='blah'&includePrerelease=false&$filter= NormalizedVersion eq '1.1.0' and substringof('PSModule', Tags) eq true
// Quotations around package name and version do not matter, same metadata gets returned.
// We need to explicitly add 'Id eq <packageName>' whenever $filter is used, otherwise arbitrary results are returned.
Expand Down Expand Up @@ -607,7 +607,7 @@ public override FindResults FindVersion(string packageName, string version, Reso
/// </summary>
public override FindResults FindVersionWithTag(string packageName, string version, string[] tags, ResourceType type, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindVersionWithTag()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindVersionWithTag()");
// We need to explicitly add 'Id eq <packageName>' whenever $filter is used, otherwise arbitrary results are returned.
string idFilterPart = $" and Id eq '{packageName}'";
string typeFilterPart = GetTypeFilterForRequest(type);
Expand Down Expand Up @@ -656,7 +656,7 @@ public override FindResults FindVersionWithTag(string packageName, string versio
/// </summary>
public override Stream InstallName(string packageName, bool includePrerelease, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::InstallName()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::InstallName()");
var requestUrlV2 = $"{Repository.Uri}/package/{packageName}";

var response = HttpRequestCallForContent(requestUrlV2, out errRecord);
Expand All @@ -675,7 +675,7 @@ public override Stream InstallName(string packageName, bool includePrerelease, o
/// </summary>
public override Stream InstallVersion(string packageName, string version, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::InstallVersion()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::InstallVersion()");
var requestUrlV2 = $"{Repository.Uri}/package/{packageName}/{version}";
var response = HttpRequestCallForContent(requestUrlV2, out errRecord);
var responseStream = response.ReadAsStreamAsync().Result;
Expand All @@ -688,7 +688,7 @@ public override Stream InstallVersion(string packageName, string version, out Er
/// </summary>
private string HttpRequestCall(string requestUrlV2, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::HttpRequestCall()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::HttpRequestCall()");
errRecord = null;
string response = string.Empty;

Expand Down Expand Up @@ -745,7 +745,7 @@ private string HttpRequestCall(string requestUrlV2, out ErrorRecord errRecord)
/// </summary>
private HttpContent HttpRequestCallForContent(string requestUrlV2, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::HttpRequestCallForContent()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::HttpRequestCallForContent()");
errRecord = null;
HttpContent content = null;

Expand Down Expand Up @@ -798,7 +798,7 @@ private HttpContent HttpRequestCallForContent(string requestUrlV2, out ErrorReco
/// </summary>
private string FindAllFromTypeEndPoint(bool includePrerelease, bool isSearchingModule, int skip, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindAllFromTypeEndPoint()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindAllFromTypeEndPoint()");
string typeEndpoint = isSearchingModule ? String.Empty : "/items/psscript";
string paginationParam = $"&$orderby=Id desc&$inlinecount=allpages&$skip={skip}&$top=6000";
var prereleaseFilter = includePrerelease ? "IsAbsoluteLatestVersion&includePrerelease=true" : "IsLatestVersion";
Expand All @@ -812,7 +812,7 @@ private string FindAllFromTypeEndPoint(bool includePrerelease, bool isSearchingM
/// </summary>
private string FindTagFromEndpoint(string[] tags, bool includePrerelease, bool isSearchingModule, int skip, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindTagFromEndpoint()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindTagFromEndpoint()");
// scenarios with type + tags:
// type: None -> search both endpoints
// type: M -> just search Module endpoint
Expand All @@ -821,7 +821,7 @@ private string FindTagFromEndpoint(string[] tags, bool includePrerelease, bool i
// type: Command -> just search Modules
string typeEndpoint = isSearchingModule ? String.Empty : "/items/psscript";
string paginationParam = $"&$orderby=Id desc&$inlinecount=allpages&$skip={skip}&$top=6000";
var prereleaseFilter = includePrerelease ? "$filter=IsAbsoluteLatestVersion&includePrerelease=true" : "$filter=IsLatestVersion";
var prereleaseFilter = includePrerelease ? "includePrerelease=true&$filter=IsAbsoluteLatestVersion" : "$filter=IsLatestVersion";
string typeFilterPart = isSearchingModule ? $" and substringof('PSModule', Tags) eq true" : $" and substringof('PSScript', Tags) eq true";

string tagFilterPart = String.Empty;
Expand All @@ -840,7 +840,7 @@ private string FindTagFromEndpoint(string[] tags, bool includePrerelease, bool i
/// </summary>
private string FindCommandOrDscResource(string[] tags, bool includePrerelease, bool isSearchingForCommands, int skip, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindCommandOrDscResource()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindCommandOrDscResource()");
// can only find from Modules endpoint
string paginationParam = $"&$orderby=Id desc&$inlinecount=allpages&$skip={skip}&$top=6000";
var prereleaseFilter = includePrerelease ? "$filter=IsAbsoluteLatestVersion&includePrerelease=true" : "$filter=IsLatestVersion";
Expand All @@ -867,7 +867,7 @@ private string FindCommandOrDscResource(string[] tags, bool includePrerelease, b
/// </summary>
private string FindNameGlobbing(string packageName, ResourceType type, bool includePrerelease, int skip, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindNameGlobbing()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindNameGlobbing()");
// https://www.powershellgallery.com/api/v2/Search()?$filter=endswith(Id, 'Get') and startswith(Id, 'PowerShell') and IsLatestVersion (stable)
// https://www.powershellgallery.com/api/v2/Search()?$filter=endswith(Id, 'Get') and IsAbsoluteLatestVersion&includePrerelease=true

Expand Down Expand Up @@ -935,7 +935,7 @@ private string FindNameGlobbing(string packageName, ResourceType type, bool incl
/// </summary>
private string FindNameGlobbingWithTag(string packageName, string[] tags, ResourceType type, bool includePrerelease, int skip, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindNameGlobbingWithTag()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindNameGlobbingWithTag()");
// https://www.powershellgallery.com/api/v2/Search()?$filter=endswith(Id, 'Get') and startswith(Id, 'PowerShell') and IsLatestVersion (stable)
// https://www.powershellgallery.com/api/v2/Search()?$filter=endswith(Id, 'Get') and IsAbsoluteLatestVersion&includePrerelease=true

Expand Down Expand Up @@ -1009,7 +1009,7 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, Resour
/// </summary>
private string FindVersionGlobbing(string packageName, VersionRange versionRange, bool includePrerelease, ResourceType type, int skip, bool getOnlyLatest, out ErrorRecord errRecord)
{
_cmdletPassedIn.WriteDebug("In NuGetServerAPICalls::FindVersionGlobbing()");
_cmdletPassedIn.WriteDebug("In V2ServerAPICalls::FindVersionGlobbing()");
//https://www.powershellgallery.com/api/v2//FindPackagesById()?id='blah'&includePrerelease=false&$filter= NormalizedVersion gt '1.0.0' and NormalizedVersion lt '2.2.5' and substringof('PSModule', Tags) eq true
//https://www.powershellgallery.com/api/v2//FindPackagesById()?id='PowerShellGet'&includePrerelease=false&$filter= NormalizedVersion gt '1.1.1' and NormalizedVersion lt '2.2.5'
// NormalizedVersion doesn't include trailing zeroes
Expand Down

0 comments on commit edef53e

Please sign in to comment.