Skip to content

Commit 64da47e

Browse files
committed
parser: add parsing of PROVISIONSRC role option
Release note: None
1 parent 0777857 commit 64da47e

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,7 @@ unreserved_keyword ::=
13921392
| 'PRIVILEGES'
13931393
| 'PROCEDURE'
13941394
| 'PROCEDURES'
1395+
| 'PROVISIONSRC'
13951396
| 'PUBLIC'
13961397
| 'PUBLICATION'
13971398
| 'QUERIES'
@@ -3284,6 +3285,7 @@ role_option ::=
32843285
| password_clause
32853286
| valid_until_clause
32863287
| subject_clause
3288+
| provisionsrc_clause
32873289
| 'REPLICATION'
32883290
| 'NOREPLICATION'
32893291
| 'BYPASSRLS'
@@ -3786,6 +3788,10 @@ subject_clause ::=
37863788
'SUBJECT' string_or_placeholder
37873789
| 'SUBJECT' 'NULL'
37883790

3791+
provisionsrc_clause ::=
3792+
'PROVISIONSRC' string_or_placeholder
3793+
| 'PROVISIONSRC' 'NULL'
3794+
37893795
func_name_no_crdb_extra ::=
37903796
type_function_name_no_crdb_extra
37913797
| prefixed_column_path
@@ -4311,6 +4317,7 @@ bare_label_keywords ::=
43114317
| 'PRIVILEGES'
43124318
| 'PROCEDURE'
43134319
| 'PROCEDURES'
4320+
| 'PROVISIONSRC'
43144321
| 'PUBLIC'
43154322
| 'PUBLICATION'
43164323
| 'QUERIES'

pkg/server/user_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func TestValidRoles(t *testing.T) {
4646
require.NoError(t, err)
4747
require.Equal(t, false, hasRole)
4848

49-
// Skip PASSWORD and SUBJECT options. Since PASSWORD still resides in
50-
// system.users and SUBJECT is an enterprise feature that is tested
51-
// separately.
52-
if name == "PASSWORD" || name == "SUBJECT" {
49+
// Skip PASSWORD and SUBJECT/PROVISIONSRC options. Since PASSWORD
50+
// still resides in system.users and SUBJECT, PROVISIONSRC are an
51+
// enterprise features that is tested separately.
52+
if name == "PASSWORD" || name == "SUBJECT" || name == "PROVISIONSRC" {
5353
continue
5454
}
5555
// Add the role and check if the role was added (or in the cases of roles starting

pkg/sql/parser/sql.y

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ func (u *sqlSymUnion) doBlockOption() tree.DoBlockOption {
10451045
%token <str> PARALLEL PARENT PARTIAL PARTITION PARTITIONS PASSWORD PAUSE PAUSED PER PERMISSIVE PHYSICAL PLACEMENT PLACING
10461046
%token <str> PLAN PLANS POINT POINTM POINTZ POINTZM POLICIES POLICY POLYGON POLYGONM POLYGONZ POLYGONZM
10471047
%token <str> POSITION PRECEDING PRECISION PREPARE PREPARED PRESERVE PRIMARY PRIOR PRIORITY PRIVILEGES
1048-
%token <str> PROCEDURAL PROCEDURE PROCEDURES PUBLIC PUBLICATION
1048+
%token <str> PROCEDURAL PROCEDURE PROCEDURES PROVISIONSRC PUBLIC PUBLICATION
10491049

10501050
%token <str> QUERIES QUERY QUOTE
10511051

@@ -1496,7 +1496,7 @@ func (u *sqlSymUnion) doBlockOption() tree.DoBlockOption {
14961496

14971497
%type <str> name opt_name opt_name_parens
14981498
%type <str> privilege savepoint_name
1499-
%type <tree.KVOption> role_option password_clause valid_until_clause subject_clause
1499+
%type <tree.KVOption> role_option password_clause valid_until_clause subject_clause provisionsrc_clause
15001500
%type <tree.Operator> subquery_op
15011501
%type <*tree.UnresolvedName> func_name func_name_no_crdb_extra
15021502
%type <tree.ResolvableFunctionReference> func_application_name
@@ -12069,6 +12069,7 @@ role_option:
1206912069
| password_clause
1207012070
| valid_until_clause
1207112071
| subject_clause
12072+
| provisionsrc_clause
1207212073
| REPLICATION
1207312074
{
1207412075
$$.val = tree.KVOption{Key: tree.Name($1), Value: nil}
@@ -12126,6 +12127,16 @@ subject_clause:
1212612127
$$.val = tree.KVOption{Key: tree.Name("subject"), Value: tree.DNull}
1212712128
}
1212812129

12130+
provisionsrc_clause:
12131+
PROVISIONSRC string_or_placeholder
12132+
{
12133+
$$.val = tree.KVOption{Key: tree.Name("provisionsrc"), Value: $2.expr()}
12134+
}
12135+
| PROVISIONSRC NULL
12136+
{
12137+
$$.val = tree.KVOption{Key: tree.Name("provisionsrc"), Value: tree.DNull}
12138+
}
12139+
1212912140
opt_view_recursive:
1213012141
/* EMPTY */ { /* no error */ }
1213112142
| RECURSIVE { return unimplemented(sqllex, "create recursive view") }
@@ -18403,6 +18414,7 @@ unreserved_keyword:
1840318414
| PRIVILEGES
1840418415
| PROCEDURE
1840518416
| PROCEDURES
18417+
| PROVISIONSRC
1840618418
| PUBLIC
1840718419
| PUBLICATION
1840818420
| QUERIES
@@ -18982,6 +18994,7 @@ bare_label_keywords:
1898218994
| PRIVILEGES
1898318995
| PROCEDURE
1898418996
| PROCEDURES
18997+
| PROVISIONSRC
1898518998
| PUBLIC
1898618999
| PUBLICATION
1898719000
| QUERIES

pkg/sql/parser/testdata/alter_user

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ ALTER ROLE foo WITH SUBJECT ('bar') -- fully parenthesized
117117
ALTER ROLE foo WITH SUBJECT '_' -- literals removed
118118
ALTER ROLE _ WITH SUBJECT 'bar' -- identifiers removed
119119

120+
parse
121+
ALTER ROLE foo PROVISIONSRC 'src'
122+
----
123+
ALTER ROLE foo WITH PROVISIONSRC 'src' -- normalized!
124+
ALTER ROLE foo WITH PROVISIONSRC ('src') -- fully parenthesized
125+
ALTER ROLE foo WITH PROVISIONSRC '_' -- literals removed
126+
ALTER ROLE _ WITH PROVISIONSRC 'src' -- identifiers removed
127+
120128
parse
121129
ALTER USER foo SET search_path = 'abc'
122130
----

pkg/sql/parser/testdata/create_user

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ CREATE ROLE foo WITH SUBJECT 'bar'
207207
CREATE ROLE foo WITH SUBJECT ('bar') -- fully parenthesized
208208
CREATE ROLE foo WITH SUBJECT '_' -- literals removed
209209
CREATE ROLE _ WITH SUBJECT 'bar' -- identifiers removed
210+
211+
parse
212+
CREATE ROLE foo WITH PROVISIONSRC 'src'
213+
----
214+
CREATE ROLE foo WITH PROVISIONSRC 'src'
215+
CREATE ROLE foo WITH PROVISIONSRC ('src') -- fully parenthesized
216+
CREATE ROLE foo WITH PROVISIONSRC '_' -- literals removed
217+
CREATE ROLE _ WITH PROVISIONSRC 'src' -- identifiers removed

pkg/sql/roleoption/option_string.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/roleoption/role_option.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const (
7676
SUBJECT
7777
BYPASSRLS
7878
NOBYPASSRLS
79+
PROVISIONSRC
7980
)
8081

8182
// ControlChangefeedDeprecationNoticeMsg is a user friendly notice which should be shown when CONTROLCHANGEFEED is used
@@ -118,6 +119,7 @@ var toSQLStmts = map[Option]string{
118119
SUBJECT: `UPSERT INTO system.role_options (username, option, value, user_id) VALUES ($1, 'SUBJECT', $2::string, $3)`,
119120
BYPASSRLS: `INSERT INTO system.role_options (username, option, user_id) VALUES ($1, 'BYPASSRLS', $2) ON CONFLICT DO NOTHING`,
120121
NOBYPASSRLS: `DELETE FROM system.role_options WHERE username = $1 AND user_id = $2 AND option = 'BYPASSRLS'`,
122+
PROVISIONSRC: `UPSERT INTO system.role_options (username, option, value, user_id) VALUES ($1, 'PROVISIONSRC', $2::string, $3)`,
121123
}
122124

123125
// Mask returns the bitmask for a given role option.
@@ -158,6 +160,7 @@ var ByName = map[string]Option{
158160
"SUBJECT": SUBJECT,
159161
"BYPASSRLS": BYPASSRLS,
160162
"NOBYPASSRLS": NOBYPASSRLS,
163+
"PROVISIONSRC": PROVISIONSRC,
161164
}
162165

163166
// ToOption takes a string and returns the corresponding Option.

0 commit comments

Comments
 (0)