Skip to content

Commit

Permalink
Merge pull request #39 from jzelinskie/v1-examples
Browse files Browse the repository at this point in the history
README: update examples to v1
  • Loading branch information
jzelinskie committed Nov 15, 2021
2 parents 0b30d66 + 0166b30 commit d933748
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 251 deletions.
91 changes: 48 additions & 43 deletions .github/workflows/build.yaml
@@ -1,64 +1,69 @@
---
name: "build"
on:
push:
branches:
- "master"
- "master"
pull_request:
branches:
- "!dependabot/*"
- "*"
- "!dependabot/*"
- "*"
jobs:
lint:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/setup-go@v2"
with:
go-version: ^1.16
- name: "Install linting tools"
run: |
- uses: "actions/setup-go@v2"
with:
go-version: "^1.16"
- name: "Install linting tools"
# This is done before checking out, as to not modify go.mod
go install mvdan.cc/gofumpt/gofumports@latest
go install github.com/mgechev/revive@latest
go install golang.org/x/tools/cmd/stringer@latest
- uses: "actions/checkout@v2"
- name: "Go Mod Tidy"
run: "go mod tidy && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'"
- name: "Formatting (gofumpt)"
run: |
GOFUMPT_OUTPUT="$(find . -iname '*.go' -type f | grep -v pb.go | grep -v 'pb.*.go' | xargs gofumports -d)"
if [ -n "$GOFUMPT_OUTPUT" ]; then
echo "All the following files are not correctly formatted"
echo "${GOFUMPT_OUTPUT}"
exit 1
fi
- name: "Linting (revive)"
run: "bash -c '[ $(find . -iname '*.go' -type f | grep -v 'pb.*.go' | xargs revive | tee /dev/fd/2 | wc -c) -eq 0 ]'"
run: "go install mvdan.cc/gofumpt/gofumports@v0.1.1"
- uses: "actions/checkout@v2"
- uses: "bewuethr/yamllint-action@v1.1.1"
with:
config-file: ".yamllint"
- name: "Go Mod Tidy"
run: "go mod tidy && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'"
- name: "Formatting (gofumpt)"
run: |
GOFUMPT_OUTPUT="$(find . -iname '*.go' -type f | grep -v pb.go | grep -v 'pb.*.go' | xargs gofumports -d)"
if [ -n "$GOFUMPT_OUTPUT" ]; then
echo "All the following files are not correctly formatted"
echo "${GOFUMPT_OUTPUT}"
exit 1
fi
- uses: "golangci/golangci-lint-action@v2"
with:
version: "v1.43"
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: false

test:
name: "Test"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-go@v2"
with:
go-version: "^1.16"
- uses: "authzed/action-testserver@v3"
- name: "go test"
run: "go test -tags integration ./..."
- uses: "actions/checkout@v2"
- uses: "actions/setup-go@v2"
with:
go-version: "^1.16"
- uses: "authzed/action-testserver@v3"
- name: "go test"
run: "go test -tags integration ./..."

protobuf:
name: "Generate Protobufs"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/setup-go@v2"
with:
go-version: "^1.16"
- name: "Install local Go Protobuf plugins"
run: "go install github.com/envoyproxy/protoc-gen-validate@v0.6.1"
- uses: "actions/checkout@v2"
- uses: "bufbuild/buf-setup-action@v0.6.0"
with:
version: "1.0.0-rc6"
- name: "Generate & Diff Protos"
run: "./buf.gen.yaml && git diff && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'"
- uses: "actions/setup-go@v2"
with:
go-version: "^1.16"
- name: "Install local Go Protobuf plugins"
run: "go install github.com/envoyproxy/protoc-gen-validate@v0.6.1"
- uses: "actions/checkout@v2"
- uses: "bufbuild/buf-setup-action@v0.6.0"
with:
version: "1.0.0-rc8"
- name: "Generate & Diff Protos"
run: "./buf.gen.yaml && git diff && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'"
26 changes: 26 additions & 0 deletions .golangci.yaml
@@ -0,0 +1,26 @@
---
run:
timeout: "5m"
skip-dirs:
- "proto"
output:
sort-results: true
linters-settings:
goimports:
local-prefixes: "github.com/authzed/authzed-go"
linters:
enable:
- "deadcode"
- "errcheck"
- "gofumpt"
- "goimports"
- "gosimple"
- "govet"
- "ineffassign"
- "revive"
- "rowserrcheck"
- "staticcheck"
- "structcheck"
- "typecheck"
- "unused"
- "varcheck"
10 changes: 10 additions & 0 deletions .yamllint
@@ -0,0 +1,10 @@
# vim: ft=yaml
---
yaml-files:
- "*.yaml"
- "*.yml"
- ".yamllint"
extends: "default"
rules:
quoted-strings: "enable"
line-length: "disable"
57 changes: 31 additions & 26 deletions README.md
@@ -1,40 +1,40 @@
# Authzed Go Client

[![GoDoc](https://godoc.org/github.com/authzed/authzed-go?status.svg)](https://godoc.org/github.com/authzed/authzed-go)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![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)
[![Mailing List](https://img.shields.io/badge/email-google%20groups-4285F4)](https://groups.google.com/g/authzed-oss)
[![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)

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

[Authzed] is a database and service that stores, computes, and validates your application's permissions.
[SpiceDB] is a database system for managing security-critical permissions checking.

Developers create a schema that models their permissions requirements and use a client library, such as this one, to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.
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?".

[Authzed] operates the globally available, serverless database platform for SpiceDB.

Supported client API versions:
- [v1alpha1](https://docs.authzed.com/reference/api#authzedapiv1alpha1)
- [v0](https://docs.authzed.com/reference/api#authzedapiv0)
- [v1](https://buf.build/authzed/api/docs/main/authzed.api.v1)
- [v1alpha1](https://buf.build/authzed/api/docs/main/authzed.api.v1alpha1)
- [v0](https://buf.build/authzed/api/docs/main/authzed.api.v0)

You can find more info on each API on the [Authzed API reference documentation].
Additionally, Protobuf API documentation can be found on the [Buf Registry Authzed API repository].
You can find more info about the API in the [Authzed Documentation API Reference] or the [Authzed API Buf Registry repository].

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

[SpiceDB]: https://github.com/authzed/spicedb
[Authzed]: https://authzed.com
[Authzed API Reference documentation]: https://docs.authzed.com/reference/api
[Buf Registry Authzed API repository]: https://buf.build/authzed/api/docs/main
[Authzed Documentation API Reference]: https://docs.authzed.com/reference/api
[Authzed API Buf Registry repository]: https://buf.build/authzed/api
[CONTRIBUTING.md]: CONTRIBUTING.md

## Getting Started

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

If you're interested in examples for a specific version of the API, they can be found in their respective folders in the [examples directory].

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

## Basic Usage

Expand Down Expand Up @@ -68,7 +68,7 @@ In order to successfully connect, you will have to provide a [Bearer Token] with

```go
import (
"github.com/authzed/authzed-go/v0"
"github.com/authzed/authzed-go/v1"
"github.com/authzed/grpcutil"
)

Expand All @@ -92,28 +92,33 @@ Because of the verbosity of these types, we recommend writing your own functions

```go
import (
"github.com/authzed/authzed-go/proto/authzed/api/v0"
"github.com/authzed/authzed-go/v0"
"github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/authzed/authzed-go/v1"
"github.com/authzed/grpcutil"
)

...

emilia := &v0.User{UserOneof: &v0.User_Userset{Userset: &v0.ObjectAndRelation{
Namespace: "user",
emilia := &pb.SubjectReference{Object: &v1.ObjectReference{
ObjectType: "blog/user",
ObjectId: "emilia",
Relation: "...",
}}}
}}

post1Reader := &v0.ObjectAndRelation{Namespace: "post", ObjectId: "1", Relation: "read"}
firstPost := &pb.ObjectReference{
ObjectType: "blog/post",
ObjectId: "1",
}

// Is Emilia in the set of users that can read post #1?
resp, err := client.Check(ctx, &v0.CheckRequest{User: emilia, TestUserset: post1Reader})
resp, err := client.CheckPermission(ctx, &pb.CheckPermissionRequest{
Resource: firstPost,
Permission: "read",
Subject: emilia,
})
if err != nil {
log.Fatalf("failed to check permission: %s", err)
log.Fatalf("failed to check permission: %s", err)
}

if resp.GetMembership() == v0.CheckResponse_MEMBER {
if resp.Permissionship == pb.CheckPermissionResponse_PERMISSIONSHIP_HAS_PERMISSION {
log.Println("allowed!")
}
```
1 change: 1 addition & 0 deletions buf.gen.yaml
@@ -1,4 +1,5 @@
#!/usr/bin/env -S buf generate buf.build/authzed/api:262837a8e7451bfd9cac0518972ceaef1d0b9963 --template
---
version: "v1"
plugins:
- remote: "buf.build/library/plugins/go:v1.27.1-1"
Expand Down

0 comments on commit d933748

Please sign in to comment.