authzed-go

module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2021 License: Apache-2.0

README

authzed-go

The official Go client library for Authzed. This repository is a collection of Go packages specialized for each versions of the Authzed API.

Example (v0 API)

This example demonstrates initializing a client and making a Check request to an existing Namespace.

A more full example can be found in v0/examples.

package main

import (
	"context"
	"log"

	"github.com/authzed/authzed-go/v0"
	"github.com/authzed/authzed-go/proto/authzed/api/v0"
)

func main() {
	// Create an Authzed client
	client, err := authzed.NewClient(
		"grpc.authzed.com:443",
		authzed.Token("t_your_token_here_1234567deadbeef"),
		authzed.SystemCerts(authzed.VerifyCA),
	)
	if err != nil {
		log.Fatalf("unable to initialize client: %s", err)
	}

	// Check if User #26 has read access to note #47
	resp, err := client.Check(context.Background(), &v0.CheckRequest{
		TestUserset: &v0.ObjectAndRelation{
			Namespace: "mynoteapp/note", // Object Type
			ObjectId:  "47",             // Unique id for a object being accessed
			Relation:  "reader"          // Relationship required for access
		},
		User: &v0.User{UserOneof: &v0.User_Userset{Userset: &v0.ObjectAndRelation{
			Namespace: "mynoteapp/user", // User Type
			ObjectId: "26",              // Unique id for a user accessing the object
			Relation: "...",
		}}},
	})
	if err != nil {
		log.Fatalf("unable to run check request: %s", err)
	}

	fmt.Println(resp.GetMembership() == v0.CheckResponse_MEMBER)
	// Outputs:
	// true
}

Directories

Path Synopsis
internal
ctxgroup
Package ctxgroup wraps golang.org/x/sync/errgroup with a context func.
Package ctxgroup wraps golang.org/x/sync/errgroup with a context func.
proto
authzed/api/v0
This file has to be manually created to workaround the following issue: https://github.com/envoyproxy/protoc-gen-validate/issues/481
This file has to be manually created to workaround the following issue: https://github.com/envoyproxy/protoc-gen-validate/issues/481
v0
examples command
x/nsbuilder
Package nsbuilder implements a builder-pattern for defining Authzed Namespaces.
Package nsbuilder implements a builder-pattern for defining Authzed Namespaces.
x/parallel
Package parallel implements experimental utilities for performing parallel client interactions with the Authzed API.
Package parallel implements experimental utilities for performing parallel client interactions with the Authzed API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL