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

Method getInstanceRoles

backend/plugin/db/tidb/role.go:15–45  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

13)
14
15func (d *Driver) getInstanceRoles(ctx context.Context) []*storepb.InstanceRole {
16 var instanceRoles []*storepb.InstanceRole
17 var users []string
18 var err error
19 users, err = d.getUsersFromMySQLUser(ctx)
20 if err != nil {
21 slog.Info("failed to get users", log.BBError(err))
22 users, err = d.getUsersFromUserAttributes(ctx)
23 if err != nil {
24 slog.Info("failed to get users", log.BBError(err))
25 return nil
26 }
27 }
28
29 // Uses single quote instead of backtick to escape because this is a string
30 // instead of table (which should use backtick instead). MySQL actually works
31 // in both ways. On the other hand, some other MySQL compatible engines might not (OceanBase in this case).
32 for _, name := range users {
33 grantList, err := d.getGrantFromUser(ctx, name)
34 if err != nil {
35 slog.Info("failed to get grants for user", slog.String("user", name), log.BBError(err))
36 continue
37 }
38 attribute := strings.Join(grantList, "\n")
39 instanceRoles = append(instanceRoles, &storepb.InstanceRole{
40 Name: name,
41 Attribute: &attribute,
42 })
43 }
44 return instanceRoles
45}
46
47// getGrantFromUser reads grants for user with format "'<user>'@'<host>'".
48func (d *Driver) getGrantFromUser(ctx context.Context, name string) ([]string, error) {

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

getUsersFromMySQLUserMethod · 0.95
getGrantFromUserMethod · 0.95
BBErrorFunction · 0.92
InfoMethod · 0.80
JoinMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected