rbacframe

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package rbacframe help other component which want to use servicecomb rbac system

Index

Constants

View Source
const (
	ClaimsUser = "account"
	ClaimsRole = "role"
)
View Source
const (
	RoleAdmin = "admin"
)

Variables

View Source
var (
	ErrInvalidHeader = errors.New("invalid auth header")
	ErrNoHeader      = errors.New("should provide Authorization header")
	ErrInvalidCtx    = errors.New("invalid context")

	ErrConvertErr = errors.New(MsgConvertErr)
	MsgConvertErr = "type convert error"
)

Functions

func Add2WhiteAPIList

func Add2WhiteAPIList(path ...string)

func Authenticate

func Authenticate(tokenStr string, pub *rsa.PublicKey) (interface{}, error)

Authenticate parse a token to claims

func FromContext

func FromContext(ctx context.Context) interface{}

FromContext returns the account value stored in ctx, if any.

func GetResource

func GetResource(api string) string

func MapResource

func MapResource(api, resource string)

MapResource save the mapping from api to resource

func MustAuth

func MustAuth(pattern string) bool

func NewContext

func NewContext(ctx context.Context, claims interface{}) context.Context

NewContext returns a new Context that carries value claims.

func RoleFromContext

func RoleFromContext(ctx context.Context) (string, error)

RoleFromContext only return role name

Types

type Account

type Account struct {
	ID                  string `json:"id,omitempty"`
	Name                string `json:"name,omitempty"`
	Password            string `json:"password,omitempty"`
	Role                string `json:"role,omitempty"`
	TokenExpirationTime string `json:"tokenExpirationTime,omitempty"`
	CurrentPassword     string `json:"currentPassword,omitempty"`
	Status              string `json:"status,omitempty"`
}

func AccountFromContext

func AccountFromContext(ctx context.Context) (*Account, error)

type AccountResponse

type AccountResponse struct {
	Total    int64      `json:"total"`
	Accounts []*Account `json:"data,omitempty"`
}

type Permission

type Permission struct {
	IDs   []string // TODO make IDs checked by rbac
	Verbs []string
}

type Role

type Role struct {
	Project     []string
	Permissions map[string]*Permission
}

type Token

type Token struct {
	TokenStr string `json:"token,omitempty"`
}

Jump to

Keyboard shortcuts

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