-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
afterValidate operation hook #1226
Comments
Use operation hooks. See http://docs.strongloop.com/display/LB/Operation+hooks. For future reference, please post questions to https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Reporting-issues#question for more details. |
@bajtos What should we do with this issue? Are validation hooks deprecated in favour of operation hooks? |
I see. I will assign this issue to you for further processing as it seems you are already working on it. |
@drish Can you please elaborate a bit more please? Are you trying to store the property value in an encrypted form and decrypt it on load? As I said in loopbackio/loopback-datasource-juggler#441 (comment), hooks are not the right tool for encrypted storage.
See #1260 for a discussion about the best way how to implement encrypted properties. |
@bajtos , gladly. This is an example, on how I think we would need to have afterValidate, back (cuz it's deprecated). On customer.json {
"name": "string"
} On validation.js
If I use something like: customer.observe("before save", function(c, next) {
encrypt(c); // suppose this function manipulates and encrypt some data
next();
}); The validation on The right way, would be something like:
Consequently, we would need to have the Thanks for the efforts. |
@drish thank you for describing your use case. So what if we implemented #1260 and allowed you to provide encrypt/decrypt functions as a part of your property definition, so that you don't need to deal with hooks at all? Would that be a better solution for your problem? {
"name": "MyModel",
"properties": {
"name": { "type": "string", "encrypted": true }
}
} module.exports = function(MyModel) {
MyModel._encryptPropertyValue = function(propertyName, value, cb) {
// your encryption algorithm
cb(null, encryptedPropertyValue);
};
MyModel._decryptPropertyValue = function(propertyName, encryptedValue, cb) {
// your encryption algorithm
cb(null, value);
};
} |
@bajtos @drish I would propose a lower-level approach using hooks first - over time you could move towards something like #1260 which could be built on top of |
In fact, I would kindly suggest to finally implement start implementing such functionality as mixins ... so you can do:
|
@fabien ok, I see your point. The {
"name": "MyModel",
"properties": {
"name": { "type": "string", "encrypted": true }
},
"mixins": {
"Encrypt": {}
}
} How about "loading" and "saving" hooks then? Note that you need to encrypt the property value even when performing |
@bajtos yes, of course - it's easy to do. What if we had the following hooks as a final solution (hopefully):
If you have some bandwidth available, I'd like you to implement this. In turn, I can create the Encrypt mixin as a seperate npm package, and resolve #1260. What do you think? |
Yes, this is exactly what I had in mind. I feel
+1 for
I started to look into the /cc @raymondfeng |
Let's move the discussion here: loopbackio/loopback-datasource-juggler#559
Let's move the discussion to a standalone issue: loopbackio/loopback-datasource-juggler#560 @drish I am closing this issue in favour of loopbackio/loopback-datasource-juggler#441 and loopbackio/loopback-datasource-juggler#559. Feel free to reopen if you disagree. |
Hello guys.
The docs say the current version does not support
afterValidate
hook, but what about the case where I need to manipulate data after it is validated ?For example, after all my fields are validated I'd like to encrypt some of them and persist into datastore.
Common hook
model.afterValidate
is deprecated.Thanks in advance.
The text was updated successfully, but these errors were encountered: