grantDatabase handles *GrantDatabase from within RowIter.
(ctx *sql.Context)
| 259 | |
| 260 | // grantDatabase handles *GrantDatabase from within RowIter. |
| 261 | func (g *Grant) grantDatabase(ctx *sql.Context) error { |
| 262 | roles, userRole, err := g.common(ctx) |
| 263 | if err != nil { |
| 264 | return err |
| 265 | } |
| 266 | for _, role := range roles { |
| 267 | for _, database := range g.GrantDatabase.Databases { |
| 268 | key := auth.DatabasePrivilegeKey{ |
| 269 | Role: userRole.ID(), |
| 270 | Name: database, |
| 271 | } |
| 272 | for _, privilege := range g.GrantDatabase.Privileges { |
| 273 | grantedBy := auth.HasDatabasePrivilegeGrantOption(key, privilege) |
| 274 | if !grantedBy.IsValid() { |
| 275 | // TODO: grab the actual error message |
| 276 | return errors.Errorf(`role "%s" does not have permission to grant this privilege`, userRole.Name) |
| 277 | } |
| 278 | auth.AddDatabasePrivilege(auth.DatabasePrivilegeKey{ |
| 279 | Role: role.ID(), |
| 280 | Name: database, |
| 281 | }, auth.GrantedPrivilege{ |
| 282 | Privilege: privilege, |
| 283 | GrantedBy: grantedBy, |
| 284 | }, g.WithGrantOption) |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | return nil |
| 289 | } |
| 290 | |
| 291 | // grantSequence handles *GrantSequence from within RowIter. |
| 292 | func (g *Grant) grantSequence(ctx *sql.Context) error { |
no test coverage detected