filestorage

package
v0.0.0-kmdagger3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRelativePath          = errors.New("path cant be relative")
	ErrNonCanonicalPath      = errors.New("path must be canonical")
	ErrPathTooLong           = errors.New("path is too long")
	ErrInvalidCharacters     = errors.New("path contains unsupported characters")
	ErrPathEndsWithDelimiter = errors.New("path can not end with delimiter")
	ErrPathPartTooLong       = errors.New("path part is too long")
	ErrEmptyPathPart         = errors.New("path can not have empty parts")
	Delimiter                = "/"
	DirectoryMimeType        = "directory"
)

Functions

func Join

func Join(parts ...string) string

func ValidatePath

func ValidatePath(path string) error

Types

type DeleteFolderOptions

type DeleteFolderOptions struct {
	// Force if set to true, the `deleteFolder` operation will delete the selected folder together with all the nested files & folders
	Force bool

	// AccessFilter must match all the nested files & folders in order for the `deleteFolder` operation to succeed
	// The access check is not performed if `AccessFilter` is nil
	AccessFilter PathFilter
}

type File

type File struct {
	Contents []byte
	FileMetadata
}

func (*File) IsFolder

func (f *File) IsFolder() bool

type FileMetadata

type FileMetadata struct {
	Name       string
	FullPath   string
	MimeType   string
	Modified   time.Time
	Created    time.Time
	Size       int64
	Properties map[string]string
}

type FileStorage

type FileStorage interface {
	Get(ctx context.Context, path string, options *GetFileOptions) (*File, bool, error)
	Delete(ctx context.Context, path string) error
	Upsert(ctx context.Context, command *UpsertFileCommand) error

	// List lists only files without content by default
	List(ctx context.Context, folderPath string, paging *Paging, options *ListOptions) (*ListResponse, error)

	CreateFolder(ctx context.Context, path string) error
	DeleteFolder(ctx context.Context, path string, options *DeleteFolderOptions) error
	// contains filtered or unexported methods
}

func NewCdkBlobStorage

func NewCdkBlobStorage(log log.Logger, bucket *blob.Bucket, rootFolder string, filter PathFilter) FileStorage

func NewDbStorage

func NewDbStorage(log log.Logger, db db.DB, filter PathFilter, rootFolder string) FileStorage

type GetFileOptions

type GetFileOptions struct {
	// WithContents if set to false, the `Get` operation will return just the file metadata. Default is `true`
	WithContents bool
}

type ListOptions

type ListOptions struct {
	Recursive    bool
	WithFiles    bool
	WithFolders  bool
	WithContents bool
	Filter       PathFilter
}

type ListResponse

type ListResponse struct {
	Files    []*File
	HasMore  bool
	LastPath string
}

func (*ListResponse) String

func (r *ListResponse) String() string

type MockFileStorage

type MockFileStorage struct {
	mock.Mock
}

MockFileStorage is an autogenerated mock type for the FileStorage type

func (*MockFileStorage) CreateFolder

func (_m *MockFileStorage) CreateFolder(ctx context.Context, path string) error

CreateFolder provides a mock function with given fields: ctx, path

func (*MockFileStorage) Delete

func (_m *MockFileStorage) Delete(ctx context.Context, path string) error

Delete provides a mock function with given fields: ctx, path

func (*MockFileStorage) DeleteFolder

func (_m *MockFileStorage) DeleteFolder(ctx context.Context, path string, options *DeleteFolderOptions) error

DeleteFolder provides a mock function with given fields: ctx, path, options

func (*MockFileStorage) Get

func (_m *MockFileStorage) Get(ctx context.Context, path string, options *GetFileOptions) (*File, bool, error)

Get provides a mock function with given fields: ctx, path, options

func (*MockFileStorage) List

func (_m *MockFileStorage) List(ctx context.Context, folderPath string, paging *Paging, options *ListOptions) (*ListResponse, error)

List provides a mock function with given fields: ctx, folderPath, paging, options

func (*MockFileStorage) Upsert

func (_m *MockFileStorage) Upsert(ctx context.Context, command *UpsertFileCommand) error

Upsert provides a mock function with given fields: ctx, command

type Paging

type Paging struct {
	After string
	First int
}

type PathFilter

type PathFilter interface {
	IsAllowed(path string) bool
	ToString() string
	// contains filtered or unexported methods
}

func NewAllowAllPathFilter

func NewAllowAllPathFilter() PathFilter

func NewAndPathFilter

func NewAndPathFilter(filters ...PathFilter) PathFilter

func NewDenyAllPathFilter

func NewDenyAllPathFilter() PathFilter

func NewPathFilter

func NewPathFilter(allowedPrefixes []string, allowedPaths []string, disallowedPrefixes []string, disallowedPaths []string) PathFilter

NewPathFilter factory function for a tree-based PathFilter `nil` and empty arrays are treated in a different way. The PathFilter will not perform checks associated with a `nil` array, examples:

  • `allowedPrefixes` & `allowedPaths` are nil -> all paths are allowed (unless included in `disallowedX` arrays)
  • `allowedPrefixes` & `allowedPaths` are both empty -> no paths are allowed, regardless of what is inside `disallowedX` arrays
  • `allowedPrefixes` is nil, `allowedPaths` is not nil. -> only paths specified in `allowedPaths` are allowed (unless included in `disallowedX` arrays)

type UpsertFileCommand

type UpsertFileCommand struct {
	Path               string
	MimeType           string
	CacheControl       string
	ContentDisposition string

	// Contents of an existing file won't be modified if cmd.Contents is nil
	Contents []byte
	// Properties of an existing file won't be modified if cmd.Properties is nil
	Properties map[string]string
}

Jump to

Keyboard shortcuts

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