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

server: use HTTP query parameter cluster for manual selection #106122

Merged
merged 1 commit into from
Jul 5, 2023
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
6 changes: 3 additions & 3 deletions pkg/cli/democluster/demo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1928,8 +1928,8 @@ func (c *transientCluster) ListDemoNodes(w, ew io.Writer, justOne, verbose bool)
if !c.demoCtx.Multitenant || verbose {
// Connection parameters for the system tenant follow.
uiURL := s.Cfg.AdminURL()
if q := uiURL.Query(); c.demoCtx.Multitenant && !c.demoCtx.DisableServerController && !q.Has(server.TenantNameParamInQueryURL) {
q.Add(server.TenantNameParamInQueryURL, catconstants.SystemTenantName)
if q := uiURL.Query(); c.demoCtx.Multitenant && !c.demoCtx.DisableServerController && !q.Has(server.ClusterNameParamInQueryURL) {
q.Add(server.ClusterNameParamInQueryURL, catconstants.SystemTenantName)
uiURL.RawQuery = q.Encode()
}

Expand Down Expand Up @@ -2011,7 +2011,7 @@ func (c *transientCluster) addDemoLoginToURL(uiURL *url.URL, includeTenantName b
}

if !includeTenantName {
q.Del(server.TenantNameParamInQueryURL)
q.Del(server.ClusterNameParamInQueryURL)
}

uiURL.RawQuery = q.Encode()
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/interactive_tests/test_demo_cli_integration.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ eexpect ":/# "
# Check that the cookies work.
set pyfile [file join [file dirname $argv0] test_auth_cookie.py]

send "$python $pyfile cookie_system.txt 'http://localhost:8080/_admin/v1/users?tenant_name=system'\r"
send "$python $pyfile cookie_system.txt 'http://localhost:8080/_admin/v1/users?cluster=system'\r"
eexpect "username"
eexpect "demo"
# No tenant name specified -> use default tenant.
Expand All @@ -190,7 +190,7 @@ eexpect "defaultdb>"

set spawn_id $shell_spawn_id

send "$python $pyfile cookie_system.txt 'http://localhost:8080/_admin/v1/users?tenant_name=system'\r"
send "$python $pyfile cookie_system.txt 'http://localhost:8080/_admin/v1/users?cluster=system'\r"
eexpect "username"
eexpect "demo"
# No tenant name specified -> use default tenant.
Expand Down
7 changes: 4 additions & 3 deletions pkg/server/server_controller_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const (
// TenantSelectHeader is the HTTP header used to select a particular tenant.
TenantSelectHeader = `X-Cockroach-Tenant`

// TenantNameParamInQueryURL is the HTTP query URL parameter used to select a particular tenant.
TenantNameParamInQueryURL = "tenant_name"
// ClusterNameParamInQueryURL is the HTTP query URL parameter used
// to select a particular virtual cluster.
ClusterNameParamInQueryURL = "cluster"

// TenantSelectCookieName is the name of the HTTP cookie used to select a particular tenant,
// if the custom header is not specified.
Expand Down Expand Up @@ -109,7 +110,7 @@ func (c *serverController) httpMux(w http.ResponseWriter, r *http.Request) {

func getTenantNameFromHTTPRequest(st *cluster.Settings, r *http.Request) roachpb.TenantName {
// Highest priority is manual override on the URL query parameters.
if tenantName := r.URL.Query().Get(TenantNameParamInQueryURL); tenantName != "" {
if tenantName := r.URL.Query().Get(ClusterNameParamInQueryURL); tenantName != "" {
return roachpb.TenantName(tenantName)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/testserver_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (ts *httpTestServer) AdminURL() string {
u := ts.t.sqlServer.execCfg.RPCContext.Config.AdminURL()
if ts.t.tenantName != "" {
q := u.Query()
q.Add(TenantNameParamInQueryURL, string(ts.t.tenantName))
q.Add(ClusterNameParamInQueryURL, string(ts.t.tenantName))
u.RawQuery = q.Encode()
}
return u.String()
Expand Down