Documentation
¶
Index ¶
- Constants
- Variables
- func CreateDatabaseEntityId(internalId interface{}, orgId int64, entityType EntityType) string
- func GetUserIDString(user *user.SignedInUser) string
- func GuessNameFromUID(uid string) string
- func UploadErrorToStatusCode(err error) int
- type CreateFolderCmd
- type DeleteFolderCmd
- type EntityEvent
- type EntityEventType
- type EntityEventsService
- type EntityType
- type EventHandler
- type FakeSystemUsers
- func (_m *FakeSystemUsers) GetFilter(_a0 *user.SignedInUser) (map[string]filestorage.PathFilter, error)
- func (_m *FakeSystemUsers) GetUser(userType SystemUserType, orgID int64) (*user.SignedInUser, error)
- func (_m *FakeSystemUsers) RegisterUser(userType SystemUserType, filterFn func() map[string]filestorage.PathFilter)
- type GlobalStorageConfig
- type MockEntityEventsService
- func (_m *MockEntityEventsService) GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
- func (_m *MockEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEvent, error)
- func (_m *MockEntityEventsService) IsDisabled() bool
- func (_m *MockEntityEventsService) OnEvent(handler EventHandler)
- func (_m *MockEntityEventsService) Run(ctx context.Context) error
- func (_m *MockEntityEventsService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error
- type NewMockEntityEventsServiceT
- type RootStorageConfig
- type RootStorageMeta
- type SaveEventCmd
- type StorageGCSConfig
- type StorageGitConfig
- type StorageListFrame
- type StorageLocalDiskConfig
- type StorageS3Config
- type StorageSQLConfig
- type StorageService
- type SystemUserType
- type SystemUsers
- type SystemUsersFilterProvider
- type SystemUsersProvider
- type UploadRequest
- type WriteValueRequest
- type WriteValueResponse
- type WriteValueWorkflow
Constants ¶
const ( ActionFilesRead = "files:read" ActionFilesWrite = "files:write" ActionFilesDelete = "files:delete" )
const ( QuotaTargetSrv quota.TargetSrv = "store" QuotaTarget quota.Target = "file" )
const MAX_UPLOAD_SIZE = 1 * 1024 * 1024 // 3MB
const RootContent = "content"
const RootDevenv = "devenv"
const RootPublicStatic = "public-static"
const RootResources = "resources"
const RootSystem = "system"
Variables ¶
var ErrAccessDenied = errors.New("access denied")
var ErrFileAlreadyExists = errors.New("file exists")
var ErrOnlyDashboardSaveSupported = errors.New("only dashboard save is currently supported")
var ErrQuotaReached = errors.New("file quota reached")
var ErrStorageNotFound = errors.New("storage not found")
var ErrUnsupportedStorage = errors.New("storage does not support this operation")
var ErrUploadInternalError = errors.New("upload internal error")
var ErrValidationFailed = errors.New("request validation failed")
Functions ¶
func CreateDatabaseEntityId ¶
func CreateDatabaseEntityId(internalId interface{}, orgId int64, entityType EntityType) string
CreateDatabaseEntityId creates entityId for entities stored in the existing SQL tables
func GetUserIDString ¶
func GetUserIDString(user *user.SignedInUser) string
Really just spitballing here :) this should hook into a system that can give better display info
func GuessNameFromUID ¶
func UploadErrorToStatusCode ¶
Types ¶
type CreateFolderCmd ¶
type CreateFolderCmd struct {
Path string `json:"path"`
}
type DeleteFolderCmd ¶
type EntityEvent ¶
type EntityEvent struct {
Id int64
EventType EntityEventType
EntityId string
Created int64
}
type EntityEventType ¶
type EntityEventType string
const ( EntityEventTypeDelete EntityEventType = "delete" EntityEventTypeCreate EntityEventType = "create" EntityEventTypeUpdate EntityEventType = "update" )
type EntityEventsService ¶
type EntityEventsService interface {
registry.BackgroundService
registry.CanBeDisabled
GetLastEvent(ctx context.Context) (*EntityEvent, error)
GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
// contains filtered or unexported methods
}
EntityEventsService is a temporary solution to support change notifications in an HA setup With this service each system can query for any events that have happened since a fixed time
func NewDummyEntityEventsService ¶
func NewDummyEntityEventsService() EntityEventsService
func ProvideEntityEventsService ¶
func ProvideEntityEventsService(cfg *setting.Cfg, sqlStore db.DB, features featuremgmt.FeatureToggles) EntityEventsService
type EntityType ¶
type EntityType string
const ( EntityTypeDashboard EntityType = "dashboard" EntityTypeFolder EntityType = "folder" EntityTypeImage EntityType = "image" EntityTypeJSON EntityType = "json" )
type EventHandler ¶
type EventHandler func(ctx context.Context, e *EntityEvent) error
type FakeSystemUsers ¶
FakeSystemUsers is an autogenerated mock type for the SystemUsers type
func NewFakeSystemUsers ¶
func NewFakeSystemUsers(t mockConstructorTestingTNewFakeSystemUsers) *FakeSystemUsers
NewFakeSystemUsers creates a new instance of FakeSystemUsers. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func (*FakeSystemUsers) GetFilter ¶
func (_m *FakeSystemUsers) GetFilter(_a0 *user.SignedInUser) (map[string]filestorage.PathFilter, error)
GetFilter provides a mock function with given fields: _a0
func (*FakeSystemUsers) GetUser ¶
func (_m *FakeSystemUsers) GetUser(userType SystemUserType, orgID int64) (*user.SignedInUser, error)
GetUser provides a mock function with given fields: userType, orgID
func (*FakeSystemUsers) RegisterUser ¶
func (_m *FakeSystemUsers) RegisterUser(userType SystemUserType, filterFn func() map[string]filestorage.PathFilter)
RegisterUser provides a mock function with given fields: userType, filterFn
type GlobalStorageConfig ¶
type GlobalStorageConfig struct {
// Defined in grafana.ini
AllowUnsanitizedSvgUpload bool `json:"allowUnsanitizedSvgUpload"`
// Add dev environment
AddDevEnv bool `json:"addDevEnv"`
// Paths under 'root' (NOTE: this is applied to all orgs)
Roots []RootStorageConfig `json:"roots"`
// contains filtered or unexported fields
}
For now this file is stored in $GRAFANA_HOME/conf/storage.json and updated from the UI
func LoadStorageConfig ¶
func LoadStorageConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles) (*GlobalStorageConfig, error)
type MockEntityEventsService ¶
MockEntityEventsService is an autogenerated mock type for the EntityEventsService type
func NewMockEntityEventsService ¶
func NewMockEntityEventsService(t NewMockEntityEventsServiceT) *MockEntityEventsService
NewMockEntityEventsService creates a new instance of MockEntityEventsService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func (*MockEntityEventsService) GetAllEventsAfter ¶
func (_m *MockEntityEventsService) GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
GetAllEventsAfter provides a mock function with given fields: ctx, id
func (*MockEntityEventsService) GetLastEvent ¶
func (_m *MockEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEvent, error)
GetLastEvent provides a mock function with given fields: ctx
func (*MockEntityEventsService) IsDisabled ¶
func (_m *MockEntityEventsService) IsDisabled() bool
IsDisabled provides a mock function with given fields:
func (*MockEntityEventsService) OnEvent ¶
func (_m *MockEntityEventsService) OnEvent(handler EventHandler)
OnEvent provides a mock function with given fields: handler
func (*MockEntityEventsService) Run ¶
func (_m *MockEntityEventsService) Run(ctx context.Context) error
Run provides a mock function with given fields: ctx
func (*MockEntityEventsService) SaveEvent ¶
func (_m *MockEntityEventsService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error
SaveEvent provides a mock function with given fields: ctx, cmd
type RootStorageConfig ¶
type RootStorageConfig struct {
Type string `json:"type"`
Prefix string `json:"prefix"`
UnderContentRoot bool `json:"underContentRoot"`
Name string `json:"name"`
Description string `json:"description"`
Disabled bool `json:"disabled,omitempty"`
// Depending on type, these will be configured
Disk *StorageLocalDiskConfig `json:"disk,omitempty"`
Git *StorageGitConfig `json:"git,omitempty"`
SQL *StorageSQLConfig `json:"sql,omitempty"`
S3 *StorageS3Config `json:"s3,omitempty"`
GCS *StorageGCSConfig `json:"gcs,omitempty"`
}
type RootStorageMeta ¶
type SaveEventCmd ¶
type SaveEventCmd struct {
EntityId string
EventType EntityEventType
}
type StorageGCSConfig ¶
type StorageGitConfig ¶
type StorageGitConfig struct {
Remote string `json:"remote"`
Branch string `json:"branch"`
Root string `json:"root"` // subfolder within the remote
// Pull interval?
// Requires pull request?
RequirePullRequest bool `json:"requirePullRequest"`
PullInterval string `json:"pullInterval"`
// SECURE JSON :grimicing:
AccessToken string `json:"accessToken,omitempty"` // Simplest auth method for github
}
type StorageListFrame ¶
func (*StorageListFrame) GetFileNames ¶
func (s *StorageListFrame) GetFileNames() []string
type StorageLocalDiskConfig ¶
type StorageS3Config ¶
type StorageSQLConfig ¶
type StorageSQLConfig struct {
}
type StorageService ¶
type StorageService interface {
registry.BackgroundService
// Register the HTTP
RegisterHTTPRoutes(routing.RouteRegister)
// List folder contents
List(ctx context.Context, user *user.SignedInUser, path string) (*StorageListFrame, error)
// Read raw file contents out of the store
Read(ctx context.Context, user *user.SignedInUser, path string) (*filestorage.File, error)
Upload(ctx context.Context, user *user.SignedInUser, req *UploadRequest) error
Delete(ctx context.Context, user *user.SignedInUser, path string) error
DeleteFolder(ctx context.Context, user *user.SignedInUser, cmd *DeleteFolderCmd) error
CreateFolder(ctx context.Context, user *user.SignedInUser, cmd *CreateFolderCmd) error
// contains filtered or unexported methods
}
func ProvideService ¶
func ProvideService( sql db.DB, features featuremgmt.FeatureToggles, cfg *setting.Cfg, quotaService quota.Service, systemUsersService SystemUsers, ) (StorageService, error)
type SystemUserType ¶
type SystemUserType string
type SystemUsers ¶
type SystemUsers interface {
SystemUsersFilterProvider
SystemUsersProvider
// RegisterUser extension point - allows other Grafana services to register their own user type and assign them path-based permissions
RegisterUser(userType SystemUserType, filterFn func() map[string]filestorage.PathFilter)
}
func ProvideSystemUsersService ¶
func ProvideSystemUsersService() SystemUsers
type SystemUsersFilterProvider ¶
type SystemUsersFilterProvider interface {
GetFilter(user *user.SignedInUser) (map[string]filestorage.PathFilter, error)
}
SystemUsersFilterProvider interface internal to `pkg/store` service. Used by the Storage service to retrieve path filter for system users
type SystemUsersProvider ¶
type SystemUsersProvider interface {
GetUser(userType SystemUserType, orgID int64) (*user.SignedInUser, error)
}
SystemUsersProvider interface used by `pkg/store` clients Used by Grafana services to retrieve users having access only to their own slice of storage For example, service 'Dashboard' could have exclusive access to paths matching `system/dashboard/*` by creating a system user with appropriate permissions.
type UploadRequest ¶
type WriteValueRequest ¶
type WriteValueRequest struct {
User *user.SignedInUser
Path string // added from URL
EntityType EntityType `json:"kind,omitempty"` // for now only dashboard
Body json.RawMessage `json:"body,omitempty"`
Message string `json:"message,omitempty"`
Title string `json:"title,omitempty"` // For PRs
Workflow WriteValueWorkflow `json:"workflow,omitempty"` // save | pr | push
}
type WriteValueResponse ¶
type WriteValueWorkflow ¶
type WriteValueWorkflow = string
var ( WriteValueWorkflow_Save WriteValueWorkflow = "save" // or empty WriteValueWorkflow_PR WriteValueWorkflow = "pr" WriteValueWorkflow_Push WriteValueWorkflow = "push" )