Categorygithub.com/batchcorp/etcd-adapter
modulepackage
1.0.3-batch
Repository: https://github.com/batchcorp/etcd-adapter.git
Documentation: pkg.go.dev

# README

etcd-adapter

Build Status Coverage Status Godoc

Update 12.27.2021

This is an updated version of the etcd-adapter written by @sebastianliu.

This version has a few quality of life updates:

  1. Updated to use go mod
  2. Use "go.etcd.io/etcd/client/v3" instead of the github pkg
  3. Use casbin/v2 (as v1 casbin panic's instead of returning errors)
  4. Updated lib to no longer panic on bad instantiation
  5. Support etcd auth

Overview

ETCD adapter is the policy storage adapter for Casbin. With this library, Casbin can load policy from ETCD and save policy to it. ETCD adapter support the Auto-Save feature for Casbin policy. This means it can support adding a single policy rule to the storage, or removing a single policy rule from the storage.

Installation

go get github.com/batchcorp/etcd-adapter

Auth

If your etcd is setup with TLS and/or username/pass auth, you can pass an optional AuthConfig.

Example

package main

import (
	"github.com/batchcorp/etcd-adapter"
	"github.com/casbin/casbin/v2"
)

func main() {
	// Initialize a casbin etcd adapter and use it in a Casbin enforcer:
	// The adapter will use the ETCD and a named path with the key you give.
	// If not provided, the adapter will try to use the default value casbin_policy.
	// If you have namespace to distinguish keys in your etcd, you can use your_namespace/casbin_root_path
	a, _ := etcdadapter.NewAdapter([]string{"http://127.0.0.1:2379"}, "casbin_policy_test", nil) // Your etcd endpoints and the path key.

	e, _ := casbin.NewEnforcer("rbac_model.conf", a)

	// Load the policy from ETCD.
	e.LoadPolicy()

	// Check the permission.
	e.Enforce("alice", "data1", "read")

	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)

	// Save the policy back to DB.
	e.SavePolicy()
}

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author

# Constants

DefaultKey is the root path in ETCD, if not provided.
DialKeepAliveTime is the time after which client pings the server to see if transport is alive.
DialKeepAliveTimeout is the time that the client waits for a response for the keep-alive probe.
DialTimeout is the timeout for failing to establish a connection.
Placeholder represent the NULL value in the Casbin Rule.
No description provided by the author

# Structs

Adapter represents the ETCD adapter for policy storage.
No description provided by the author
No description provided by the author