Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create OwnerDetailsUriTemplateResourceV3 and provider #5763

Merged
merged 6 commits into from
Apr 27, 2024

Conversation

donnie-msft
Copy link
Contributor

@donnie-msft donnie-msft commented Apr 24, 2024

Bug

Fixes: NuGet/Home#13409

Regression? Last working version:

Description

Note: this resource is not yet consumed by the Client, but will be in #5766

Adds a resource, OwnerDetailsUriTemplateResourceV3, similar to the PackageDetailsUriResourceV3.

  • A template must use a Uri scheme of HTTPS and be an Absolute Uri.
  • GetUri will replace a template's substring, {owner}, with each Owner returned from the NuGet Search API.
    • Client will not enforce that the template must have this substring. The linked documentation change will suggest that practice.

A new resource provider, OwnerDetailsUriResourceV3Provider, retrieves the resource from the service index, if available.

I've tested in Visual Studio by consuming this resource from package source, https://apidev.nugettest.org/v3/index.json, which @martinrrm has been developing for nuget.org (Thank you! 🙏).

PR Checklist

private static bool IsValidUriTemplate(string absoluteUri)
{
Uri? uri;
var isValidUri = Uri.TryCreate(absoluteUri, UriKind.Absolute, out uri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are converting the URI parameter value to a string in the CreateOrNull method, which then calls the IsValidUriTemplate method, passing in that string. I am not sure why we are converting that string again to verify if it is a valid URI. How about just passing the URI object that was passed to the CreateOrNull method instead of creating another URI object here?

Security considerations section in docs suggest that, You can check a URI string for validity by calling the Uri.IsWellFormedOriginalString method. Can this method be used in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that method as well, but unfortunately, it returns false because of the braces in the URI template provided by the server resource, as shown below.

My suspicion is this is why the PackageDetailsUriResourceV3 does this custom validation, and it's why I copied that for the OwnerDetailsUriTemplateResourceV3 as well.

If you have other suggestions, let me know. I'm a little hesitant to modify the PackageDetailsUriResourceV3 in this PR, but could consider refactoring it as well separately.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateOrNull method in PackageDetailsUriResourceV3 takes a string as parameter but in this resource the same method has Uri as parameter. Is this could be a reason why we are converting the Uri to string and then string to Uri for validation purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reduced some of the validation logic there, have a look and see if that addresses your concern.

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor feedback.

return new OwnerDetailsUriTemplateResourceV3(absoluteUri);
}

private static bool IsValidUriTemplate(string absoluteUri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a Uri type in the method calling this, so you shouldn't need to pass a string.

I'd just all the validations in 1 method and use the Uri type that's already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I was trying not to invent any new validation strategy, as mentioned in #5763 (comment), PackageDetailsUriResourceV3 does this custom validation, and it's why I copied that for the OwnerDetailsUriTemplateResourceV3 as well.

I'll see if I can reduce this validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I don't like this any better than what was there, but now I'm throwing if a null is provided, and now must check for null in the Provider. We don't want providers to throw when they can't find the resource, because it's not required for a package source to implement this resource.

@donnie-msft donnie-msft requested a review from nkolev92 April 27, 2024 00:30
@donnie-msft donnie-msft enabled auto-merge (squash) April 27, 2024 03:52
@donnie-msft donnie-msft merged commit f6615e7 into dev Apr 27, 2024
13 of 16 checks passed
@donnie-msft donnie-msft deleted the dev-donnie-msft-ownerDetailsProtocol branch April 27, 2024 04:25
Copy link
Contributor

@kartheekp-ms kartheekp-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR has already been merged, but I would like to provide some feedback and am happy to discuss it further offline. If my comments are valid, perhaps we could consider opening a follow-up issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consume the OwnerDetailsUriTemplate resource
3 participants