stripe/skycfg

Feature Request: File module

andrewhamon opened this issue · 2 comments

Hey there, I've been experimenting with Skycfg and I really like it!

I was hoping to import some data from a yaml file and use that to generate some config, but it seems that the yaml module can only decode a blob of yaml. This is a bit puzzling to me - where does one get a blob of yaml in a pure starlark program with no ability to read from a file?

Anyway, maybe I'm missing something obvious, but it sure would be handy to have a file module for slurping up the bytes of a file.

Hey @andrewhamon - one option is to define a variable or a function returning a string in a .star file and import it using Starlark's load built-in. Here's an example:
https://github.com/stripe/skycfg/blob/a77cda5e9354b9079ee6e7feb4b7cef6895b02ae/_examples/envoy/envoy.cfg#L17C1-L17C1

Another option is to implement custom module that reads data from external source (e.g Vault) or a filesystem but that obviously breaks determinism.

one option is to define a variable or a function returning a string in a .star file and import it using Starlark's load built-in. Here's an example:

Maybe I'm blind, but I don't see any use of yaml there? That just looks like loading some starlark structures from another file.

Anyways, putting my yaml inside a starlark string and then parsing it isn't really an option, the yaml file is also read by other non-skycfg systems.

but that obviously breaks determinism.

I don't see how a filesystem read breaks determinism any more than load would (which also reads from the filesystem by default). The implementation could use whatever skycfg.FileReader is configured, to perfectly match load semantics.

In fact... thats exactly what I did. All in all pretty easy.