getUsersFromUserAttributes reads users from information_schema.user_attributes, returns the list of users with format "' '@' '".
(ctx context.Context)
| 71 | |
| 72 | // getUsersFromUserAttributes reads users from information_schema.user_attributes, returns the list of users with format "'<user>'@'<host>'". |
| 73 | func (d *Driver) getUsersFromUserAttributes(ctx context.Context) ([]string, error) { |
| 74 | var users []string |
| 75 | query := ` |
| 76 | SELECT |
| 77 | user, |
| 78 | host |
| 79 | FROM information_schema.user_attributes |
| 80 | WHERE user <> '' |
| 81 | AND user NOT LIKE 'mysql.%' |
| 82 | ` |
| 83 | roleRows, err := d.db.QueryContext(ctx, query) |
| 84 | if err != nil { |
| 85 | return nil, errors.Wrapf(err, "failed to query information_schema.user_attributes") |
| 86 | } |
| 87 | defer roleRows.Close() |
| 88 | for roleRows.Next() { |
| 89 | var user string |
| 90 | var host string |
| 91 | if err := roleRows.Scan( |
| 92 | &user, |
| 93 | &host, |
| 94 | ); err != nil { |
| 95 | return nil, err |
| 96 | } |
| 97 | users = append(users, fmt.Sprintf("'%s'@'%s'", user, host)) |
| 98 | } |
| 99 | if err := roleRows.Err(); err != nil { |
| 100 | return nil, errors.Wrapf(err, "failed to iterate information_schema.user_attributes") |
| 101 | } |
| 102 | return users, nil |
| 103 | } |
| 104 | |
| 105 | // getUsersFromMySQLUser reads users from mysql.user, returns the list of users with format "'<user>'@'<host>'". |
| 106 | func (d *Driver) getUsersFromMySQLUser(ctx context.Context) ([]string, error) { |
no test coverage detected