Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new table user_privileges #15745

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/parser"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
)

Expand All @@ -44,6 +45,7 @@ var informationSchema = virtualSchema{
informationSchemaTablePrivileges,
informationSchemaTablesTable,
informationSchemaViewsTable,
informationSchemaUserPrivileges,
},
}

Expand Down Expand Up @@ -416,6 +418,30 @@ CREATE TABLE information_schema.table_constraints (
},
}

var informationSchemaUserPrivileges = virtualSchemaTable{
schema: `
CREATE TABLE information_schema.user_privileges (
GRANTEE STRING NOT NULL DEFAULT '',
TABLE_CATALOG STRING NOT NULL DEFAULT '',
PRIVILEGE_TYPE STRING NOT NULL DEFAULT '',
IS_GRANTABLE BOOL NOT NULL DEFAULT FALSE
);`,
populate: func(ctx context.Context, p *planner, addRow func(...parser.Datum) error) error {
grantee := parser.NewDString(security.RootUser)
for _, p := range privilege.List(privilege.ByValue[:]).SortedNames() {
if err := addRow(
grantee, // grantee
defString, // table_catalog
parser.NewDString(p), // privilege_type
parser.DNull, // is_grantable
); err != nil {
return err
}
}
return nil
},
}

var informationSchemaTablePrivileges = virtualSchemaTable{
schema: `
CREATE TABLE information_schema.table_privileges (
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ statistics
table_constraints
table_privileges
tables
user_privileges
views

query TT colnames
Expand Down Expand Up @@ -224,6 +225,7 @@ statistics
table_constraints
table_privileges
tables
user_privileges
views
abc
xyz
Expand Down Expand Up @@ -269,6 +271,7 @@ zones
xyz
views
users
user_privileges
ui
tables
tables
Expand Down Expand Up @@ -326,6 +329,7 @@ def information_schema statistics SYSTEM VIEW 1
def information_schema table_constraints SYSTEM VIEW 1
def information_schema table_privileges SYSTEM VIEW 1
def information_schema tables SYSTEM VIEW 1
def information_schema user_privileges SYSTEM VIEW 1
def information_schema views SYSTEM VIEW 1
def other_db abc VIEW 1
def other_db xyz BASE TABLE 2
Expand Down Expand Up @@ -388,6 +392,7 @@ def information_schema statistics SYSTEM VIEW 1
def information_schema table_constraints SYSTEM VIEW 1
def information_schema table_privileges SYSTEM VIEW 1
def information_schema tables SYSTEM VIEW 1
def information_schema user_privileges SYSTEM VIEW 1
def information_schema views SYSTEM VIEW 1
def pg_catalog pg_am SYSTEM VIEW 1
def pg_catalog pg_attrdef SYSTEM VIEW 1
Expand Down Expand Up @@ -436,6 +441,7 @@ def information_schema statistics SYSTEM VIEW 1
def information_schema table_constraints SYSTEM VIEW 1
def information_schema table_privileges SYSTEM VIEW 1
def information_schema tables SYSTEM VIEW 1
def information_schema user_privileges SYSTEM VIEW 1
def information_schema views SYSTEM VIEW 1
def other_db xyz BASE TABLE 6
def pg_catalog pg_am SYSTEM VIEW 1
Expand Down Expand Up @@ -869,3 +875,21 @@ NULL NULL NULL NULL NU

statement ok
DROP DATABASE other_db


#Verify information_schema.user_privileges

query TTTT colnames
SELECT * FROM information_schema.user_privileges ORDER BY privilege_type
----
grantee table_catalog privilege_type is_grantable
root def ALL NULL
root def CREATE NULL
root def DELETE NULL
root def DROP NULL
root def GRANT NULL
root def INSERT NULL
root def SELECT NULL
root def UPDATE NULL