Skip to content

Commit

Permalink
server: add db and table grants apis by id routes
Browse files Browse the repository at this point in the history
This commit introduces apis to retrieve db and table
level grants.
The following GET routes have been introduced to api/v2:
- `api/v2/grants/databases/:database_id`
- `api/v2/grants/tables/:table_id`

Both provide pagination capabilities via URL query params:
- pageSize: int
- pageNum: int

Epic: CRDB-37558
Part of: #131211

Release note: None
  • Loading branch information
xinhaoz committed Sep 26, 2024
1 parent 72ad9e1 commit a943160
Show file tree
Hide file tree
Showing 4 changed files with 1,072 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"api_v2.go",
"api_v2_constants.go",
"api_v2_databases_metadata.go",
"api_v2_grants.go",
"api_v2_ranges.go",
"api_v2_sql.go",
"api_v2_sql_schema.go",
Expand Down Expand Up @@ -425,6 +426,7 @@ go_test(
size = "enormous",
srcs = [
"api_v2_databases_metadata_test.go",
"api_v2_grants_test.go",
"api_v2_ranges_test.go",
"api_v2_sql_schema_test.go",
"api_v2_sql_test.go",
Expand Down
8 changes: 8 additions & 0 deletions pkg/server/api_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ import (
"github.com/gorilla/mux"
)

// Path variables.
const (
dbIdPathVar = "database_id"
tableIdPathVar = "table_id"
)

type ApiV2System interface {
health(w http.ResponseWriter, r *http.Request)
listNodes(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -191,6 +197,8 @@ func registerRoutes(
{"table_metadata/", a.GetTableMetadata, true, authserver.RegularRole, true},
{"table_metadata/{table_id:[0-9]+}/", a.GetTableMetadataWithDetails, true, authserver.RegularRole, true},
{"table_metadata/updatejob/", a.TableMetadataJob, true, authserver.RegularRole, true},
{fmt.Sprintf("grants/databases/{%s:[0-9]+}/", dbIdPathVar), a.getDatabaseGrants, true, authserver.RegularRole, true},
{fmt.Sprintf("grants/tables/{%s:[0-9]+}/", tableIdPathVar), a.getTableGrants, true, authserver.RegularRole, true},
}

// For all routes requiring authentication, have the outer mux (a.mux)
Expand Down
Loading

0 comments on commit a943160

Please sign in to comment.