store

package
v0.0.0-test.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2023 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionFilesRead   = "files:read"
	ActionFilesWrite  = "files:write"
	ActionFilesDelete = "files:delete"
)
View Source
const (
	QuotaTargetSrv quota.TargetSrv = "store"
	QuotaTarget    quota.Target    = "file"
)
View Source
const MAX_UPLOAD_SIZE = 1 * 1024 * 1024 // 3MB
View Source
const RootContent = "content"
View Source
const RootDevenv = "devenv"
View Source
const RootPublicStatic = "public-static"
View Source
const RootResources = "resources"
View Source
const RootSystem = "system"

Variables

View Source
var ErrAccessDenied = errors.New("access denied")
View Source
var ErrFileAlreadyExists = errors.New("file exists")
View Source
var ErrOnlyDashboardSaveSupported = errors.New("only dashboard save is currently supported")
View Source
var ErrQuotaReached = errors.New("file quota reached")
View Source
var ErrStorageNotFound = errors.New("storage not found")
View Source
var ErrUnsupportedStorage = errors.New("storage does not support this operation")
View Source
var ErrUploadInternalError = errors.New("upload internal error")
View Source
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 GuessNameFromUID(uid string) string

func UploadErrorToStatusCode

func UploadErrorToStatusCode(err error) int

Types

type CreateFolderCmd

type CreateFolderCmd struct {
	Path string `json:"path"`
}

type DeleteFolderCmd

type DeleteFolderCmd struct {
	Path  string `json:"path"`
	Force bool   `json:"force"`
}

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

type FakeSystemUsers struct {
	mock.Mock
}

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

type MockEntityEventsService struct {
	mock.Mock
}

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

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 NewMockEntityEventsServiceT

type NewMockEntityEventsServiceT interface {
	mock.TestingT
	Cleanup(func())
}

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 RootStorageMeta struct {
	ReadOnly bool          `json:"editable,omitempty"`
	Builtin  bool          `json:"builtin,omitempty"`
	Ready    bool          `json:"ready"` // can connect
	Notice   []data.Notice `json:"notice,omitempty"`

	Config RootStorageConfig `json:"config"`
}

type SaveEventCmd

type SaveEventCmd struct {
	EntityId  string
	EventType EntityEventType
}

type StorageGCSConfig

type StorageGCSConfig struct {
	Bucket string `json:"bucket"`
	Folder string `json:"folder"`

	CredentialsFile string `json:"credentialsFile"`
}

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

type StorageListFrame struct {
	*data.Frame
}

func (*StorageListFrame) GetFileNames

func (s *StorageListFrame) GetFileNames() []string

type StorageLocalDiskConfig

type StorageLocalDiskConfig struct {
	Path  string   `json:"path"`
	Roots []string `json:"roots,omitempty"` // null is everything
}

type StorageS3Config

type StorageS3Config struct {
	Bucket string `json:"bucket"`
	Folder string `json:"folder"`

	// SECURE!!!
	AccessKey string `json:"accessKey"`
	SecretKey string `json:"secretKey"`
	Region    string `json:"region"`
}

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 UploadRequest struct {
	Contents           []byte
	Path               string
	CacheControl       string
	ContentDisposition string
	Properties         map[string]string
	EntityType         EntityType

	OverwriteExistingFile bool
}

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 WriteValueResponse struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	URL     string `json:"url,omitempty"`
	Hash    string `json:"hash,omitempty"`
	Branch  string `json:"branch,omitempty"`
	Pending bool   `json:"pending,omitempty"`
	Size    int64  `json:"size,omitempty"`
}

type WriteValueWorkflow

type WriteValueWorkflow = string
var (
	WriteValueWorkflow_Save WriteValueWorkflow = "save" // or empty
	WriteValueWorkflow_PR   WriteValueWorkflow = "pr"
	WriteValueWorkflow_Push WriteValueWorkflow = "push"
)

Directories

Path Synopsis
dummy
Package dummy provides a dummy kind useful for testing
Package dummy provides a dummy kind useful for testing
png
svg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL