roles

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	//NameRole - name space of the roles module
	NameRole = "role"
	// CostCreate is the cost to create a new role
	CostCreate = uint64(40)
	// CostAssume is the cost to assume a role as part of a tx
	CostAssume = uint64(5)
)
View Source
const (
	ByteAssumeRoleTx = 0x23
	ByteCreateRoleTx = 0x24

	TypeAssumeRoleTx = NameRole + "/assume" // no prefix needed as it is middleware
	TypeCreateRoleTx = NameRole + "/create" // prefix needed for dispatcher
)

nolint

Variables

View Source
var (
	// MaxMembers it the maximum number of members in a Role.  Used to avoid
	// extremely large roles.
	// Value is arbitrary, please adjust as needed
	MaxMembers = 20
)

Functions

func ErrInsufficientSigs

func ErrInsufficientSigs() errors.TMError

func ErrNoMembers

func ErrNoMembers() errors.TMError

func ErrNoRole

func ErrNoRole() errors.TMError

TODO: codegen? ex: err-gen NoRole,"No such role",CodeType_Unauthorized

func ErrNotEnoughMembers

func ErrNotEnoughMembers() errors.TMError

func ErrNotMember

func ErrNotMember() errors.TMError

func ErrRoleExists

func ErrRoleExists() errors.TMError

func ErrTooManyMembers

func ErrTooManyMembers() errors.TMError

func IsInsufficientSigsErr

func IsInsufficientSigsErr(err error) bool

func IsNoMembersErr

func IsNoMembersErr(err error) bool

func IsNoRoleErr

func IsNoRoleErr(err error) bool

func IsNotEnoughMembersErr

func IsNotEnoughMembersErr(err error) bool

func IsNotMemberErr

func IsNotMemberErr(err error) bool

func IsRoleExistsErr

func IsRoleExistsErr(err error) bool

func IsTooManyMembersErr

func IsTooManyMembersErr(err error) bool

func NewAssumeRoleTx

func NewAssumeRoleTx(role []byte, tx sdk.Tx) sdk.Tx

NewAssumeRoleTx creates a new wrapper to add a role to a tx execution

func NewCreateRoleTx

func NewCreateRoleTx(role []byte, minSigs uint32, signers []sdk.Actor) sdk.Tx

NewCreateRoleTx creates a new role, which we can later use

func NewPerm

func NewPerm(role []byte) sdk.Actor

NewPerm creates a role permission with the given label

Types

type AssumeRoleTx

type AssumeRoleTx struct {
	Role data.Bytes `json:"role"`
	Tx   sdk.Tx     `json:"tx"`
}

AssumeRoleTx is a layered tx that can wrap your normal tx to give it the authority to use a given role.

func (AssumeRoleTx) ValidateBasic

func (tx AssumeRoleTx) ValidateBasic() error

ValidateBasic - validate nothing is empty

func (AssumeRoleTx) Wrap

func (tx AssumeRoleTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type CreateRoleTx

type CreateRoleTx struct {
	Role    data.Bytes  `json:"role"`
	MinSigs uint32      `json:"min_sigs"`
	Signers []sdk.Actor `json:"signers"`
}

CreateRoleTx is used to construct a new role

TODO: add ability to update signers on a role... but that adds a lot more complexity to the permissions

func (CreateRoleTx) ValidateBasic

func (tx CreateRoleTx) ValidateBasic() error

ValidateBasic - validate nothing is empty

func (CreateRoleTx) Wrap

func (tx CreateRoleTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type Handler

type Handler struct {
	sdk.NopInitState
	sdk.NopInitValidate
}

Handler allows us to create new roles

func NewHandler

func NewHandler() Handler

NewHandler makes a role handler to create roles

func (Handler) CheckTx

func (h Handler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx verifies if the transaction is properly formated

func (Handler) DeliverTx

func (h Handler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx tries to create a new role.

Returns an error if the role already exists

func (Handler) Name

func (Handler) Name() string

Name - return name space

type Middleware

type Middleware struct {
	stack.PassInitState
	stack.PassInitValidate
}

Middleware allows us to add a requested role as a permission if the tx requests it and has sufficient authority

func NewMiddleware

func NewMiddleware() Middleware

NewMiddleware creates a role-checking middleware

func (Middleware) CheckTx

func (m Middleware) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

CheckTx tries to assume the named role if requested. If no role is requested, do nothing. If insufficient authority to assume the role, return error.

func (Middleware) DeliverTx

func (m Middleware) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

DeliverTx tries to assume the named role if requested. If no role is requested, do nothing. If insufficient authority to assume the role, return error.

func (Middleware) Name

func (Middleware) Name() string

Name - return name space

type Role

type Role struct {
	MinSigs uint32      `json:"min_sigs"`
	Signers []sdk.Actor `json:"signers"`
}

Role - structure to hold permissioning

func NewRole

func NewRole(min uint32, signers []sdk.Actor) Role

NewRole creates a Role structure to store the permissioning

func (Role) IsAuthorized

func (r Role) IsAuthorized(ctx sdk.Context) bool

IsAuthorized checks if the context has permission to assume the role

func (Role) IsSigner

func (r Role) IsSigner(a sdk.Actor) bool

IsSigner checks if the given Actor is allowed to sign this role

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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