authorize

package
v0.0.0-...-1fc07e7 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OP group name
	OP = "op"
	// DEV group name
	DEV = "dev"
)
View Source
var (
	// AuthBuck is the bucket id to save group and authorize data.
	AuthBuck = "authorize"

	// DefaultUser is a user. no use
	DefaultUser = "loda-defaultuser"

	// DefaultGName is the group name has all read permission of all node..
	DefaultGName = "defaultgroup"

	// AdminGName is the group name has all permission of all node.
	AdminGName = "admingroup"
)

Functions

func GetGNameByNs

func GetGNameByNs(ns, name string) string

GetGNameByNs reverse the ns and join the name. The purpose of reverse the ns is list the group by prefix, so that can list the group by ns. e.g: server1.product1.loda, op -> loda.product1.server1-op

func GetNsDevGName

func GetNsDevGName(ns string) string

GetNsDevGName return dev group name of ns.

func GetNsOpGName

func GetNsOpGName(ns string) string

GetNsOpGName return op group name of ns.

Types

type Cluster

type Cluster interface {
	// Get returns the value for the given key.
	View(bucket, key []byte) ([]byte, error)

	// RemoveKey removes the key from the bucket.
	RemoveKey(bucket, key []byte) error

	// Set sets the value for the given key, via distributed consensus.
	Update(bucket []byte, key []byte, value []byte) error

	// Batch update values for given keys in given buckets, via distributed consensus.
	Batch(rows []m.Row) error

	// ViewPrefix returns the value for the keys has the keyPrefix.
	ViewPrefix(bucket, keyPrefix []byte) (map[string][]byte, error)

	// Create a bucket via distributed consensus if not exist.
	CreateBucketIfNotExist(name []byte) error
}

Cluster is the interface op must implement.

type Group

type Group struct {
	GName    string   `json:"gname"`
	Managers []string `json:"managers"`
	Members  []string `json:"members"`
	Items    []string `json:"items"`
	// contains filtered or unexported fields
}

Group is the infrmation one group has.

func (*Group) Byte

func (g *Group) Byte() ([]byte, error)

Byte return group at from of []byte.

func (*Group) GetGroup

func (g *Group) GetGroup(gName string) (Group, error)

GetGroup return group by group name.

func (*Group) ListNsGroup

func (g *Group) ListNsGroup(ns string) ([]Group, error)

ListNsGroup return group list of one ns.

func (*Group) ReadGName

func (g *Group) ReadGName(gname string) (ns, name string)

ReadGName return the ns and name of group name.

func (*Group) UpdateGroupMember

func (g *Group) UpdateGroupMember(gName string, addManagers, addMembers, removeManagers, removeMembers []string) (m.Row, error)

UpdateGroupMember add/remove user from group.

func (*Group) UpdateItems

func (g *Group) UpdateItems(gName string, items []string) error

UpdateItems group items which manage the group permissions.

type GroupInf

type GroupInf interface {
	// ListGroup return the group list of under one ns.
	ListNsGroup(ns string) ([]Group, error)

	// GetGroup return the group by group name.
	GetGroup(gName string) (Group, error)

	// UpdateItems update the group permissions.
	UpdateItems(gName string, items []string) error

	// ReadGName return the ns and name of the group.
	ReadGName(gname string) (ns, name string)
}

GroupInf is interface to manager group.

type Perm

type Perm interface {
	// user interface
	UserInf

	// group interface
	GroupInf

	// DefaultGroupItems return the default permission of the ns.
	DefaultGroupItems(ns string) []string

	// DefaultGroupItems return the admin permission of the ns.
	AdminGroupItems(ns string) []string

	// Check return the query has the permission or not by ns/resource type/username/method.
	Check(username, ns, resourceType, method string) (bool, error)

	// InitGroup init default/admin group and default user.
	InitGroup(rootNode string) error

	// CreateGroup create a group.
	CreateGroup(gName string, managers, members, items []string) error

	// UpdateMember update group member and the user groups.
	UpdateMember(group string, managers, members []string) error

	// RemoveUser remove user from his all group.
	RemoveUser(username string) error

	// RemoveGroup remove the group.
	RemoveGroup(gName string) error
}

Perm is interface to manager authorize.

func NewPerm

func NewPerm(cluster Cluster) (Perm, error)

NewPerm return interface Perm to manager authorize.

type User

type User struct {
	Username string   `json:"username"`
	Mobile   string   `json:"mobile"`
	Groups   []string `json:"groups"`
	// contains filtered or unexported fields
}

User is the infomation one user has.

func (*User) Byte

func (u *User) Byte() ([]byte, error)

Byte return the user at []byte format.

func (*User) CheckUserExist

func (u *User) CheckUserExist(username string) (bool, error)

CheckUserExist return the username exist or not.

func (*User) GetUser

func (u *User) GetUser(username string) (User, error)

GetUser return user by username.

func (*User) GetUserList

func (u *User) GetUserList(usernames []string) (map[string]User, error)

GetUserList return user list by username list.

func (*User) SetUser

func (u *User) SetUser(username, mobile string) error

SetUser create/update user. But will not init/update groups.

func (*User) UpdateUser

func (u *User) UpdateUser(username string, addGroup string, removeGroup string) (m.Row, error)

UpdateUser add or remove the user to or from group.

func (*User) UserRemoveUser

func (u *User) UserRemoveUser(username string) ([]string, error)

UserRemoveUser remove the user and from the groups the user has.

type UserInf

type UserInf interface {
	// GetUser return user by username.
	GetUser(username string) (User, error)

	// GetUserList return a map[string]User,
	// key is username and value is User.
	GetUserList(usernames []string) (map[string]User, error)

	// SetUser create a user with username/mobile.
	SetUser(username, mobile string) error

	// CheckUserExist check the username exist or not.
	CheckUserExist(username string) (bool, error)
}

UserInf is interface to manager user.

Jump to

Keyboard shortcuts

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