privilege

package
Version: v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserRs = &sqltypes.Result{
		Fields: []*querypb.Field{
			{
				Name: "Host",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "User",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "Select_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Insert_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Update_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Delete_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Create_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Drop_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Alter_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Index_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Show_db_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Super_priv",
				Type: querypb.Type_ENUM,
			},
		},
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock")),
			},
		},
	}

	DbRs = &sqltypes.Result{
		Fields: []*querypb.Field{
			{
				Name: "Host",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "User",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "Select_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Insert_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Update_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Delete_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Create_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Drop_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Grant_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Alter_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Index_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Db",
				Type: querypb.Type_VARCHAR,
			},
		},
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock")),
			},
		},
	}

	UserRs1 = &sqltypes.Result{
		Fields: []*querypb.Field{
			{
				Name: "Host",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "User",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "Select_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Insert_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Update_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Delete_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Create_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Drop_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Alter_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Index_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Show_db_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Super_priv",
				Type: querypb.Type_ENUM,
			},
		},
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock")),
			},
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock1")),
			},
		},
	}

	DbRs1 = &sqltypes.Result{
		Fields: []*querypb.Field{
			{
				Name: "Host",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "User",
				Type: querypb.Type_VARCHAR,
			},

			{
				Name: "Select_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Insert_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Update_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Delete_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Create_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Drop_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Grant_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Alter_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Index_priv",
				Type: querypb.Type_ENUM,
			},

			{
				Name: "Db",
				Type: querypb.Type_VARCHAR,
			},
		},
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock")),
			},
			{
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("%")),
				sqltypes.MakeTrusted(querypb.Type_VARCHAR, []byte("mock")),
			},
		},
	}
)

Functions

func MockInitPrivilegeN

func MockInitPrivilegeN(fakedbs *fakedb.DB)

MockInitPrivilegeN init the Rows with N.

func MockInitPrivilegeNotSuper

func MockInitPrivilegeNotSuper(fakedbs *fakedb.DB)

MockInitPrivilegeNotSuper init the Rows with N to Super_priv.

func MockInitPrivilegeUserNDatabaseY

func MockInitPrivilegeUserNDatabaseY(fakedbs *fakedb.DB)

MockInitPrivilegeUserNDatabaseY init the Rows with user priv N and db priv Y.

func MockInitPrivilegeUsers

func MockInitPrivilegeUsers(fakedbs *fakedb.DB)

MockInitPrivilegeUsers init the Rows with multiple users.

func MockInitPrivilegeY

func MockInitPrivilegeY(fakedbs *fakedb.DB)

MockInitPrivilegeY init the Rows with Y.

Types

type Privilege

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

Privilege struct.

func (*Privilege) Check

func (p *Privilege) Check(database string, user string, node sqlparser.Statement) error

Check -- checks the session privilege on the database.

func (*Privilege) CheckDBinUserPrivilege

func (p *Privilege) CheckDBinUserPrivilege(user string, db string) bool

CheckDBinUserPrivilege ...

func (*Privilege) CheckUserPrivilegeIsSet

func (p *Privilege) CheckUserPrivilegeIsSet(user string) bool

CheckUserPrivilegeIsSet ...

func (*Privilege) Close

func (p *Privilege) Close() error

Close -- close the privilege plugin.

func (*Privilege) GetUserPrivilegeDBS

func (p *Privilege) GetUserPrivilegeDBS(user string) (dbMap map[string]struct{})

GetUserPrivilegeDBS get the dbmap with dbPrivs in the user.

func (*Privilege) Init

func (p *Privilege) Init() error

Init -- init the privilege plugin.

func (*Privilege) IsSuperPriv

func (p *Privilege) IsSuperPriv(user string) bool

IsSuperPriv ...

func (*Privilege) UpdatePrivileges

func (p *Privilege) UpdatePrivileges() error

UpdatePrivileges -- used to update the privileges map to latest.

type PrivilegeHandler

type PrivilegeHandler interface {
	Init() error
	Check(db string, user string, node sqlparser.Statement) error
	CheckPrivilege(db string, user string, node sqlparser.Statement) bool
	CheckUserPrivilegeIsSet(user string) bool
	IsSuperPriv(user string) bool
	GetUserPrivilegeDBS(user string) (dbs map[string]struct{})
	CheckDBinUserPrivilege(user string, db string) bool
	Close() error
}

func NewPrivilege

func NewPrivilege(log *xlog.Log, conf *config.Config, scatter *backend.Scatter) PrivilegeHandler

NewPrivilege -- creates new Privilege.

Jump to

Keyboard shortcuts

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