grantRoutine handles *GrantRoutine from within RowIter.
(ctx *sql.Context)
| 327 | |
| 328 | // grantRoutine handles *GrantRoutine from within RowIter. |
| 329 | func (g *Grant) grantRoutine(ctx *sql.Context) error { |
| 330 | roles, userRole, err := g.common(ctx) |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | for _, role := range roles { |
| 335 | for _, routine := range g.GrantRoutine.Routines { |
| 336 | schemaName, err := core.GetSchemaName(ctx, nil, routine.Schema) |
| 337 | if err != nil { |
| 338 | return err |
| 339 | } |
| 340 | key := auth.RoutinePrivilegeKey{ |
| 341 | Role: userRole.ID(), |
| 342 | Schema: schemaName, |
| 343 | Name: routine.Name, |
| 344 | ArgTypes: routine.ArgTypes, |
| 345 | } |
| 346 | for _, privilege := range g.GrantRoutine.Privileges { |
| 347 | grantedBy := auth.HasRoutinePrivilegeGrantOption(key, privilege) |
| 348 | if !grantedBy.IsValid() { |
| 349 | // TODO: grab the actual error message |
| 350 | return errors.Errorf(`role "%s" does not have permission to grant this privilege`, userRole.Name) |
| 351 | } |
| 352 | auth.AddRoutinePrivilege(auth.RoutinePrivilegeKey{ |
| 353 | Role: role.ID(), |
| 354 | Schema: schemaName, |
| 355 | Name: routine.Name, |
| 356 | ArgTypes: routine.ArgTypes, |
| 357 | }, auth.GrantedPrivilege{ |
| 358 | Privilege: privilege, |
| 359 | GrantedBy: grantedBy, |
| 360 | }, g.WithGrantOption) |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | return nil |
| 365 | } |
| 366 | |
| 367 | // grantRole handles *GrantRole from within RowIter. |
| 368 | func (g *Grant) grantRole(ctx *sql.Context) error { |
no test coverage detected