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

Method getInstanceRoles

backend/plugin/db/pg/role.go:14–82  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

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

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 6

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

Tested by

no test coverage detected