Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: File module #109

Open
andrewhamon opened this issue Aug 15, 2023 · 2 comments
Open

Feature Request: File module #109

andrewhamon opened this issue Aug 15, 2023 · 2 comments

Comments

@andrewhamon
Copy link

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.

@andrewhamon andrewhamon changed the title File module Feature: File module Aug 15, 2023
@andrewhamon andrewhamon changed the title Feature: File module Feature Request: File module Aug 15, 2023
@dilyevsky
Copy link
Contributor

dilyevsky commented Aug 15, 2023

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.

@andrewhamon
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants