forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions.go
43 lines (36 loc) · 1.16 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
38
39
40
41
42
43
// 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/proto"
)
// GetPermissions lists the permissions on the mysqld
func GetPermissions(mysqld MysqlDaemon) (*proto.Permissions, error) {
permissions := &proto.Permissions{}
// get Users
qr, err := mysqld.FetchSuperQuery("SELECT * FROM mysql.user")
if err != nil {
return nil, err
}
for _, row := range qr.Rows {
permissions.UserPermissions = append(permissions.UserPermissions, proto.NewUserPermission(qr.Fields, row))
}
// get Dbs
qr, err = mysqld.FetchSuperQuery("SELECT * FROM mysql.db")
if err != nil {
return nil, err
}
for _, row := range qr.Rows {
permissions.DbPermissions = append(permissions.DbPermissions, proto.NewDbPermission(qr.Fields, row))
}
// get Hosts
qr, err = mysqld.FetchSuperQuery("SELECT * FROM mysql.host")
if err != nil {
return nil, err
}
for _, row := range qr.Rows {
permissions.HostPermissions = append(permissions.HostPermissions, proto.NewHostPermission(qr.Fields, row))
}
return permissions, nil
}