etcdadapter

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

README

etcd-adapter

Build Status Coverage Status Godoc

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:

  • Add a single policy rule to the storage
  • Remove a single policy rule from the storage.
  • Add a set of policies rule to the storage.
  • Remove a set of policies rule to the storage.

Additional, this version has enhancements:

  • Fully control the Etcd configuration. It will be useful if Etcd is enable authentication.
  • Support Etcd namespace.
  • Use casbin/v2 (as v1 casbin panic's instead of returning errors).
  • Use "go.etcd.io/etcd/client/v3" instead of the outdated github pkg.

Installation

go get github.com/ntk148v/etcd-adapter

Sample Example

Check the examples folder

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	REQUESTTIMEOUT = 5 * time.Second

	// PLACEHOLDER represent the NULL value in the Casbin Rule.
	PLACEHOLDER = "_"

	// DEFAULT_KEY is the root path in ETCD, if not provided.
	DEFAULT_KEY = "casbin_policy"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter represents the ETCD adapter for policy storage.

func NewAdapter

func NewAdapter(etcdCfg client.Config, namespace string, key string) (*Adapter, error)

func (*Adapter) AddPolicies added in v1.1.0

func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error

AddPolicies adds policy rules to the storage. This is part of the Auto-Save feature.

func (*Adapter) AddPolicy

func (a *Adapter) AddPolicy(sec string, ptype string, line []string) error

AddPolicy adds a policy rule to the storage. Part of the Auto-Save feature.

func (*Adapter) LoadPolicy

func (a *Adapter) LoadPolicy(model model.Model) error

LoadPolicy loads all of policys from ETCD

func (*Adapter) RemoveFilteredPolicy

func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy removes policy rules that match the filter from the storage. Part of the Auto-Save feature.

func (*Adapter) RemovePolicies added in v1.1.0

func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) error

RemovePolicies removes policy rules from the storage. This is part of the Auto-Save feature.

func (*Adapter) RemovePolicy

func (a *Adapter) RemovePolicy(sec string, ptype string, line []string) error

RemovePolicy removes a policy rule from the storage. Part of the Auto-Save feature.

func (*Adapter) SavePolicy

func (a *Adapter) SavePolicy(model model.Model) error

This will rewrite all of policies in ETCD with the current data in Casbin

type CasbinRule

type CasbinRule struct {
	Key   string `json:"key"`
	PType string `json:"ptype"`
	V0    string `json:"v0"`
	V1    string `json:"v1"`
	V2    string `json:"v2"`
	V3    string `json:"v3"`
	V4    string `json:"v4"`
	V5    string `json:"v5"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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