casbinfs

package module
v0.0.0-...-f8e3389 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 8 Imported by: 0

README

Casbin HTTP FileSystem Adapter

GoDoc Reference Latest Version License Name Build Status Coverage Status Report Card Status

Package casbin-httpfs is a convenient http.FileSystem adapter for Casbin v2. It enables Casbin to load policy and model from anything that implements the http.FileSystem interface.

Installation

Make sure you have a working Go workspace, then:

go get github.com/h4ckedneko/casbin-httpfs

For updating to latest stable release, do:

go get -u github.com/h4ckedneko/casbin-httpfs

Usage

Here is a basic example for this package:

package main

import (
	"net/http"

	"github.com/casbin/casbin/v2"
	casbinfs "github.com/h4ckedneko/casbin-httpfs"
)

var fs http.FileSystem = http.Dir("/")

func main() {
	// Initialize a new adapter instance.
	adapter := casbinfs.NewAdapter(fs, "/path/to/policy.csv")

	// Initialize a new enforcer instance by passing the adapter.
	enforcer, _ := casbin.NewEnforcer("/path/to/model.conf", adapter)

	// Start checking for permissions.
	enforcer.Enforce("alice", "data1", "read")
}

License

MIT © Lyntor Paul Figueroa. See LICENSE for full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPolicyFromFS

func LoadPolicyFromFS(fs http.FileSystem, path string, model model.Model) error

LoadPolicyFromFS loads all policy rules from http.FileSystem. It registers all the loaded policy rules into a specified model. This function is used by the Adapter but feel free to use it as is.

func NewCachedEnforcer

func NewCachedEnforcer(fs http.FileSystem, paths ...string) (*casbin.CachedEnforcer, error)

NewCachedEnforcer returns a newly initialized CachedEnforcer instance.

func NewEnforcer

func NewEnforcer(fs http.FileSystem, paths ...string) (*casbin.Enforcer, error)

NewEnforcer returns a newly initialized Enforcer instance.

func NewModel

func NewModel(fs http.FileSystem, path string) (model.Model, error)

NewModel returns a newly initialized Model instance.

func NewSyncedEnforcer

func NewSyncedEnforcer(fs http.FileSystem, paths ...string) (*casbin.SyncedEnforcer, error)

NewSyncedEnforcer returns a newly initialized SyncedEnforcer instance.

Types

type Adapter

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

An Adapter implements the Casbin adapter for http.FileSystem.

func NewAdapter

func NewAdapter(fs http.FileSystem, path string) *Adapter

NewAdapter returns a newly initialized Adapter instance.

func (*Adapter) AddPolicy

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

AddPolicy adds a policy rule into the storage.

func (*Adapter) LoadPolicy

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

LoadPolicy loads all policy rules from the storage.

func (*Adapter) RemoveFilteredPolicy

func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fid int, fvals ...string) error

RemoveFilteredPolicy removes a policy rule from storage that matches the filter.

func (*Adapter) RemovePolicy

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

RemovePolicy removes a policy rule from the storage.

func (*Adapter) SavePolicy

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

SavePolicy saves all policy rules into the storage.

Jump to

Keyboard shortcuts

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