(addr proto.AccountAddress, dbID proto.DatabaseID, queryType types.QueryType, queries []types.Query)
| 582 | } |
| 583 | |
| 584 | func (dbms *DBMS) checkPermission(addr proto.AccountAddress, |
| 585 | dbID proto.DatabaseID, queryType types.QueryType, queries []types.Query) (err error) { |
| 586 | log.Debugf("in checkPermission, database id: %s, user addr: %s", dbID, addr.String()) |
| 587 | |
| 588 | var ( |
| 589 | permStat *types.PermStat |
| 590 | ok bool |
| 591 | ) |
| 592 | |
| 593 | // get database perm stat |
| 594 | permStat, ok = dbms.busService.RequestPermStat(dbID, addr) |
| 595 | |
| 596 | // perm stat not exists |
| 597 | if !ok { |
| 598 | err = errors.Wrap(ErrPermissionDeny, "database not exists") |
| 599 | return |
| 600 | } |
| 601 | |
| 602 | // check if query is enabled |
| 603 | if !permStat.Status.EnableQuery() { |
| 604 | err = errors.Wrapf(ErrPermissionDeny, "cannot query, status: %d", permStat.Status) |
| 605 | return |
| 606 | } |
| 607 | |
| 608 | // check query type permission |
| 609 | switch queryType { |
| 610 | case types.ReadQuery: |
| 611 | if !permStat.Permission.HasReadPermission() { |
| 612 | err = errors.Wrapf(ErrPermissionDeny, "cannot read, permission: %v", permStat.Permission) |
| 613 | return |
| 614 | } |
| 615 | case types.WriteQuery: |
| 616 | if !permStat.Permission.HasWritePermission() { |
| 617 | err = errors.Wrapf(ErrPermissionDeny, "cannot write, permission: %v", permStat.Permission) |
| 618 | return |
| 619 | } |
| 620 | default: |
| 621 | err = errors.Wrapf(ErrInvalidPermission, |
| 622 | "invalid permission, permission: %v", permStat.Permission) |
| 623 | return |
| 624 | } |
| 625 | |
| 626 | // check for query pattern |
| 627 | var ( |
| 628 | disallowedQuery string |
| 629 | hasDisallowedQuery bool |
| 630 | ) |
| 631 | |
| 632 | if disallowedQuery, hasDisallowedQuery = permStat.Permission.HasDisallowedQueryPatterns(queries); hasDisallowedQuery { |
| 633 | err = errors.Wrapf(ErrPermissionDeny, "disallowed query %s", disallowedQuery) |
| 634 | log.WithError(err).WithFields(log.Fields{ |
| 635 | "permission": permStat.Permission, |
| 636 | "query": disallowedQuery, |
| 637 | }).Debug("can not query") |
| 638 | return |
| 639 | } |
| 640 | |
| 641 | return |
no test coverage detected