@@ -106,12 +106,12 @@ type columnsPrivRecord struct {
106106}
107107
108108// RoleGraphEdgesTable is used to cache relationship between and role.
109- type RoleGraphEdgesTable struct {
109+ type roleGraphEdgesTable struct {
110110 roleList map [string ]bool
111111}
112112
113113// Find method is used to find role from table
114- func (g RoleGraphEdgesTable ) Find (user , host string ) bool {
114+ func (g roleGraphEdgesTable ) Find (user , host string ) bool {
115115 if host == "" {
116116 host = "%"
117117 }
@@ -120,10 +120,7 @@ func (g RoleGraphEdgesTable) Find(user, host string) bool {
120120 return false
121121 }
122122 _ , ok := g .roleList [key ]
123- if ok {
124- return true
125- }
126- return false
123+ return ok
127124}
128125
129126// MySQLPrivilege is the in-memory cache of mysql privilege tables.
@@ -132,10 +129,10 @@ type MySQLPrivilege struct {
132129 DB []dbRecord
133130 TablesPriv []tablesPrivRecord
134131 ColumnsPriv []columnsPrivRecord
135- RoleGraph map [string ]RoleGraphEdgesTable
132+ RoleGraph map [string ]roleGraphEdgesTable
136133}
137134
138- // FindRole is used to detect whether this is an edge between user and role
135+ // FindRole is used to detect whether there is edges between users and roles.
139136func (p * MySQLPrivilege ) FindRole (user string , host string , role * auth.RoleIdentity ) bool {
140137 rec := p .matchUser (user , host )
141138 r := p .matchUser (role .Username , role .Hostname )
@@ -199,7 +196,7 @@ func noSuchTable(err error) bool {
199196
200197// LoadRoleGraph loads the mysql.role_edges table from database.
201198func (p * MySQLPrivilege ) LoadRoleGraph (ctx sessionctx.Context ) error {
202- p .RoleGraph = make (map [string ]RoleGraphEdgesTable )
199+ p .RoleGraph = make (map [string ]roleGraphEdgesTable )
203200 err := p .loadTable (ctx , "select FROM_USER, FROM_HOST, TO_USER, TO_HOST from mysql.role_edges;" , p .decodeRoleEdgesTable )
204201 if err != nil {
205202 return errors .Trace (err )
@@ -449,12 +446,12 @@ func (p *MySQLPrivilege) decodeRoleEdgesTable(row chunk.Row, fs []*ast.ResultFie
449446 }
450447 fromKey := fromUser + "@" + fromHost
451448 toKey := toUser + "@" + toHost
452- if _ , ok := p .RoleGraph [toKey ]; ok {
453- p .RoleGraph [toKey ].roleList [fromKey ] = true
454- } else {
455- p .RoleGraph [toKey ] = RoleGraphEdgesTable {roleList : make (map [string ]bool )}
456- p .RoleGraph [toKey ].roleList [fromKey ] = true
449+ roleGraph , ok := p .RoleGraph [toKey ]
450+ if ! ok {
451+ roleGraph = roleGraphEdgesTable {roleList : make (map [string ]bool )}
452+ p .RoleGraph [toKey ] = roleGraph
457453 }
454+ roleGraph .roleList [fromKey ] = true
458455 return nil
459456}
460457
0 commit comments