-
Notifications
You must be signed in to change notification settings - Fork 10
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
RFC: Add IFileUploadValidator to mirror the pattern of the new validator classes #567
base: main
Are you sure you want to change the base?
Conversation
685f204
to
86ba987
Compare
src/Altinn.App.Core/Features/Validation/Default/LegacyFileAnalyzerValidator.cs
Fixed
Show fixed
Hide fixed
foreach (var validatorName in dataType.EnabledFileValidators) | ||
{ | ||
var validator = _fileValidators.First(v => v.Id == validatorName); | ||
var (success, issues) = await validator.Validate(dataType, fileAnalysisResults); | ||
if (!success) | ||
{ | ||
validationIssues.AddRange(issues); | ||
} | ||
} |
Check notice
Code scanning / CodeQL
Missed opportunity to use Select Note
maps its iteration variable to another variable
86ba987
to
e3cec69
Compare
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.
Pretty limited understanding of the whole context here, but approach looks good to me. I'm uncertain about removing public types and such though. Since it seemed like we agreed to follow semver pretty strictly?
src/Altinn.App.Core/Features/FileAnalyzis/IFileAnalyserFactory.cs
Outdated
Show resolved
Hide resolved
/// Implementation of <see cref="IFileUploadValidator"/> that uses the legacy | ||
/// <see cref="IFileValidator"/> and <see cref="IFileAnalyser"/>. | ||
/// </summary> | ||
public class LegacyFileAnalyzerValidator : IFileUploadValidator |
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 think this should be internal
and sealed
? This was meant to bridge the migration to the the new interfaces right, so we have some expectations from the behavior here?
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 just followed previous practice. Having this internal would make it more awkward for users to unregister this implementation from the DI container, and they would have to do it in a way that does not cause compiler warnings if this implementation is removed. I don't have a strong opinion either way.
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.
Should users be able to unregister this? I thought it was needed to still support the file analyzer abstraction
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 don't see any reason why we should actively prevent users from unregistering anything and replace it with their own interface implementation.
I also can't find any realistic scenario when you'd actually need to unregister this service, but a contrived example might be if you had a badly behaved IFileAnalyser
in a package that should not be constructed for uploads to all DataTypes, but only the ones where it is actually used. A quick fix would be to replace this implementation that inject IEnumerable<IFileAnalysr>
with one that fetches from IServiceProvider
only when it is actually required.
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.
It doesn't prevent unregistering though. My impression from previous discussions was that we would be more intentional about type accessibility going forward, and that any modification to public types is a breaking change. That's what I was considering here when reviewing, and so if I consider the tradeoffs between the ergonomics of unregistering and including this as a public API I personally am more worried about adding another public type
src/Altinn.App.Core/Features/Validation/Default/LegacyFileAnalyzerValidator.cs
Outdated
Show resolved
Hide resolved
"Error while running validator {validatorName} on {dataType} for instance {instanceId}", | ||
v.GetType().Name, | ||
dataType.Id, | ||
instance.Id |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
"Start running validator {validatorName} on {dataType} for instance {instanceId}", | ||
v.GetType().Name, | ||
dataType.Id, | ||
instance.Id |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
This log entry depends on a
user-provided value
Quality Gate passedIssues Measures |
Quality Gate passedIssues Measures |
Some service owners has asked for validation of uploaded files. Since we decided to use a new approach for the new validation classes, I think it would make sense to provide a new interface
IFileUploadValidator
to provide a way that follows the same patterns as the new validation interfaces to validate file uploads.Description
IFileValidator
andIFileAnalyser
are registered in custom fields on theDataType
object in applicationmetadata.json. All the other new validation interfaces uses a different pattern where the validator has aDataType
/TaskId
field to configure when it should be executed.This PR:
IFileUploadValidator
interface to match the new validation interfaces (including language parameter)LegacyFileAnalyzerValidator
that ensuresIFileValidator
/IFileAnalyser
continue to work in a backwards compatible way.ValidationService
/ValidationFactory
.Related Issue(s)
Verification
Documentation