Skip to content

Commit

Permalink
Modify filter query parameter (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi authored Jan 7, 2025
1 parent 1d825a3 commit c796914
Showing 1 changed file with 84 additions and 24 deletions.
108 changes: 84 additions & 24 deletions src/code/V2ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public override FindResults FindName(string packageName, bool includePrerelease,
filterBuilder.AddCriterion($"Id eq '{packageName}'");
}

filterBuilder.AddCriterion(includePrerelease ? "IsAbsoluteLatestVersion" : "IsLatestVersion");
filterBuilder.AddCriterion(includePrerelease ? "IsAbsoluteLatestVersion eq true" : "IsLatestVersion eq true");
if (type != ResourceType.None) {
filterBuilder.AddCriterion(GetTypeFilterForRequest(type));
}
Expand Down Expand Up @@ -424,7 +424,7 @@ public override FindResults FindNameWithTag(string packageName, string[] tags, b
filterBuilder.AddCriterion($"Id eq '{packageName}'");
}

filterBuilder.AddCriterion(includePrerelease ? "IsAbsoluteLatestVersion" : "IsLatestVersion");
filterBuilder.AddCriterion(includePrerelease ? "IsAbsoluteLatestVersion eq true" : "IsLatestVersion eq true");
if (type != ResourceType.None) {
filterBuilder.AddCriterion(GetTypeFilterForRequest(type));
}
Expand Down Expand Up @@ -915,14 +915,26 @@ private string FindAllFromTypeEndPoint(bool includePrerelease, bool isSearchingM
// JFrog/Artifactory requires an empty search term to enumerate all packages in the feed
if (_isJFrogRepo) {
queryBuilder.SearchTerm = "''";
}

if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
} else {
filterBuilder.AddCriterion("IsLatestVersion");
if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsAbsoluteLatestVersion correctly
filterBuilder.AddCriterion("IsAbsoluteLatestVersion eq true");
} else {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsLatestVersion correctly
filterBuilder.AddCriterion("IsLatestVersion eq true");
}
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
} else {
filterBuilder.AddCriterion("IsLatestVersion");
}
}

var requestUrlV2 = $"{Repository.Uri}{typeEndpoint}/Search()?{queryBuilder.BuildQueryString()}";
return HttpRequestCall(requestUrlV2, out errRecord);
}
Expand Down Expand Up @@ -952,16 +964,24 @@ private string FindTagFromEndpoint(string[] tags, bool includePrerelease, bool i
queryBuilder.AdditionalParameters["$orderby"] = "Id desc";
}

// JFrog/Artifactory requires an empty search term to enumerate all packages in the feed
if (_isJFrogRepo) {
queryBuilder.SearchTerm = "''";
}

if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsAbsoluteLatestVersion correctly
filterBuilder.AddCriterion("IsAbsoluteLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
}
} else {
filterBuilder.AddCriterion("IsLatestVersion");
if (_isJFrogRepo) {
filterBuilder.AddCriterion("IsLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsLatestVersion");
}
}

filterBuilder.AddCriterion($"substringof('PS{(isSearchingModule ? "Module" : "Script")}', Tags) eq true");
Expand Down Expand Up @@ -996,12 +1016,25 @@ private string FindCommandOrDscResource(string[] tags, bool includePrerelease, b

if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsAbsoluteLatestVersion correctly
filterBuilder.AddCriterion("IsAbsoluteLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
}
} else {
filterBuilder.AddCriterion("IsLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsLatestVersion correctly
filterBuilder.AddCriterion("IsLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsLatestVersion");
}
}


// can only find from Modules endpoint
var tagPrefix = isSearchingForCommands ? "PSCommand_" : "PSDscResource_";

Expand Down Expand Up @@ -1038,12 +1071,25 @@ private string FindNameGlobbing(string packageName, ResourceType type, bool incl

if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsAbsoluteLatestVersion correctly
filterBuilder.AddCriterion("IsAbsoluteLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
}
} else {
filterBuilder.AddCriterion("IsLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsLatestVersion correctly
filterBuilder.AddCriterion("IsLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsLatestVersion");
}
}


var names = packageName.Split(new char[] {'*'}, StringSplitOptions.RemoveEmptyEntries);

if (names.Length == 0)
Expand Down Expand Up @@ -1131,14 +1177,28 @@ private string FindNameGlobbingWithTag(string packageName, string[] tags, Resour
queryBuilder.AdditionalParameters["$orderby"] = "Id desc";
}

// JFrog/Artifactory requires an empty search term to enumerate all packages in the feed
if (includePrerelease) {
queryBuilder.AdditionalParameters["includePrerelease"] = "true";
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsAbsoluteLatestVersion correctly
filterBuilder.AddCriterion("IsAbsoluteLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsAbsoluteLatestVersion");
}
} else {
filterBuilder.AddCriterion("IsLatestVersion");
if (_isJFrogRepo) {
// note: we add 'eq true' because some PMPs (currently we know of JFrog, but others may do this too) will proxy the query unedited to the upstream remote and if that's PSGallery, it doesn't handle IsLatestVersion correctly
filterBuilder.AddCriterion("IsLatestVersion eq true");
}
else {
// For ADO, 'IsLatestVersion eq true' and 'IsAbsoluteLatestVersion eq true' in the filter create a bad request error, so we use 'IsLatestVersion' or 'IsAbsoluteLatestVersion' only
filterBuilder.AddCriterion("IsLatestVersion");
}
}


var names = packageName.Split(new char[] {'*'}, StringSplitOptions.RemoveEmptyEntries);

if (!_isPSGalleryRepo)
Expand Down

0 comments on commit c796914

Please sign in to comment.