rbac

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTagName = "json"
)

Functions

func FillMap

func FillMap(s interface{}, out map[string]interface{})

func IsStruct

func IsStruct(s interface{}) bool

func Map

func Map(s interface{}) map[string]interface{}

func RoleMiddleware

func RoleMiddleware() echo.MiddlewareFunc

func RoleMiddlewareWithConfig

func RoleMiddlewareWithConfig(config RoleMiddlewareConfig) echo.MiddlewareFunc

func Values

func Values(s interface{}) []interface{}

Types

type Action

type Action string
const (
	Create     Action = "create"
	Read       Action = "read"
	Update     Action = "update"
	Delete     Action = "delete"
	Play       Action = "play"
	Admin      Action = "admin"
	Management Action = "management"
)

type CustomStruct

type CustomStruct struct {
	TagName string
	// contains filtered or unexported fields
}

func Struct

func Struct(s interface{}) *CustomStruct

func (*CustomStruct) Field

func (s *CustomStruct) Field(name string) *Field

func (*CustomStruct) FieldOk

func (s *CustomStruct) FieldOk(name string) (*Field, bool)

func (*CustomStruct) Fields

func (s *CustomStruct) Fields() []*Field

func (*CustomStruct) FillMap

func (s *CustomStruct) FillMap(out map[string]interface{})

func (*CustomStruct) ToMap

func (s *CustomStruct) ToMap() map[string]interface{}

func (*CustomStruct) Values

func (s *CustomStruct) Values() []interface{}

type Field

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

func Fields

func Fields(s interface{}) []*Field

type Operator

type Operator string
const (
	Equals            Operator = "eq"
	NotEquals         Operator = "ne"
	GreaterThanEquals Operator = "gte"
	GreaterThan       Operator = "gt"
	LessThan          Operator = "lt"
	LessThanEquals    Operator = "lte"
	Contains          Operator = "like"
	Icontains         Operator = "ilike"
	Any               Operator = "any"
	In                Operator = "in"
)

type Permission

type Permission struct {
	ID     string `json:"id" yaml:"id"`
	Name   string `json:"name" yaml:"name"`
	Action string `json:"action" yaml:"action"`
	Target string `json:"target" yaml:"target"`
	Rules  []Rule `json:"rules" yaml:"rules"`
}

func (*Permission) IsValid

func (p *Permission) IsValid() bool

type Rbac

type Rbac struct {
	Roles []Role `json:"roles" yaml:"roles"`
}

func With

func With(roles []Role) *Rbac

func WithJSON

func WithJSON(str string) *Rbac

func WithRoles

func WithRoles(str interface{}) *Rbac

func (*Rbac) HasPermission

func (r *Rbac) HasPermission(action Action, target string) bool

func (*Rbac) IsAllowed

func (r *Rbac) IsAllowed(i interface{}) bool

type Role

type Role struct {
	ID          string       `json:"id" yaml:"id"`
	Name        string       `json:"name" yaml:"name"`
	Permissions []Permission `json:"permissions" yaml:"permissions"`
}

func FromFile

func FromFile(path string) ([]Role, error)

func FromJSON

func FromJSON(i interface{}) ([]Role, error)

func FromYAML

func FromYAML(i interface{}) ([]Role, error)

type RoleMiddlewareConfig

type RoleMiddlewareConfig struct {
	Skipper        func(c echo.Context) bool
	Mandatory      []Action
	ContextRoleKey string
}

type Rule

type Rule struct {
	Allowed  bool        `json:"allowed" yaml:"allowed"`
	Key      string      `json:"key" yaml:"key"`
	Operator Operator    `json:"operator" yaml:"operator"`
	Value    interface{} `json:"value" yaml:"value"`
}

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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