I can't find one in std library. Any other solution?
--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+unsubscribe@googlegroups.com.
To post to this group, send email to jso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/1f3c864d-fff6-41b6-8596-d13212305015%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import uuid
import json
import _jsonnet
import sys
def make_uuid():
return str(uuid.uuid4())
native_callbacks = {
'make_uuid': ((), make_uuid),
}
json_str = _jsonnet.evaluate_file(
'test.jsonnet',
native_callbacks=native_callbacks,
)
sys.stdout.write(json_str)
local make_uuid() =
std.native("make_uuid")();
{
response: make_uuid(),
}
Such a function would be inherently non-hermetic. The usual advice here is to put some placeholder in the config that is expanded to the UUID by whomever consumes the config. E.g. return something that embeds a unique string identifying the UUID within the context of the config, but not unique across time / re-runs of the config. That way the consumer can generate the right number of UUIDs for the config. Also if you need to reconcile the original config with the deployed artifact containing the UUIDs generated when it was deployed, you can do that too.
You can also parameterize the jsonnet run with the UUIDs, but that means you need to know how many there are ahead of time, so it's a bit less general.
On Fri, Aug 24, 2018 at 2:06 AM, jesse zhao <chat2...@gmail.com> wrote:
I can't find one in std library. Any other solution?
--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.