cockroach: github.com/cockroachdb/cockroach/pkg/sql/privilege Index | Files

package privilege

import "github.com/cockroachdb/cockroach/pkg/sql/privilege"

Index

Package Files

kind_string.go privilege.go

Variables

var (
    AllPrivileges     = List{ALL, CREATE, DROP, GRANT, SELECT, INSERT, DELETE, UPDATE, USAGE, ZONECONFIG}
    ReadData          = List{GRANT, SELECT}
    ReadWriteData     = List{GRANT, SELECT, INSERT, DELETE, UPDATE}
    DBTablePrivileges = List{ALL, CREATE, DROP, GRANT, SELECT, INSERT, DELETE, UPDATE, ZONECONFIG}
    SchemaPrivileges  = List{ALL, GRANT, CREATE, USAGE}
    TypePrivileges    = List{ALL, GRANT, USAGE}
)

Predefined sets of privileges.

var ByName = map[string]Kind{
    "ALL":        ALL,
    "CREATE":     CREATE,
    "DROP":       DROP,
    "GRANT":      GRANT,
    "SELECT":     SELECT,
    "INSERT":     INSERT,
    "DELETE":     DELETE,
    "UPDATE":     UPDATE,
    "ZONECONFIG": ZONECONFIG,
    "USAGE":      USAGE,
}

ByName is a map of string -> kind value.

var ByValue = [...]Kind{
    ALL, CREATE, DROP, GRANT, SELECT, INSERT, DELETE, UPDATE, USAGE, ZONECONFIG,
}

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

func ValidatePrivileges Uses

func ValidatePrivileges(privileges List, objectType ObjectType) error

ValidatePrivileges returns an error if any privilege in privileges cannot be granted on the given objectType. Currently db/schema/table can all be granted the same privileges.

type Kind Uses

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
    CREATE
    DROP
    GRANT
    SELECT
    INSERT
    DELETE
    UPDATE
    USAGE
    ZONECONFIG
)

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

func (Kind) Mask Uses

func (k Kind) Mask() uint32

Mask returns the bitmask for a given privilege.

func (Kind) String Uses

func (i Kind) String() string

type List Uses

type List []Kind

List is a list of privileges.

func GetValidPrivilegesForObject Uses

func GetValidPrivilegesForObject(objectType ObjectType) List

GetValidPrivilegesForObject returns the list of valid privileges for the specified object type.

func ListFromBitField Uses

func ListFromBitField(m uint32, objectType ObjectType) List

ListFromBitField takes a bitfield of privileges and a ObjectType returns a List. It is ordered in increasing value of privilege.Kind.

func ListFromStrings Uses

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 Uses

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 Uses

func (pl List) Len() int

Len, Swap, and Less implement the Sort interface.

func (List) Less Uses

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

func (List) SortedNames Uses

func (pl List) SortedNames() []string

SortedNames returns a list of privilege names in sorted order.

func (List) SortedString Uses

func (pl List) SortedString() string

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

func (List) String Uses

func (pl List) String() string

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

func (List) Swap Uses

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

func (List) ToBitField Uses

func (pl List) ToBitField() uint32

ToBitField returns the bitfield representation of a list of privileges.

type ObjectType Uses

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"
    // Schema represents a schema object.
    Schema ObjectType = "schema"
    // Table represents a table object.
    Table ObjectType = "table"
    // Type represents a type object.
    Type ObjectType = "type"
)

Package privilege imports 7 packages (graph) and is imported by 118 packages. Updated 2020-10-01. Refresh now. Tools for package owners.