1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

NEW FEATURE: Add RFC4183 support to REV() (#2879)

Co-authored-by: Thomas Misilo <tmisilo@ksu.edu>
Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl>
This commit is contained in:
Tom Limoncelli
2024-04-03 16:01:55 -04:00
committed by GitHub
parent f9cff3d5e6
commit 1d96981e11
18 changed files with 601 additions and 145 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/StackExchange/dnscontrol/v4/models"
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
"github.com/StackExchange/dnscontrol/v4/pkg/rfc4183"
"github.com/StackExchange/dnscontrol/v4/pkg/transform"
"github.com/robertkrimen/otto" // load underscore js into vm by default
_ "github.com/robertkrimen/otto/underscore" // required by otto
@ -70,6 +71,7 @@ func ExecuteJavascriptString(script []byte, devMode bool, variables map[string]s
vm.Set("require", require)
vm.Set("REV", reverse)
vm.Set("REVCOMPAT", reverseCompat)
vm.Set("glob", listFiles) // used for require_glob()
vm.Set("PANIC", jsPanic)
@ -290,3 +292,16 @@ func reverse(call otto.FunctionCall) otto.Value {
v, _ := otto.ToValue(rev)
return v
}
func reverseCompat(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 1 {
throw(call.Otto, "REVCOMPAT takes exactly one argument")
}
dom := call.Argument(0).String()
err := rfc4183.SetCompatibilityMode(dom)
if err != nil {
throw(call.Otto, err.Error())
}
v, _ := otto.ToValue(nil)
return v
}