https://github.com/danhtran94/authzed-codegen
Type-Safety Code Generation tools for AuthZed. (Golang)
https://github.com/danhtran94/authzed-codegen
acl authzed fga generator permission rbac
Last synced: 18 days ago
JSON representation
Type-Safety Code Generation tools for AuthZed. (Golang)
- Host: GitHub
- URL: https://github.com/danhtran94/authzed-codegen
- Owner: danhtran94
- License: mit
- Created: 2025-03-26T08:01:53.000Z (20 days ago)
- Default Branch: main
- Last Pushed: 2025-03-26T08:04:41.000Z (20 days ago)
- Last Synced: 2025-03-26T09:23:12.474Z (20 days ago)
- Topics: acl, authzed, fga, generator, permission, rbac
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-spicedb - danhtran94/authzed-codegen - Type-Safe stubs code generator for your AuthZed schemas (Clients / Third-party Libraries)
README
# `authzed-codegen`
This repository contains Type-Safe Code Generation tools for AuthZed.
[Authzed](https://authzed.com/) is a powerful authorization engine that allows you to define and manage your authorization policies. This code generation tool helps you generate type-safe code for your AuthZed schemas, making it easier to work with your authorization policies in a type-safe manner.
TLDR; `zed` schema => `go` code generation.
```hcl
// ... other definitionsdefinition menusvc/order {
relation creator: menusvc/user | menusvc/customer
relation company: menusvc/company
permission write = creator + creator->manage + company->manage
}// ... other definitions
``````golang
// order-flow.go
// usage generated stubs example
// ...order := menusvc.Order("order-id")
user := menusvc.User("user-id")order.CreateCreatorRelations(ctx, menusvc.OrderCreatorObjects{
User: []menusvc.User{user},
// Customer: []menusvc.Customer{},
})order.
CheckWrite(ctx, acl.CheckOrderWriteInputs{
User: []menusvc.User{user},
// Company: []menusvc.Company{},
})// ...
``````golang
// order.gen.go
// Code generated by authzed-codegen. DO NOT EDIT.package menusvc
const TypeOrder authz.Type = "menusvc/order"
type RelationOrder authz.Relation
type PermissionOrder authz.Permission// Many payload types like `OrderCreatorObjects`, `OrderCreatorRelation`, etc.
// ...type Order authz.ID
const OrderCreator RelationOrder = "creator"
const OrderCompany RelationOrder = "company"const OrderWrite PermissionOrder = "write"
// Many other utility methods like `Order.CreateCreatorRelations`, `Order.CheckWrite`, etc.
// ...
```## Installation
To install the dependencies, run:
```sh
go install -v github.com/danhtran94/authzed-codegen/cmd/authzed-codegen@latest
```## Usage
To generate code, run:
```sh
authzed-codegen --output example/authzed example/schema.zed
```## Features (check the `example` folder for more details)
- Create relationships and permissions stubs.
- Read relationships.
- Lookup permissions and relationships.
- Generate code for multiple languages (Go, ~~TypeScript, etc.~~).
- SpiceDB engine client.## TODOs
- [ ] Support all schema features.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.