MCPcopy Create free account
hub / github.com/bytebase/bytebase / getInstanceRoles

Method getInstanceRoles

backend/plugin/db/cockroachdb/role.go:16–88  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

14)
15
16func (d *Driver) getInstanceRoles(ctx context.Context) ([]*storepb.InstanceRole, error) {
17 query := `
18 SELECT r.rolname, r.rolsuper, r.rolinherit, r.rolcreaterole, r.rolcreatedb, r.rolcanlogin, r.rolreplication, r.rolvaliduntil, r.rolbypassrls
19 FROM pg_catalog.pg_roles r
20 WHERE r.rolname !~ '^pg_';
21 `
22 var instanceRoles []*storepb.InstanceRole
23 if err := crdb.Execute(func() error {
24 rows, err := d.db.QueryContext(ctx, query)
25 if err != nil {
26 return err
27 }
28 defer rows.Close()
29 for rows.Next() {
30 var role string
31 var super, inherit, createRole, createDB, canLogin, replication, bypassRLS bool
32 var rolValidUntil sql.NullString
33 if err := rows.Scan(
34 &role,
35 &super,
36 &inherit,
37 &createRole,
38 &createDB,
39 &canLogin,
40 &replication,
41 &rolValidUntil,
42 &bypassRLS,
43 ); err != nil {
44 return err
45 }
46 if pgparser.IsSystemUser(role) {
47 continue
48 }
49
50 var attributes []string
51 if super {
52 attributes = append(attributes, "Superuser")
53 }
54 if !inherit {
55 attributes = append(attributes, "No inheritance")
56 }
57 if createRole {
58 attributes = append(attributes, "Create role")
59 }
60 if createDB {
61 attributes = append(attributes, "Create DB")
62 }
63 if !canLogin {
64 attributes = append(attributes, "Cannot login")
65 }
66 if replication {
67 attributes = append(attributes, "Replication")
68 }
69 if rolValidUntil.Valid {
70 attributes = append(attributes, fmt.Sprintf("Password valid until %s", rolValidUntil.String))
71 }
72 if bypassRLS {
73 attributes = append(attributes, "Bypass RLS+")

Callers 1

SyncInstanceMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 7

FormatErrorWithQueryFunction · 0.92
QueryContextMethod · 0.80
ScanMethod · 0.80
JoinMethod · 0.80
ExecuteMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected