2021-12-20 02:52:24 -06:00
|
|
|
package resourcepermissions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-25 10:12:00 -06:00
|
|
|
|
2022-02-03 09:27:05 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
2022-01-25 10:12:00 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
2021-12-20 02:52:24 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type ResourceValidator func(ctx context.Context, orgID int64, resourceID string) error
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
// Resource is the action and scope prefix that is generated
|
|
|
|
Resource string
|
2021-12-21 07:22:54 -06:00
|
|
|
// OnlyManaged will tell the service to return all permissions if set to false and only managed permissions if set to true
|
|
|
|
OnlyManaged bool
|
2021-12-20 02:52:24 -06:00
|
|
|
// ResourceValidator is a validator function that will be called before each assignment.
|
|
|
|
// If set to nil the validator will be skipped
|
|
|
|
ResourceValidator ResourceValidator
|
|
|
|
// Assignments decides what we can assign permissions to (users/teams/builtInRoles)
|
|
|
|
Assignments Assignments
|
|
|
|
// PermissionsToAction is a map of friendly named permissions and what access control actions they should generate.
|
|
|
|
// E.g. Edit permissions should generate dashboards:read, dashboards:write and dashboards:delete
|
|
|
|
PermissionsToActions map[string][]string
|
|
|
|
// ReaderRoleName is the display name for the generated fixed reader role
|
|
|
|
ReaderRoleName string
|
|
|
|
// WriterRoleName is the display name for the generated fixed writer role
|
|
|
|
WriterRoleName string
|
|
|
|
// RoleGroup is the group name for the generated fixed roles
|
|
|
|
RoleGroup string
|
2021-12-23 03:10:06 -06:00
|
|
|
// OnSetUser if configured will be called each time a permission is set for a user
|
2022-02-03 09:27:05 -06:00
|
|
|
OnSetUser func(session *sqlstore.DBSession, orgID int64, user accesscontrol.User, resourceID, permission string) error
|
2021-12-23 03:10:06 -06:00
|
|
|
// OnSetTeam if configured will be called each time a permission is set for a team
|
2022-01-25 10:12:00 -06:00
|
|
|
OnSetTeam func(session *sqlstore.DBSession, orgID, teamID int64, resourceID, permission string) error
|
2021-12-23 03:10:06 -06:00
|
|
|
// OnSetBuiltInRole if configured will be called each time a permission is set for a built-in role
|
2022-01-25 10:12:00 -06:00
|
|
|
OnSetBuiltInRole func(session *sqlstore.DBSession, orgID int64, builtInRole, resourceID, permission string) error
|
2022-02-10 10:47:48 -06:00
|
|
|
// UidSolver if configured will be used in a middleware to translate an uid to id for each request
|
|
|
|
UidSolver uidSolver
|
2021-12-20 02:52:24 -06:00
|
|
|
}
|