privilege

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AllPrivileges         = List{ALL, SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, USAGE, SET, ALTERSYSTEM}
	ReadData              = List{ALL, SELECT}
	ReadWriteData         = List{ALL, SELECT, INSERT, DELETE, UPDATE}
	DatabasePrivileges    = List{ALL, CREATE, CONNECT, TEMPORARY}
	LargeObjectPrivileges = List{ALL, SELECT, UPDATE}
	ParameterPrivileges   = List{ALL, SET, ALTERSYSTEM}
	TablePrivileges       = List{ALL, SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER}
	TableColumnPrivileges = List{ALL, SELECT, INSERT, UPDATE, REFERENCES}
	SequencePrivileges    = List{ALL, SELECT, UPDATE, USAGE}
	SchemaPrivileges      = List{ALL, CREATE, USAGE}

	// UsagePrivilege is used for domains, foreign data wrappers, foreign servers, languages and types
	UsagePrivilege = List{ALL, USAGE}
	// ExecutePrivilege is used for functions and procedures
	ExecutePrivilege = List{ALL, EXECUTE}
)

Predefined sets of privileges.

View Source
var ByName = map[string]Kind{
	"ALL":          ALL,
	"CREATE":       CREATE,
	"SELECT":       SELECT,
	"INSERT":       INSERT,
	"DELETE":       DELETE,
	"UPDATE":       UPDATE,
	"USAGE":        USAGE,
	"TRUNCATE":     TRUNCATE,
	"REFERENCES":   REFERENCES,
	"TRIGGER":      TRIGGER,
	"EXECUTE":      EXECUTE,
	"CONNECT":      CONNECT,
	"TEMP":         TEMPORARY,
	"TEMPORARY":    TEMPORARY,
	"SET":          SET,
	"ALTER SYSTEM": ALTERSYSTEM,
}

ByName is a map of string -> kind value.

ByValue is just an array of privilege kinds sorted by value.

Functions

This section is empty.

Types

type Kind

type Kind uint32

Kind defines a privilege. This is output by the parser, and used to generate the privilege bitfields in the PrivilegeDescriptor.

const (
	ALL Kind
	SELECT
	INSERT
	UPDATE
	DELETE
	TRUNCATE
	REFERENCES
	TRIGGER
	CREATE
	CONNECT
	TEMPORARY
	EXECUTE
	USAGE
	SET
	ALTERSYSTEM
)

List of privileges. ALL is specifically encoded so that it will automatically pick up new privileges.

func KindFromString added in v0.4.0

func KindFromString(s string) (Kind, error)

func (Kind) Mask

func (k Kind) Mask() uint32

Mask returns the bitmask for a given privilege.

func (Kind) String

func (i Kind) String() string

type List

type List []Kind

List is a list of privileges.

func ListFromStrings

func ListFromStrings(strs []string) (List, error)

ListFromStrings takes a list of strings and attempts to build a list of Kind. We convert each string to uppercase and search for it in the ByName map. If an entry is not found in ByName, an error is returned.

func (List) Format

func (pl List) Format(buf *bytes.Buffer)

Format prints out the list in a buffer. This keeps the existing order and uses ", " as separator.

func (List) Len

func (pl List) Len() int

Len, Swap, and Less implement the Sort interface.

func (List) Less

func (pl List) Less(i, j int) bool

func (List) SortedNames

func (pl List) SortedNames() []string

SortedNames returns a list of privilege names in sorted order.

func (List) SortedString

func (pl List) SortedString() string

SortedString is similar to String() but returns privileges sorted by name and uses "," as separator.

func (List) String

func (pl List) String() string

String implements the Stringer interface. This keeps the existing order and uses ", " as separator.

func (List) Swap

func (pl List) Swap(i, j int)

func (List) ToBitField

func (pl List) ToBitField() uint32

ToBitField returns the bitfield representation of a list of privileges.

type ObjectType

type ObjectType string

ObjectType represents objects that can have privileges.

const (
	// Any represents any object type.
	Any ObjectType = "any"
	// Database represents a database object.
	Database ObjectType = "database"
	// Domain represents a domain object.
	Domain ObjectType = "domain"
	// Function represents a function object.
	Function ObjectType = "function"
	// Procedure represents a procedure object.
	Procedure ObjectType = "procedure"
	// ForeignDataWrapper represents a foreign data wrapper object.
	ForeignDataWrapper ObjectType = "foreign data wrapper"
	// ForeignServer represents a foreign server object.
	ForeignServer ObjectType = "foreign server"
	// Language represents a language object.
	Language ObjectType = "language"
	// LargeObject represents a large object object.
	LargeObject ObjectType = "large object"
	// Parameter represents a parameter object.
	Parameter ObjectType = "parameter"
	// Schema represents a schema object.
	Schema ObjectType = "schema"
	// Sequence represents a sequence object.
	Sequence ObjectType = "sequence"
	// Table represents a table object.
	Table ObjectType = "table"
	// Tablespace represents a tablespace object.
	Tablespace ObjectType = "tablespace"
	// Type represents a type object.
	Type ObjectType = "type"

	// Routine represents a routine object.
	Routine ObjectType = "routine" // it includes both functions and procedures
)

Jump to

Keyboard shortcuts

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