-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
74920: server: create new endpoint that return the roles of the sql user r=maryliag a=maryliag The commit creates a new endpoint `/sqlroles` that returns a list of roles of the SQL user logged in. Partially addresses #74817 Release note (api change): Creation of new endpoint `/sqlroles` that returns a list of the SQL roles for the SQL user logged in. 75088: sql: migrate has_sequence_privilege from evalPrivilegeCheck to ctx.Pl… r=otan a=ecwall …anner.HasPrivilege refs #66173 Migrate has_sequence_privilege from evalPrivilegeCheck to ctx.Planner.HasPrivilege. Release note: None 75116: bazel: update comments in `BUILD.bazel`, include reference to `dev -h` r=irfansharif a=rickystewart Most of this stuff is out-of-date at this point. Release note: None 75145: sql: deflake TestTelemetry r=rytaft a=rytaft This commit deflakes `TestTelemetry` by adding a more precise `feature-allowlist`. Fixes #75138 Release note: None 75149: cloud: close Reader before resetting in ResumingReader r=knz a=adityamaru This change `Close()`s the Reader before resetting it when we encounter a resumable error in the ResumingReader. This is particularly important for the http external storage provide, since forgetting to call Close() results in goroutine leaks from go1.17.6 onwards. See: golang/go#50652 Fixes: #75143 Release note: None Co-authored-by: Marylia Gutierrez <marylia@cockroachlabs.com> Co-authored-by: Evan Wall <wall@cockroachlabs.com> Co-authored-by: Ricky Stewart <ricky@cockroachlabs.com> Co-authored-by: Rebecca Taft <becca@cockroachlabs.com> Co-authored-by: Aditya Maru <adityamaru@gmail.com>
- Loading branch information
Showing
15 changed files
with
323 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// UserSQLRoles return a list of the logged in SQL user roles. | ||
func (s *baseStatusServer) UserSQLRoles( | ||
ctx context.Context, req *serverpb.UserSQLRolesRequest, | ||
) (_ *serverpb.UserSQLRolesResponse, retErr error) { | ||
ctx = propagateGatewayMetadata(ctx) | ||
ctx = s.AnnotateCtx(ctx) | ||
username, err := userFromContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
it, err := s.sqlServer.internalExecutor.QueryIteratorEx( | ||
ctx, "sqlroles", nil, /* txn */ | ||
sessiondata.InternalExecutorOverride{User: username}, | ||
"SELECT option FROM system.role_options WHERE username=$1", username, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// We have to make sure to close the iterator since we might return from the | ||
// for loop early (before Next() returns false). | ||
defer func() { retErr = errors.CombineErrors(retErr, it.Close()) }() | ||
|
||
ok, err := it.Next(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp serverpb.UserSQLRolesResponse | ||
if !ok { | ||
// The query returned 0 rows. | ||
return &resp, nil | ||
} | ||
scanner := makeResultScanner(it.Types()) | ||
for ; ok; ok, err = it.Next(ctx) { | ||
row := it.Cur() | ||
var role string | ||
err = scanner.ScanIndex(row, 0, &role) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp.Roles = append(resp.Roles, role) | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} |
Oops, something went wrong.