Skip to content

Commit

Permalink
(NuGet#9) Add check for capabilities to package search
Browse files Browse the repository at this point in the history
When a package search resource is returned, it should first check to see
if the feed that is being accessed has the capabilities to perform the
search.  If this is not done, saerches can be emitted against a feed
which will fail.  A similar check is performed when using a listResource
so this commit does something very similar for a searchResource.  Within
this commit, a NullLogger is used, which isn't ideal, but without
additional work, and refactoring, this has been deemed as ok for now. A
follow up issue will be created to try to remove the usage of this
NullLogger.

Co-authored-by: TheCakeIsNaOH <[email protected]>
  • Loading branch information
gep13 and TheCakeIsNaOH committed Feb 3, 2023
1 parent 6da318d commit 637616d
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito

var serviceDocument = await source.GetResourceAsync<ODataServiceDocumentResourceV2>(token);

resource = new PackageSearchResourceV2Feed(httpSourceResource, serviceDocument.BaseAddress, source.PackageSource);
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

if (serviceDocument != null)
{
var parser = new V2FeedParser(httpSourceResource.HttpSource, serviceDocument.BaseAddress, source.PackageSource.Source);
var feedCapabilityResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceDocument.BaseAddress);
if (await feedCapabilityResource.SupportsSearchAsync(Common.NullLogger.Instance, token))
{
resource = new PackageSearchResourceV2Feed(httpSourceResource, serviceDocument.BaseAddress, source.PackageSource);
}
}

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
}

return new Tuple<bool, INuGetResource>(resource != null, resource);
Expand Down

0 comments on commit 637616d

Please sign in to comment.