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

Questions regarding LYPLG_TYPE_STORE_ONLY flag with union #2341

Closed
jeremie6wind opened this issue Jan 22, 2025 · 6 comments
Closed

Questions regarding LYPLG_TYPE_STORE_ONLY flag with union #2341

jeremie6wind opened this issue Jan 22, 2025 · 6 comments
Labels
is:question Issue is actually a question.

Comments

@jeremie6wind
Copy link

jeremie6wind commented Jan 22, 2025

Hi,
Since this commit:
b89b5ae
is there another way to reach a store callback of a plugin with the LYPLG_TYPE_STORE_ONLY flag?
For instance:

leaf name {
   type union {
         type mytype1;
         type mytype2;
   }
}

mytype1 is implemented in a plugin. Before the store callback was called with this flag.
This was helpful when loading a known valid configuration.
The previous behavior was fine for me.

I had a similar behavior before also with list keys, let's say that the name is a list:

list mylist {
  key "name";
  leaf name {
     type union {
           type mytype1;
           type mytype2;
     }
  }
}

The store callback was called twice once with the flag and once without.
Now the flag is not present anymore.

Regards

@michalvasko
Copy link
Member

I do not think the flag is compatible with the definition of the union type. The value must be stored as the first matching type, which includes validation. If you skip it, you may store it as a type, which it is not valid for. And that is a problem.

@michalvasko michalvasko added the is:question Issue is actually a question. label Jan 23, 2025
@jeremie6wind
Copy link
Author

Hi Michal,

To give you more context, we use a union with a specific type to encrypt data.

For instance, let's say that we want to encrypt a string password field.
We move the string type to a union in the yang model and implement the encryption
in the store function callback of a libyang secret type plugin, like this:

leaf password {
  type union {
     type secret;
     type string;
    }
}

We were checking the LYPLG_TYPE_STORE_ONLY flag to avoid encrypting in some use cases,
and it was working fine as we use simple unions. I am not sure how to do that if the flag disappears on unions.

@michalvasko
Copy link
Member

I am sorry but you were misusing the flag for additional functionality, which always has a risk of stopping to work after an update. I am not sure what exactly decides when to encrypt the password but sysrepo supports changing the value before storing it or you can define 2 leaves (in a choice, for example) password-encrypted and password-cleartext with the types from your union.

@jeremie6wind
Copy link
Author

Thank you for your reply.
What do you mean by "sysrepo supports changing the value before storing it"?
Do you mean sr_module_change_subscribe with SR_SUBSCR_UPDATE?

@michalvasko
Copy link
Member

Yes, that is what I meant.

@jlesk
Copy link

jlesk commented Jan 27, 2025

thank you Michal.
You can close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:question Issue is actually a question.
Projects
None yet
Development

No branches or pull requests

3 participants