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

Possible bug when using add_vars variable and referencing it to use in a regex with re(MY_REGEX_VARIABLE) #124

Open
bodleytunes opened this issue Sep 6, 2024 · 0 comments

Comments

@bodleytunes
Copy link

Hi,

I'm hitting a problem where it could be a bug but could be how Im using TTP with a regex string variable.

If I defined/hard code under and create a variable POLICY_RE like so:

POLICY_RE = ".*MANAGEMENT.*"

And using it to scrape a juniper

<group name="policy_options.{{ policy }}" itemize="network">
{{ ignore("\s*") }}set policy-options prefix-list {{ policy | re(POLICY_RE) }} {{ network }}
</group>

It works fine.

But if I try this

<group name="policy_options.{{ policy }}" itemize="network">
{{ ignore("\s*") }}set policy-options prefix-list {{ policy | re(MY_CUSTOM_REGEX) }} {{ network }}
</group>

    search_policies = ".*MANAGEMENT.*"

    parser = ttp(data=config, template=ttp_template)
    parser.add_vars({"MY_CUSTOM_REGEX": search_policies})
    parser.parse()

It doesn't work and when I step through the library code I see that the variable for parserObj.groups.0.start_re

is showing the name of the variable rather than the contents of the variable, the regex string like so:

'\\n(?:\\s*)set[ \\t] policy\\-options[ \\t] prefix\\-list[ \\t] (?P<policy>(?:MY_CUSTOM_REGEX))[ \\t] (?P<network>(?:\\S ))[\\t ]*(?=\\n|\\r\\n)'

whereas in the working case with hardcoding vars in template im getting the full regex string appearing

parserObj.groups.0.start_re

'\\n(?:\\s*)set[ \\t] policy\\-options[ \\t] prefix\\-list[ \\t] (?P<policy>(?:.*MANAGEMENT.*))[ \\t] (?P<network>(?:\\S ))[\\t ]*(?=\\n|\\r\\n)'

Is this by design or am I using it incorrectly?

Many thanks,

Jon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant