plugin/template: Add parseInt template function (#5609)

* plugin/template: Add parseInt template function

Signed-off-by: Erik Johansson <ejohansson@spotify.com>
This commit is contained in:
Erik Johansson 2022-09-15 12:25:58 -07:00 committed by GitHub
parent 7beb76c045
commit e93e932ce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 20 deletions

View file

@ -83,6 +83,20 @@ func TestSetupParse(t *testing.T) {
}`,
true,
},
{
`template ANY ANY {
answer "{{ notAFunction }}"
}`,
true,
},
{
`template ANY ANY {
answer "{{ parseInt }}"
additional "{{ parseInt }}"
authority "{{ parseInt }}"
}`,
false,
},
// examples
{`template ANY ANY (?P<x>`, false},
{
@ -128,6 +142,13 @@ func TestSetupParse(t *testing.T) {
}`,
false,
},
{
`template IN A example {
match ^ip0a(?P<b>[a-f0-9]{2})(?P<c>[a-f0-9]{2})(?P<d>[a-f0-9]{2})[.]example[.]$
answer "{{ .Name }} 3600 IN A 10.{{ parseInt .Group.b 16 8 }}.{{ parseInt .Group.c 16 8 }}.{{ parseInt .Group.d 16 8 }}"
}`,
false,
},
{
`template IN MX example {
match ^ip-10-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)[.]example[.]$