-
Notifications
You must be signed in to change notification settings - Fork 2k
/
permissions.go
37 lines (31 loc) · 1.08 KB
/
permissions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mysqlctl
import (
"github.com/youtube/vitess/go/vt/mysqlctl/tmutils"
tabletmanagerdatapb "github.com/youtube/vitess/go/vt/proto/tabletmanagerdata"
"golang.org/x/net/context"
)
// GetPermissions lists the permissions on the mysqld
func GetPermissions(mysqld MysqlDaemon) (*tabletmanagerdatapb.Permissions, error) {
ctx := context.TODO()
permissions := &tabletmanagerdatapb.Permissions{}
// get Users
qr, err := mysqld.FetchSuperQuery(ctx, "SELECT * FROM mysql.user")
if err != nil {
return nil, err
}
for _, row := range qr.Rows {
permissions.UserPermissions = append(permissions.UserPermissions, tmutils.NewUserPermission(qr.Fields, row))
}
// get Dbs
qr, err = mysqld.FetchSuperQuery(ctx, "SELECT * FROM mysql.db")
if err != nil {
return nil, err
}
for _, row := range qr.Rows {
permissions.DbPermissions = append(permissions.DbPermissions, tmutils.NewDbPermission(qr.Fields, row))
}
return permissions, nil
}