-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql,server: create toString to role option #75271
Conversation
pkg/server/admin.go
Outdated
@@ -3209,7 +3209,7 @@ func (c *adminPrivilegeChecker) hasRoleOption( | |||
row, err := c.ie.QueryRowEx( | |||
ctx, "check-role-option", nil, /* txn */ | |||
sessiondata.InternalExecutorOverride{User: user}, | |||
"SELECT crdb_internal.has_role_option($1)", roleOption.String()) | |||
"SELECT crdb_internal.has_role_option($1)", roleoption.ToString[roleOption]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd prefer if we added a method to RoleOption
called ToString() instead of using the map directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test that would fail without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test added
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @RichardJCai)
pkg/server/admin.go, line 3212 at r1 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
nit: I'd prefer if we added a method to
RoleOption
called ToString() instead of using the map directly
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
// It should be used instead of roleOption.String() to accommodate the cases // with space on the role (e.g. `VALID UNTIL`). func (o Option) ToString() string {
Looks like there's some precedence for the name SQLString
here, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @matthewtodd)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Looks like there's some precedence for the name
SQLString
here, WDYT?
Are you referring to the toSQLStmt mapping? I was thinking is just easier to understand/remember ToString
than ToSQLString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
Are you referring to the toSQLStmt mapping? I was thinking is just easier to understand/remember
ToString
thanToSQLString
I was talking about renaming this method to SQLString
. If you git grep SQLString pkg
there are some examples. I was thinking I would have a hard time understanding the difference between String
and ToString
from the names alone.
e511eaa
to
3520455
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @matthewtodd)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
I was talking about renaming this method to
SQLString
. If yougit grep SQLString pkg
there are some examples. I was thinking I would have a hard time understanding the difference betweenString
andToString
from the names alone.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
Done
on the other hand, now i wonder if we ever want to use the String()
method at all? should we just make String()
be the only one?
pkg/sql/roleoption/role_option.go, line 170 at r3 (raw file):
// with space on the role (e.g. `VALID UNTIL`). func (o Option) SQLString() string { return toSQLStringMap[o]
is VALID UNTIL the only one that needs to be handled differently?
i wonder if we should just add a special case here in this function, instead of making a whole new map that needs to be maintained separately (and might be easy to forget to update)
pkg/server/user_test.go, line 41 at r3 (raw file):
for name := range roleoption.ByName { _, err := s.(*TestServer).status.baseStatusServer.privilegeChecker.hasRoleOption(ctx, fooUser, roleoption.ByName[name]) require.NoError(t, err)
ah i didn't realize it was erroring before; i thought it was returning true/false incorrectly.
should we also add a test to make sure true/false is calculated correctly too? up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @matthewtodd, @rafiss, and @RichardJCai)
pkg/sql/roleoption/role_option.go, line 169 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
on the other hand, now i wonder if we ever want to use the
String()
method at all? should we just makeString()
be the only one?
Changed the original String function,using the //go:generate stringer -type=Option -linecomment
Thanks Rafi for the tip!
pkg/sql/roleoption/role_option.go, line 170 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
is VALID UNTIL the only one that needs to be handled differently?
i wonder if we should just add a special case here in this function, instead of making a whole new map that needs to be maintained separately (and might be easy to forget to update)
The only one different, so I added the comment on the role with the space
pkg/server/user_test.go, line 41 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
ah i didn't realize it was erroring before; i thought it was returning true/false incorrectly.
should we also add a test to make sure true/false is calculated correctly too? up to you
Add the check if the role existed after being added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 6 files at r4, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @maryliag and @rafiss)
-- commits, line 10 at r4:
That new //go:generate
line is awesome! Probably worth rewriting the commit message now? Otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks great! thanks for all the work on this
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @maryliag and @rafiss)
pkg/server/user_test.go, line 62 at r4 (raw file):
require.NoError(t, err) hasRole, err := s.(*TestServer).status.baseStatusServer.privilegeChecker.hasRoleOption(ctx, fooUser, roleoption.ByName[name])
this could also do a check using crdb_internal.has_role_option
directly, but not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @matthewtodd and @rafiss)
Previously, matthewtodd (Matthew Todd) wrote…
That new
//go:generate
line is awesome! Probably worth rewriting the commit message now? Otherwise
Updated
pkg/server/user_test.go, line 62 at r4 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
this could also do a check using
crdb_internal.has_role_option
directly, but not necessary
I prefer keeping the hasRole function because it does a few extra checks and in the end that was the funcional that was causing issues for me and I wanted to test.
Previously, the code was using roleOption.String() to create a string to be used on queries. This was causing an issue with roles that contained spaces within it, e.g. role option `VALIDUNTIL` was being translate to `VALIDUNTIL` instead of the correct way `VALID UNTIL`. This commit updates the String() function to correctly add the space on the `VALID UNTIL` case. Release note (bug fix): Update the String() function of roleOption to add a space on the role `VALID UNTIL`.
TFTR! bors r+ |
Build failed (retrying...): |
Build succeeded: |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 29211b6 to blathers/backport-release-21.1-75271: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 21.1.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
75274: ui: hide statement diagnostics when role VIEWACTIVITYREDACTED r=maryliag a=maryliag When the sql user has the role VIEWACTIVITYREDACTED, all the information about Statement Diagnostics Bundle will be hidden. That happens on: Statement - diagnostics column Statement Details - diagnostics tab Advanced Debug - diagnostics history Fixes #74817 Note: Can only be merged after #75271 and #75273 Release note (ui change): If the user has the role VIEWACTIVITYREDACTED, we hide the Statement Diagnostics bundle info on Statement page (diagnostics column), Statement Details page (diagnostics tab) and Advanced Debug page (diagnostics history). 75479: colflow: finish the span after closing the batch flow coordinator r=yuzefovich a=yuzefovich Previously, the coordinator would be closed after the tracing span is finished. However, this is incorrect in some cases where some components might use the span up until they are closed. This is now fixed by closing the coordinator before finishing the span. Fixes: #75425. Release note: None 75493: backupccl: give each restore goroutine its own rewriter r=dt a=dt Release note: none. 75506: migrations: bump size of `migrations` test r=rail a=rickystewart Release note: None Co-authored-by: Marylia Gutierrez <marylia@cockroachlabs.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com> Co-authored-by: David Taylor <tinystatemachine@gmail.com> Co-authored-by: Ricky Stewart <ricky@cockroachlabs.com>
Previously, the code was using roleOption.String() to
create a string to be used on queries. This was causing
an issue with roles that contained spaces within it,
e.g. role option
VALIDUNTIL
was being translate toVALIDUNTIL
instead of the correct wayVALID UNTIL
.This commit updates the String() function to correctly
add the space on the
VALID UNTIL
case.Release note (bug fix): Update the String() function of
roleOption to add a space on the role
VALID UNTIL
.