I’ve setup an OpenFGA project, using the provided docker container. I’ve written a short node.js
script to initialise the store locally, setup the model, add some test tuples, and add some assertions, then test all these. With typescript and tsx watch
, these tests will run anytime I add a new tuple or assertion or make any code changes. Happy days.
However, every time I edit my authModel.fga
DSL file, I need to convert it to JSON manually before I can re-run my tests. The best way I’ve found to do this so far is to use the VSCode extension command, and then copy-paste the output.
Ideally, I’d like to script the transformation so it automatically runs whenever the model file changes. I’d like everything self-contained so that other users can check out the codebase, bootstrap, and go. We use docker
and docker-compose
for this for all our usual node modules.
I saw there is a docker container for the OpenFGA CLI, but I couldn’t figure out how to make it transform my model and output to a JSON file.
This is the closest I got:
docker run -it openfga/cli model transform "$(cat packages/fga/model/authModel.fga)" > packages/fga/model/authModel.json
…but this seems to mangle the output JSON with a bunch of weird characters like this:
[1m{[22m[m
[m[m [m[34;1m"[0;22m[34;1mschema_version[0;22m[34;1m"[0;22m[1m:[22m[32m"[0m[32m1.1[0m[32m"[0m[1m,[22m[m
[m[m [m[34;1m"[0;22m[34;1mtype_definitions[0;22m[34;1m"[0;22m[1m:[22m[m [m[1m[[22m[m
[m[m [m[1m{[22m[m
Any ideas?
2
Answers
try this script
this part will remove weird characters from the output
You can also do this by using volume mounts for the input & output file to read/write it easily from inside the container. Try: