Skip to content

Utility to generate a basic JSON representation of a SpiceDB Schema

License

Notifications You must be signed in to change notification settings

alsbury/spice2json

Repository files navigation

spice2json

Utility to generate a simplified JSON representation of a SpiceDB Schema in order to power code generation in other languages.

Build Binary

Build for mac

GOARCH=arm64 go build -ldflags="-s -w"

Build for intel

GOARCH=amd64 go build -ldflags="-s -w"

Compress using upx for a smaller build

upx --brute spice2json

Command Usage

Read from file, output is to stdout unless an output file is given as the second argument.

spice2json [-n namespace] input.zaml [output.json]

Read from stdin

spice2json -s < schema.zaml

Read from spicedb rest client

spice2json -h -k MyPreSharedKey http:https://localhost:8443

Read from spicedb grpc client

spice2json -g -k MyPreSharedKey [-insecure] localhost:50051

Example

This is a simple example of SpiceDB Schema DSL as input

/** 
 * represents a user of the system 
 */
definition user {}

definition platform {
	relation administrator: user

	permission super_admin = administrator

	permission create_tenant = super_admin + administrator
}

JSON output from above example

{
  "definitions": [
    {
      "name": "user",
      "comment": "represents a user of the system"
    },
    {
      "name": "platform",
      "relations": [
        {
          "name": "administrator",
          "types": [
            {
              "type": "user"
            }
          ]
        }
      ],
      "permissions": [
        {
          "name": "super_admin",
          "userSet": {
            "operation": "union",
            "children": [
              {
                "relation": "administrator"
              }
            ]
          }
        },
        {
          "name": "create_tenant",
          "userSet": {
            "operation": "union",
            "children": [
              {
                "relation": "super_admin"
              },
              {
                "relation": "administrator"
              }
            ]
          }
        }
      ]
    }
  ]
}

About

Utility to generate a basic JSON representation of a SpiceDB Schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages