-
Notifications
You must be signed in to change notification settings - Fork 310
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
Migrate to new validation plugin #194
Conversation
2b57a22
to
eac2172
Compare
"application_ids", | ||
"field_mask", | ||
} | ||
var ListApplicationsRequestFieldPathsNested = []string{ |
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.
Inconsistent spacing, but that can be fixed in the future.
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.
switch name { | ||
case "ids": | ||
|
||
if v, ok := interface{}(&m.ApplicationIdentifiers).(interface{ ValidateFields(...string) error }); ok { |
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 looks pretty dirty and I'm not sure the compiler optimizes this, but we can leave it for a future PR.
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.
IDEM, see #194 (comment)
cause) | ||
} | ||
|
||
var _ error = ApplicationsValidationError{} |
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.
These kind of assertions belong in test code (same below). For every XXXValidationError we initialize two, each taking up 32 bytes of memory (or so). Do we really need to generate them? Can't we just add a unit test in the generator to make sure that (any) generated XXXValidationError implements these?
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.
IDEM, see #194 (comment)
c402597
to
0c411af
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.
Looks good to me now, but let's test CLI and e2e join/uplink/downlink flow before merging.
|
0c411af
to
712efad
Compare
Giving it another thought, it only makes sense to have a In fact, for any non-generated
Since there are no proto paths defined for the struct. In result we just end up with a confusing method signature and additional error handling for all these cases, where fieldpath cannot be specified. |
This would mean that I think this could come in handy indeed. I would also see this useful in the registry, where we do want to validate (#70) but where we don't have the means to do so. Sure, with our proto stores we have access to the entire entity, but we don't when working with IoT platform device registries. |
Not "instead". The proposal is this ordering - https://github.com/rvolosatovs/lorawan-stack/blob/a761c089c3d176d85bdb9783423d46afbd5707eb/pkg/rpcmiddleware/validator/validator.go#L91-L112 The validator plugin generates |
I think we should not change the interceptor (so it still calls On all request messages we implement (by hand) a No need to change what is generated. |
I think that works. In registries we then simply call |
712efad
to
97f87aa
Compare
I made the changes, please take a look. |
LGTM. Next is to implement |
- Use `ValidateFields(...string) error` - Enable validation of entities in registries
604fdd1
to
6c170e1
Compare
e599a3c
to
7d0d128
Compare
@adriansmares Can you test 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.
Wait for regression testing confirmation by @adriansmares
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.
Approved. Both OTAA and ABP tests are working correctly.
Summary:
Closes #69
Closes #51
Closes #260
References #245
References TheThingsIndustries/protoc-gen-fieldmask#22 TheThingsIndustries/protoc-gen-fieldmask#24 TheThingsIndustries/protoc-gen-fieldmask#25 TheThingsIndustries/protoc-gen-fieldmask#26
Changes:
Create.*
helpers from NS and JS and specify fieldpaths to set explicitly