Skip to content

Commit

Permalink
Merge pull request #130 from jzelinskie/include-buf-ref
Browse files Browse the repository at this point in the history
mage: generate buf metadata with protos
  • Loading branch information
jzelinskie committed Jun 29, 2023
2 parents 0b6dd4a + be82819 commit 06e3de6
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 28 deletions.
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
# Authzed Go Client
# Official SpiceDB Go Client

[![GoDoc](https://godoc.org/github.com/authzed/authzed-go?status.svg)](https://godoc.org/github.com/authzed/authzed-go)
[![Docs](https://img.shields.io/badge/docs-authzed.com-%234B4B6C "Authzed Documentation")](https://docs.authzed.com)
[![Build Status](https://github.com/authzed/authzed-go/workflows/build/badge.svg)](https://github.com/authzed/authzed-go/actions)
[![Discord Server](https://img.shields.io/discord/844600078504951838?color=7289da&logo=discord "Discord Server")](https://discord.gg/jTysUaxXzM)
[![Twitter](https://img.shields.io/twitter/follow/authzed?color=%23179CF0&logo=twitter&style=flat-square)](https://twitter.com/authzed)
[![Docs](https://img.shields.io/badge/docs-authzed.com-%234B4B6C "Authzed Documentation")](https://authzed.com/docs)
[![YouTube](https://img.shields.io/youtube/channel/views/UCFeSgZf0rPqQteiTQNGgTPg?color=%23F40203&logo=youtube&style=flat-square&label=YouTube "Authzed YouTube Channel")](https://www.youtube.com/channel/UCFeSgZf0rPqQteiTQNGgTPg)
[![Discord Server](https://img.shields.io/discord/844600078504951838?color=7289da&logo=discord "Discord Server")](https://authzed.com/discord)
[![Twitter](https://img.shields.io/badge/twitter-%40authzed-1D8EEE?logo=twitter "@authzed on Twitter")](https://twitter.com/authzed)

This repository houses the official Go client library for Authzed and SpiceDB.
This repository houses the official Go client library for SpiceDB and Authzed services.

[SpiceDB] is a database system for managing security-critical permissions checking.
[SpiceDB] is an open source, [Google Zanzibar]-inspired, database system for creating and managing security-critical application permissions.

SpiceDB acts as a centralized service that stores authorization data.
Once stored, data can be performantly queried to answer questions such as "Does this user have access to this resource?" and "What are all the resources this user has access to?".
Developers create a schema that models their permissions requirements and use any of the official or community maintained [client libraries] to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.

[Authzed] operates the globally available, serverless database platform for SpiceDB.
[SpiceDB]: https://github.com/authzed/spicedb
[Google Zanzibar]: https://authzed.com/blog/what-is-zanzibar/
[client libraries]: https://github.com/authzed/awesome-spicedb#clients

Supported client API versions:
- [v1](https://buf.build/authzed/api/docs/main/authzed.api.v1)
- [v1alpha1](https://buf.build/authzed/api/docs/main/authzed.api.v1alpha1)

You can find more info about the API in the [Authzed Documentation API Reference] or the [Authzed API Buf Registry repository].
Have questions? Ask in our [Discord].

See [CONTRIBUTING.md] for instructions on how to contribute and perform common tasks like building the project and running tests.
Looking to contribute? See [CONTRIBUTING.md].

[SpiceDB]: https://github.com/authzed/spicedb
[Authzed]: https://authzed.com
[Authzed Documentation API Reference]: https://docs.authzed.com/reference/api
[Authzed API Buf Registry repository]: https://buf.build/authzed/api
[CONTRIBUTING.md]: CONTRIBUTING.md
You can find issues by priority: [Urgent], [High], [Medium], [Low], [Maybe].
There are also [good first issues].

[Discord]: https://authzed.com/discord
[CONTRIBUTING.md]: https://github.com/authzed/authzed-go/blob/main/CONTRIBUTING.md
[Urgent]: https://github.com/authzed/authzed-go/labels/priority%2F0%20urgent
[High]: https://github.com/authzed/authzed-go/labels/priority%2F1%20high
[Medium]: https://github.com/authzed/authzed-go/labels/priority%2F2%20medium
[Low]: https://github.com/authzed/authzed-go/labels/priority%2F3%20low
[Maybe]: https://github.com/authzed/authzed-go/labels/priority%2F4%20maybe
[good first issues]: https://github.com/authzed/authzed-go/labels/hint%2Fgood%20first%20issue

## Getting Started

We highly recommend following the **[Protecting Your First App]** guide to learn the latest best practice to integrate an application with Authzed.

[Protecting Your First App]: https://docs.authzed.com/guides/first-app

## Basic Usage

### Installation

If you're using a modern version of [Go], run the following commands to add dependencies to your project:
Expand Down
1 change: 0 additions & 1 deletion magefiles/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env -S go run github.com/bufbuild/buf/cmd/buf generate buf.build/authzed/api:dc592e107033a7a4336935cf94fb90426719508d --template
---
version: "v1"
plugins:
Expand Down
46 changes: 44 additions & 2 deletions magefiles/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
package main

import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"text/template"

"github.com/magefile/mage/mg"
)
Expand All @@ -16,8 +21,45 @@ func (g Gen) All() error {
return nil
}

const (
ProtoPath = "proto/authzed/api"
BufRepository = "buf.build/authzed/api"
BufTag = "dc592e107033a7a4336935cf94fb90426719508d"
)

// Proto runs proto codegen
func (Gen) Proto() error {
fmt.Println("generating buf")
return runDirV("magefiles", "./buf.gen.yaml")
bufRef := BufRepository + ":" + BufTag
fmt.Println("generating", bufRef)
runDirV("magefiles", "go", "run", "github.com/bufbuild/buf/cmd/buf", "generate", bufRef)
return generateVersionFiles()
}

func generateVersionFiles() error {
tmpl, err := template.ParseFiles("magefiles/version.go.tpl")
if err != nil {
return fmt.Errorf("failed to parse version template: %w", err)
}

entries, err := os.ReadDir(ProtoPath)
if err != nil {
return err
}

for _, entry := range entries {
if entry.IsDir() && !strings.HasSuffix(entry.Name(), "_test") {
var b bytes.Buffer
tmpl.Execute(&b, map[string]string{
"package": entry.Name(),
"bufRepo": BufRepository,
"bufTag": BufTag,
})

versionPath := filepath.Join(ProtoPath, entry.Name(), "zz_generated.version.go")
if err := os.WriteFile(versionPath, b.Bytes(), 0o644); err != nil {
return err
}
}
}
return nil
}
4 changes: 1 addition & 3 deletions magefiles/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ module github.com/authzed/authzed-go/magefiles
go 1.20

require (
github.com/authzed/authzed-go v0.8.0
github.com/bufbuild/buf v1.20.0
github.com/envoyproxy/protoc-gen-validate v1.0.1
github.com/golangci/golangci-lint v1.52.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
github.com/magefile/mage v1.15.0
github.com/planetscale/vtprotobuf v0.4.0
golang.org/x/vuln v0.1.0
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923
google.golang.org/grpc v1.53.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.30.0
mvdan.cc/gofumpt v0.5.0
Expand Down Expand Up @@ -225,6 +222,7 @@ require (
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
3 changes: 0 additions & 3 deletions magefiles/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions magefiles/version.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package {{ .package }}

const (
BufRepository = "{{ .bufRepo }}"
BufTag = "{{ .bufTag }}"
)
6 changes: 6 additions & 0 deletions proto/authzed/api/v0/zz_generated.version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v0

const (
BufRepository = "buf.build/authzed/api"
BufTag = "dc592e107033a7a4336935cf94fb90426719508d"
)
6 changes: 6 additions & 0 deletions proto/authzed/api/v1/zz_generated.version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v1

const (
BufRepository = "buf.build/authzed/api"
BufTag = "dc592e107033a7a4336935cf94fb90426719508d"
)
6 changes: 6 additions & 0 deletions proto/authzed/api/v1alpha1/zz_generated.version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v1alpha1

const (
BufRepository = "buf.build/authzed/api"
BufTag = "dc592e107033a7a4336935cf94fb90426719508d"
)

0 comments on commit 06e3de6

Please sign in to comment.