MCPcopy Create free account
hub / github.com/dolthub/doltgresql / grantRoutine

Method grantRoutine

server/node/grant.go:329–365  ·  view source on GitHub ↗

grantRoutine handles *GrantRoutine from within RowIter.

(ctx *sql.Context)

Source from the content-addressed store, hash-verified

327
328// grantRoutine handles *GrantRoutine from within RowIter.
329func (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.
368func (g *Grant) grantRole(ctx *sql.Context) error {

Callers 1

RowIterMethod · 0.95

Calls 7

commonMethod · 0.95
GetSchemaNameFunction · 0.92
AddRoutinePrivilegeFunction · 0.92
ErrorfMethod · 0.65
IDMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected