Must validation with list for unknown keys

Hi,

I have a use case where I need to validate if a list has one particular entry. I do not have complete information about the key. I have only partial string. So I need to use re-match for my validation.

Here is the must rule that I used:

tailf:annotate "/secu:security/dataenc:data-encryption/dataenc:interface/dataenc:ifName" {
    must "re-match(/if:interfaces/if:interface/if:name, 'ip-1/1/0/E1.1:0')" {
      error-message "IP interface is must to enable data encryption";
    }
  }

interface is the list here.
For simplicity sake, I have hardcoded the pattern here. But in my actual use case, I need to derive the pattern from the current() value.

From xpathTracing logs, I observe that it is not traversing through the list to check all the entries. It fails to match the very first entry in the last and then returns with failure.
My expectation is that it has to iterate through the list and return failure only when it is unable to match at least one entry.
Could someone let me know if this is possible to let re-match iterate through the list?

Regards,
Vaishnavi CU

Hello,

the “iteration” can be obtained via using the re-match() in the projection (the […]) of the list.
As your model has more nested items i am unfamiliar with - ill try to briefly show on the simpler “pseudo” model:

container aaa {
  list interface {
     key name;
     leaf name {};
  }
}

if i understood your example correctly, you have something like:

must "re-match(/aaa/interface/name, 'eth')");

while i think you need this:

must "/aaa/interface[re-match(name, 'eth')]";

For more complex model, you can of course use the projection on the specific list where you need it, as well as use the paths depending on the specific "current() elements…

re-match when added for the key works!!!
Thank you very much. :slight_smile: