2022-07-17 13:41:54 -05:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/infra/filestorage"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2022-07-17 13:41:54 -05:00
|
|
|
)
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
type createPathFilterByAction func(ctx context.Context, user *user.SignedInUser, storageName string) map[string]filestorage.PathFilter
|
2022-07-17 13:41:54 -05:00
|
|
|
|
|
|
|
func newStaticStorageAuthService(createPathFilterByAction createPathFilterByAction) storageAuthService {
|
|
|
|
return &staticStorageAuth{
|
|
|
|
denyAllFileGuardian: &denyAllFileGuardian{},
|
|
|
|
createPathFilterByAction: createPathFilterByAction,
|
|
|
|
log: log.New("staticStorageAuthService"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type staticStorageAuth struct {
|
|
|
|
log log.Logger
|
|
|
|
denyAllFileGuardian fileGuardian
|
|
|
|
createPathFilterByAction createPathFilterByAction
|
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
func (a *staticStorageAuth) newGuardian(ctx context.Context, user *user.SignedInUser, storageName string) fileGuardian {
|
2022-07-17 13:41:54 -05:00
|
|
|
pathFilter := a.createPathFilterByAction(ctx, user, storageName)
|
|
|
|
|
|
|
|
if pathFilter == nil {
|
|
|
|
return a.denyAllFileGuardian
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pathFilterFileGuardian{
|
|
|
|
ctx: ctx,
|
|
|
|
user: user,
|
|
|
|
log: a.log,
|
|
|
|
prefix: storageName,
|
|
|
|
pathFilterByAction: pathFilter,
|
|
|
|
}
|
|
|
|
}
|