-
Notifications
You must be signed in to change notification settings - Fork 643
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
Conversation
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`.
: 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
tests/NuGetGallery.Facts/Services/CloudBlobFileStorageServiceFacts.cs
Outdated
Show resolved
Hide resolved
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments
src/NuGetGallery.Services/Storage/CloudBlobFileStorageService.cs
Outdated
Show resolved
Hide resolved
src/NuGetGallery.Services/Storage/CloudBlobFileStorageService.cs
Outdated
Show resolved
Hide resolved
|
||
string query = uri.Query.Substring(queryIndex); | ||
|
||
var nvcol = HttpUtility.ParseQueryString(query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit type please
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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).
7a6e130
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 handleversionParameter
.IFileStorageService
: Updated interface to includeversionParameter
.FileSystemFileStorageService.cs
: Updated methods to handleversionParameter
.PackageFileService
: PassedversionParameter
in method calls.CloudBlobFileStorageServiceFacts
,FileSystemFileStorageServiceFacts
, andPackageFileServiceFacts
to includeversionParameter
.