cacheadapter

package
v0.0.0-...-a7f516c Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// 策略再redis中的key
	Policy_Key = "casbin:policy"

	// 前缀,代表他要检测redis的哪一个键
	Casbin_Indicate_Prefix = "casbin:op"

	// Casbin_Policy_Ad
	//
	//d 添加列表末尾的几行进入内存,addplicy命令
	// 像deny就是直接加一条就可以了
	Casbin_Policy_Add = "add:"
	// Casbin_Policy_Del 删除谁的什么权限,不能做就重新加载
	Casbin_Policy_Del = "del:"
	// Casbin_Policy_Load 重新加载
	Casbin_Policy_Load = "load"
)
View Source
const NS = "PolicyLoad"

Variables

View Source
var (
	LoadFormCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: NS,
			Name:      "policy_load_total",
			Help:      "A counter for policy load from mysql and redis.",
		},
		[]string{"from", "status"},
	)
	LoadTimeHistogram = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Namespace:   NS,
			Subsystem:   "",
			Name:        "load_seconds",
			Help:        "Histogram of loading policy response latency in seconds.",
			ConstLabels: nil,
			Buckets:     []float64{0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2.0, 5.0},
		}, []string{"from"})
)

Functions

func GetCollectors

func GetCollectors() []prometheus.Collector

Types

type CacheAdapter

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

func NewAdapter

func NewAdapter(db *gorm.DB, r *redis.Client, params ...interface{}) *CacheAdapter

使用前请确保已经建立了数据库,数据表可以自动创建

func (*CacheAdapter) AddMorePolicy

func (a *CacheAdapter) AddMorePolicy()

AddMorePolicy (will delete) 增加1w个策略

func (*CacheAdapter) AddPolicy

func (a *CacheAdapter) AddPolicy(_ string, ptype string, rule []string) (err error)

AddPolicy adds a policy rule to the storage.

func (*CacheAdapter) LoadPolicy

func (a *CacheAdapter) LoadPolicy(model model.Model) (err error)

func (*CacheAdapter) RemoveFilteredPolicy

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

RemoveFilteredPolicy 从持久层删除符合筛选条件的policy规则 删除了之后可以考虑直接清除redis,或是也一个一个的找到并删除

func (*CacheAdapter) RemovePolicy

func (a *CacheAdapter) RemovePolicy(sec string, ptype string, rule []string) error

注意redis 删除的时候要放四条规则进去,有一个是deny什么的

func (*CacheAdapter) SavePolicy

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

Jump to

Keyboard shortcuts

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