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

Method grantDatabase

server/node/grant.go:261–289  ·  view source on GitHub ↗

grantDatabase handles *GrantDatabase from within RowIter.

(ctx *sql.Context)

Source from the content-addressed store, hash-verified

259
260// grantDatabase handles *GrantDatabase from within RowIter.
261func (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.
292func (g *Grant) grantSequence(ctx *sql.Context) error {

Callers 1

RowIterMethod · 0.95

Calls 6

commonMethod · 0.95
AddDatabasePrivilegeFunction · 0.92
ErrorfMethod · 0.65
IDMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected