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

Add package version to query string for v2 CDN endpoint (#10082) #10083

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

clairernovotny
Copy link
Contributor

@clairernovotny clairernovotny commented Jul 26, 2024

PR Classification

New feature: Added support for handling a version parameter in cloud blob storage services

Implements #10082

PR Summary

Introduced a version parameter to enhance file storage service methods and updated related tests.

  • CloudBlobFileStorageService.cs: Modified constructor and methods to handle versionParameter.
  • IFileStorageService: Updated interface to include versionParameter.
  • FileSystemFileStorageService.cs: Updated methods to handle versionParameter.
  • PackageFileService: Passed versionParameter in method calls.
  • Updated tests in CloudBlobFileStorageServiceFacts, FileSystemFileStorageServiceFacts, and PackageFileServiceFacts to include versionParameter.

Add the packageVersion to the query string of cdn redirect url's

Added a new constant `PackageVersionParameterName` to `CoreConstants.cs`.
Reorganized and added necessary `using` directives in multiple files.
Modified `CloudBlobFileStorageService` to include and handle the new `versionParameter` in its constructor and methods.
Refactored `GetRedirectUri` to include the `versionParameter` in the query string.
Added a helper method `ParseQueryString` in `CloudBlobFileStorageService`.
Updated `IFileStorageService` interface to include the `versionParameter`.
Updated `FileSystemFileStorageService` and `SymbolPackageFileService` to handle the `versionParameter`.
Updated `PackageFileService` to pass the `versionParameter`.
Updated and added tests in corresponding test files to verify the handling of the `versionParameter`.
@clairernovotny clairernovotny requested a review from a team as a code owner July 26, 2024 20:59
: base(client, diagnosticsService, cloudBlobFolderInformationProvider)
{
_configuration = configuration;
_redirectPolicy = redirectPolicy;
}

public async Task<ActionResult> CreateDownloadFileActionResultAsync(Uri requestUrl, string folderName, string fileName)
public async Task<ActionResult> CreateDownloadFileActionResultAsync(Uri requestUrl, string folderName, string fileName, string versionParameter)
Copy link
Member

Choose a reason for hiding this comment

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

This is a low level method not specific to a package or version. What do you think about a simple queryString parameter instead?

Copy link
Member

Choose a reason for hiding this comment

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

This would allow flexibility at the call site.

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 looked a bit closer and the easiest approach hardcodes the parameter name lower down--this just passes the version. Making it more generic would also put the burden on a properly urlencoded query string on the caller.

Copy link
Member

Choose a reason for hiding this comment

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

Seems okay to me. A Dictionary<string, string> would be more flexible. but it's not a big deal to me.

@@ -28,13 +29,18 @@ public PackageFileService(IFileStorageService fileStorageService)
public Task<ActionResult> CreateDownloadPackageActionResultAsync(Uri requestUrl, Package package)
{
var fileName = FileNameHelper.BuildFileName(package, CoreConstants.PackageFileSavePathTemplate, CoreConstants.NuGetPackageFileExtension);
return _fileStorageService.CreateDownloadFileActionResultAsync(requestUrl, CoreConstants.Folders.PackagesFolderName, fileName);

var packageVersion = NuGetVersionFormatter.GetNormalizedPackageVersion(package).ToLowerInvariant(); // will not return null bc BuildFileName will throw if values are null
Copy link
Member

Choose a reason for hiding this comment

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

Why lower invariant? Generally we use the original casing when we have it and allow the user of the value to do the comparison in a case insensitive manner if necessary. This means we can retain that original author intent as much as possible.

@@ -1,6 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Moq;

using NuGetGallery.Configuration;
Copy link
Member

Choose a reason for hiding this comment

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

No need to organize usings. IDE will mess it up as we go.

Copy link
Member

@joelverhagen joelverhagen Jul 29, 2024

Choose a reason for hiding this comment

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

Unless it's possible to add it to encode the rule in editorconfig

Choose a reason for hiding this comment

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

If you set dotnet_sort_system_directives_first = true in editorconfig and once it's in the correct order, the IDE will insert new usings correctly.

It used to get weird with using aliases (e.g. using Foo = System.Foo), but I don't know if it still does or not.

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 added an editorconfig to the repo to resolve this.

Copy link
Member

@joelverhagen joelverhagen left a comment

Choose a reason for hiding this comment

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

Minor comments


string query = uri.Query.Substring(queryIndex);

var nvcol = HttpUtility.ParseQueryString(query);
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicit type please

@erdembayar
Copy link
Contributor

Please add tracking issue link in description.

Enhanced null and whitespace checks in `CreateDownloadPackageActionResultAsync` method of `PackageFileService.cs`. Modified `ParseQueryString` in `CloudBlobFileStorageService.cs` to return `HttpUtility.ParseQueryString(string.Empty)` when query index is `-1`. Updated and removed tests in `CloudBlobFileStorageServiceFacts.cs`. Added new tests in `PackageFileServiceFacts.cs` for null or empty `version` and `id`.
.editorconfig Outdated
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_space_around_binary_operators = before_and_after
csharp_indent_labels = no_change

Choose a reason for hiding this comment

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

nit: ironically this file doesn't have a trailing newline. 😜

.editorconfig Outdated
; Helpful errors
dotnet_diagnostic.CA2017.severity = error
dotnet_diagnostic.CS0105.severity = error
dotnet_diagnostic.IDE0005.severity = error

Choose a reason for hiding this comment

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

nit: would be nice to keep the diagnostics alphabetically sorted by ID, as we will likely add more rules over time, and duplicates are tedious to find when the list is long.

jimmylewis
jimmylewis previously approved these changes Jul 31, 2024
Copy link

@jimmylewis jimmylewis left a comment

Choose a reason for hiding this comment

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

LGTM with a few nits, but I'll defer to Joel for his design feedback comments.

@@ -1,14 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using NuGetGallery.Configuration;

Choose a reason for hiding this comment

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

nit: this file and a few others modified in this PR don't adhere to the new style rules put in place by this PR (.editorconfig).

joelverhagen
joelverhagen previously approved these changes Aug 1, 2024
@clairernovotny clairernovotny dismissed stale reviews from joelverhagen and jimmylewis via 7a6e130 August 1, 2024 15:31
@clairernovotny clairernovotny merged commit 4036cf1 into dev Aug 1, 2024
2 checks passed
@clairernovotny clairernovotny deleted the cnov-package-version-param branch August 1, 2024 16:14
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.

4 participants