grafana/pkg/services/thumbs/crawler_auth.go
Artur Wierzbicki a4381ebc91
Previews: create crawler auth setup service (#47349)
* #46968: add `RetrieveServiceAccountIdByName` to serviceaccounts service

* #46968: improve error logging in rendering service

* #46968: add oss crawler account setup

* #46968: fix tests

* #46968: switch back to ROLE_ADMIN

* #46968: rename to crawlerAuth

* comment crawler_auth.go
2022-04-12 19:34:04 +02:00

42 lines
1016 B
Go

package thumbs
import (
"context"
"github.com/grafana/grafana/pkg/models"
)
type CrawlerAuthSetupService interface {
Setup(ctx context.Context) (CrawlerAuth, error)
}
func ProvideCrawlerAuthSetupService() *OSSCrawlerAuthSetupService {
return &OSSCrawlerAuthSetupService{}
}
type OSSCrawlerAuthSetupService struct{}
type CrawlerAuth interface {
GetUserId(orgId int64) int64
GetOrgRole() models.RoleType
}
type staticCrawlerAuth struct {
userId int64
orgRole models.RoleType
}
func (o *staticCrawlerAuth) GetOrgRole() models.RoleType {
return o.orgRole
}
func (o *staticCrawlerAuth) GetUserId(orgId int64) int64 {
return o.userId
}
func (o *OSSCrawlerAuthSetupService) Setup(ctx context.Context) (CrawlerAuth, error) {
// userId:0 and ROLE_ADMIN grants the crawler process permissions to view all dashboards in all folders & orgs
// the process doesn't and shouldn't actually need to edit/modify any resources from the UI
return &staticCrawlerAuth{userId: 0, orgRole: models.ROLE_ADMIN}, nil
}