Skip to content
Snippets Groups Projects
Unverified Commit 95446969 authored by Bryan Liles's avatar Bryan Liles Committed by GitHub
Browse files

Merge pull request #377 from greggdonovan/remove_native_methods_provided_in_jsonnet_0_10_0

Remove native methods provided in jsonnet 0.10.0
parents e9bfcf44 42d97b7d
No related branches found
No related tags found
No related merge requests found
......@@ -30,21 +30,6 @@
// element.
parseYaml:: std.native("parseYaml"),
// manifestJson(value, indent): convert the jsonnet object `value`
// to a string encoded as "pretty" (multi-line) JSON, with each
// nesting level indented by `indent` spaces.
manifestJson(value, indent=4):: (
local f = std.native("manifestJsonFromJson");
f(std.toString(value), indent)
),
// manifestYaml(value): convert the jsonnet object `value` to a
// string encoded as a single YAML document.
manifestYaml(value):: (
local f = std.native("manifestYamlFromJson");
f(std.toString(value))
),
// escapeStringRegex(s): Quote the regex metacharacters found in s.
// The result is a regex that will match the original literal
// characters.
......
......@@ -27,33 +27,6 @@ baz: xyzzy
");
assert x == [[3, 4], {foo: "bar", baz: "xyzzy"}] : "got " + x;
local x = kubecfg.manifestJson({foo: "bar", baz: [3, 4]});
assert x == '{
"baz": [
3,
4
],
"foo": "bar"
}
' : "got " + x;
local x = kubecfg.manifestJson({foo: "bar", baz: [3, 4]}, indent=2);
assert x == '{
"baz": [
3,
4
],
"foo": "bar"
}
' : "got " + x;
local x = kubecfg.manifestYaml({foo: "bar", baz: [3, 4]});
assert x == "baz:
- 3
- 4
foo: bar
" : "got " + x;
local i = kubecfg.resolveImage("busybox");
assert i == "busybox:latest" : "got " + i;
......
......@@ -20,9 +20,6 @@ import (
"encoding/json"
"io"
"regexp"
"strings"
goyaml "github.com/ghodss/yaml"
jsonnet "github.com/google/go-jsonnet"
"github.com/google/go-jsonnet/ast"
......@@ -82,38 +79,6 @@ func RegisterNativeFuncs(vm *jsonnet.VM, resolver Resolver) {
},
})
vm.NativeFunction(
&jsonnet.NativeFunction{
Name: "manifestJsonFromJson",
Params: ast.Identifiers{"json", "indent"},
Func: func(data []interface{}) (interface{}, error) {
indent := int(data[1].(float64))
dataBytes := []byte(data[0].(string))
dataBytes = bytes.TrimSpace(dataBytes)
buf := bytes.Buffer{}
if err := json.Indent(&buf, dataBytes, "", strings.Repeat(" ", indent)); err != nil {
return "", err
}
buf.WriteString("\n")
return buf.String(), nil
},
})
vm.NativeFunction(
&jsonnet.NativeFunction{
Name: "manifestYamlFromJson",
Params: ast.Identifiers{"json"},
Func: func(data []interface{}) (interface{}, error) {
var input interface{}
dataBytes := []byte(data[0].(string))
if err := json.Unmarshal(dataBytes, &input); err != nil {
return "", err
}
output, err := goyaml.Marshal(input)
return string(output), err
},
})
vm.NativeFunction(
&jsonnet.NativeFunction{
Name: "resolveImage",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment