store

package
v0.0.1-test Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionFilesRead   = "files:read"
	ActionFilesWrite  = "files:write"
	ActionFilesDelete = "files:delete"
)
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"
View Source
const SystemBrandingStorage = "system/" + brandingStorage

Variables

View Source
var (
	SystemBrandingReader = &user.SignedInUser{OrgID: ac.GlobalOrgID}
	SystemBrandingAdmin  = &user.SignedInUser{OrgID: ac.GlobalOrgID}
)
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 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 ProvideEntityEventsService

func ProvideEntityEventsService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, 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 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,
) StorageService

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

Jump to

Keyboard shortcuts

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