Loading and base64'ing binary files

163 views
Skip to first unread message

Tyler Johnson

unread,
Feb 11, 2019, 11:13:26 AM2/11/19
to Jsonnet
Is there any way to do this in Jsonnet? My particular use case is I want to base64 some binary files to include in a kubernetes Secret.

Igor Peshansky

unread,
Feb 11, 2019, 11:45:38 AM2/11/19
to Tyler Johnson, Jsonnet
You can use https://jsonnet.org/ref/stdlib.html#base64 to encode the bits.
        Igor

On Mon, Feb 11, 2019 at 11:13 AM Tyler Johnson <tsj...@gmail.com> wrote:
Is there any way to do this in Jsonnet? My particular use case is I want to base64 some binary files to include in a kubernetes Secret.

--
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.
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/0868dade-9154-49e5-a3dd-bf236e7fa19a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cunningham

unread,
Feb 11, 2019, 12:48:55 PM2/11/19
to Igor Peshansky, Tyler Johnson, Jsonnet
You can't load a binary file unfortunately, because it has to be UTF-8. You can however base64 it on the commandline and read it as text with importstr.  You can then base64-decode / recode it in Jsonnet if you need to process it somehow.

Angus Lees

unread,
Mar 8, 2019, 4:55:35 AM3/8/19
to Jsonnet
On Tuesday, 12 February 2019 03:13:26 UTC+11, Tyler Johnson wrote:
Is there any way to do this in Jsonnet? My particular use case is I want to base64 some binary files to include in a kubernetes Secret.

As pointed out earlier, the usual solution is std.base64(importstr "yourfile.pem") which of course doesn't work for binary (non-UTF8) files.

If you really need to import non-utf8 files for kubernetes, I'd be happy to add a new builtin in kubecfg for this (probably return a base64 jsonnet string).  If that's something you want, please create a feature-request issue on that github repo.

 - Gus


Haoyi Li

unread,
Mar 8, 2019, 4:58:22 AM3/8/19
to Angus Lees, Jsonnet
The Sjsonnet implementation makes it really easy to add your own intrinsic functions implemented in Java, as the rest of the standard library is, so if anyone else is on Sjsonnet then you can always add support for loading binary-files-as-base64 yourself

--
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.
To post to this group, send email to jso...@googlegroups.com.

emay...@vmware.com

unread,
Mar 8, 2019, 5:30:24 PM3/8/19
to Jsonnet
I have exactly the same issue!

Dave Cunningham

unread,
Mar 9, 2019, 4:28:56 PM3/9/19
to emay...@vmware.com, Jsonnet
It might just be time to add importbin (which is pretty trivial to do)

--
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.
To post to this group, send email to jso...@googlegroups.com.

ED Talks

unread,
May 19, 2020, 6:54:13 PM5/19/20
to Jsonnet
Yup, same here.
Reply all
Reply to author
Forward
0 new messages