core

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package core contains the central code for creating and reading blobs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobNode

type BlobNode struct {
	ID       uuid.UUID
	Size     int64 // ideally uint64, but ContentLength in http req is int64, so pointless
	MD5      values.MD5
	Stored   time.Time
	Filename string
	Format   string
	Owner    User
	Readers  *[]User
	Public   bool
}

BlobNode contains basic information about a blob stored in the blobstore.

type BlobStore

type BlobStore struct {
	// contains filtered or unexported fields
}

BlobStore is the storage system for blobs.

func New

func New(filestore filestore.FileStore, nodestore nodestore.NodeStore) *BlobStore

New creates a new blob store.

func NewWithUUIDGen

func NewWithUUIDGen(filestore filestore.FileStore, nodestore nodestore.NodeStore, uuidGen UUIDGen,
) *BlobStore

NewWithUUIDGen creates a new blob store with a provided UUID generator, which allows for easier testing.

func (*BlobStore) AddReaders

func (bs *BlobStore) AddReaders(user auth.User, id uuid.UUID, readerAccountNames []string,
) (*BlobNode, error)

AddReaders adds readers to a node. Has no effect if the user is the node's owner or the user is already in the read ACL. Returns NoBlobError and UnauthorizedACLError.

func (*BlobStore) ChangeOwner

func (bs *BlobStore) ChangeOwner(user auth.User, id uuid.UUID, newowner string,
) (*BlobNode, error)

ChangeOwner changes the owner of a node. If the new owner is in the read ACL, the new owner will be removed. Setting the new owner to the current owner has no effect. Returns NoBlobError and UnauthorizedACLError.

func (*BlobStore) CopyNode

func (bs *BlobStore) CopyNode(user auth.User, id uuid.UUID) (*BlobNode, error)

CopyNode makes a copy of the given node with an empty readers list. Returns NoBlobError and UnauthorizedError.

func (*BlobStore) DeleteNode

func (bs *BlobStore) DeleteNode(user auth.User, id uuid.UUID) error

DeleteNode deletes the given node. Returns NoBlobError and UnauthorizedError.

func (*BlobStore) Get

func (bs *BlobStore) Get(user *auth.User, id uuid.UUID) (*BlobNode, error)

Get gets details about a node. Returns NoBlobError and UnauthorizedError.

func (*BlobStore) GetFile

func (bs *BlobStore) GetFile(user *auth.User, id uuid.UUID, seek uint64, length uint64,
) (data io.ReadCloser, size int64, filename string, err error)

GetFile gets the file from a node. seek and length determine the byte range of the file returned. Passing 0 for length implies the remainder of the file should be returned. seeking beyond the file length will return an error, but requesting a file longer than the actual length is accepted and will return the remainder of the file. Returns NoBlobError, UnauthorizedError, and IllegalInputError.

func (*BlobStore) RemoveReaders

func (bs *BlobStore) RemoveReaders(user auth.User, id uuid.UUID, readerAccountNames []string,
) (*BlobNode, error)

RemoveReaders removes readers from a node. Has no effect if the user is not already in the read ACL. Returns NoBlobError and UnauthorizedACLError.

func (*BlobStore) SetNodePublic

func (bs *BlobStore) SetNodePublic(user auth.User, id uuid.UUID, public bool,
) (*BlobNode, error)

SetNodePublic sets whether a node can be read by anyone, including anonymous users. Returns NoBlobError and UnauthorizedACLError.

func (*BlobStore) Store

func (bs *BlobStore) Store(
	le *logrus.Entry,
	user auth.User,
	data io.Reader,
	size int64,
	filename values.FileName,
	format values.FileFormat,
) (*BlobNode, error)

Store stores a blob. The caller is responsible for closing the reader.

type NoBlobError

type NoBlobError string

NoBlobError is returned when a requested blob does not exist.

func NewNoBlobError

func NewNoBlobError(err string) *NoBlobError

NewNoBlobError creates a new NoBlobError.

func (*NoBlobError) Error

func (e *NoBlobError) Error() string

type UUIDGen

type UUIDGen interface {
	// GetUUID generates a random UUID.
	GetUUID() uuid.UUID
}

UUIDGen is an interface for a type that generates random UUIDs.

type UUIDGenDefault

type UUIDGenDefault struct{}

UUIDGenDefault generates uuids via the uuid.New() method.

func (*UUIDGenDefault) GetUUID

func (u *UUIDGenDefault) GetUUID() uuid.UUID

GetUUID generates a random UUID.

type UnauthorizedACLError

type UnauthorizedACLError string

UnauthorizedACLError is returned when a user may not alter a blob's ACLs in the manner requested.

func NewUnauthorizedACLError

func NewUnauthorizedACLError(err string) *UnauthorizedACLError

NewUnauthorizedACLError creates a new UnauthorizedACLError.

func (*UnauthorizedACLError) Error

func (e *UnauthorizedACLError) Error() string

type UnauthorizedError

type UnauthorizedError string

UnauthorizedError is returned when a user may not read a blob.

func NewUnauthorizedError

func NewUnauthorizedError(err string) *UnauthorizedError

NewUnauthorizedError creates a new UnauthorizedError.

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

type User

type User struct {
	// ID is the internal blobstore ID for the user.
	ID uuid.UUID
	// AccountName is the ID of the user in external systems.
	AccountName string
}

User is a user that may own or read Nodes.

Directories

Path Synopsis
Package values contains simple wrapper classes for value types, such as MD5 strings.
Package values contains simple wrapper classes for value types, such as MD5 strings.

Jump to

Keyboard shortcuts

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