nodestore

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileName

func FileName(filename string) func(*Node) error

FileName provides an arbitrary file name to the NewStoreFileParams() method.

func Format

func Format(format string) func(*Node) error

Format provides an arbitrary file format (e.g. json, txt) to the NewStoreFileParams() method.

func Public

func Public(public bool) func(*Node) error

Public sets the node to publicly readable or not.

func Reader

func Reader(user User) func(*Node) error

Reader adds a user to the node's read ACL.

Types

type MongoNodeStore

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

MongoNodeStore is a storage system for blobstore nodes using Mongo as the underlying database.

func NewMongoNodeStore

func NewMongoNodeStore(db *mongo.Database) (*MongoNodeStore, error)

NewMongoNodeStore creates a new node store given a MongoDB database for storing node data.

func (*MongoNodeStore) AddReader

func (s *MongoNodeStore) AddReader(id uuid.UUID, user User) error

AddReader adds a user to a node's read ACL. The caller is responsible for ensuring the user is valid - retrieving the user via GetUser() is the proper way to do so. Has no effect if the user is already in the read ACL. Returns NoNodeError if the node does not exist.

func (*MongoNodeStore) ChangeOwner

func (s *MongoNodeStore) ChangeOwner(id uuid.UUID, user User) error

ChangeOwner changes the owner of a node. The caller is responsible for ensuring the user is valid - retrieving the user via GetUser() is the proper way to do so. Adds the new owner the the read acl. Setting the new owner to the current owner has no effect. Returns NoNodeError if the node does not exist.

func (*MongoNodeStore) DeleteNode

func (s *MongoNodeStore) DeleteNode(id uuid.UUID) error

DeleteNode deletes a node.

func (*MongoNodeStore) GetNode

func (s *MongoNodeStore) GetNode(id uuid.UUID) (*Node, error)

GetNode gets a node. Returns NoNodeError if the node does not exist.

func (*MongoNodeStore) GetUser

func (s *MongoNodeStore) GetUser(accountName string) (*User, error)

GetUser gets a user. If the user does not exist in the system, a new ID will be assigned to the user.

func (*MongoNodeStore) RemoveReader

func (s *MongoNodeStore) RemoveReader(id uuid.UUID, user User) error

RemoveReader removes a user from the node's read ACL. Has no effect if the user is not in the read ACL or is the node owner. Returns NoNodeError if the node does not exist.

func (*MongoNodeStore) SetNodePublic

func (s *MongoNodeStore) SetNodePublic(id uuid.UUID, public bool) error

SetNodePublic sets whether a node can be read by anyone, including anonymous users. Returns NoNodeError if the node does not exist.

func (*MongoNodeStore) StoreNode

func (s *MongoNodeStore) StoreNode(node *Node) error

StoreNode stores a node. The caller is responsible for ensuring any users are valid - retrieving users via GetUser() is the proper way to do so. Attempting to store Nodes with the same ID is an error.

type NoNodeError

type NoNodeError string

NoNodeError is returned when a node doesn't exist.

func NewNoNodeError

func NewNoNodeError(err string) *NoNodeError

NewNoNodeError creates a new NoNodeError.

func (*NoNodeError) Error

func (e *NoNodeError) Error() string

type Node

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

Node is a collection of data about a file, including ACLs.

func NewNode

func NewNode(
	id uuid.UUID,
	owner User,
	size int64,
	md5 values.MD5,
	stored time.Time,
	options ...func(*Node) error) (*Node, error)

NewNode creates a new node. The owner is automatically added to the reader list.

func (*Node) GetFileName

func (n *Node) GetFileName() string

GetFileName gets the name of the file associated with the node, if any.

func (*Node) GetFormat

func (n *Node) GetFormat() string

GetFormat gets the format of the file associated with the node, if any.

func (*Node) GetID

func (n *Node) GetID() uuid.UUID

GetID returns the node's ID.

func (*Node) GetMD5

func (n *Node) GetMD5() values.MD5

GetMD5 returns the MD5 of the file associated with the node.

func (*Node) GetOwner

func (n *Node) GetOwner() User

GetOwner returns the node's owner ID.

func (*Node) GetPublic

func (n *Node) GetPublic() bool

GetPublic gets whether the node is publicly readable or not.

func (*Node) GetReaders

func (n *Node) GetReaders() *[]User

GetReaders gets the IDs of users that may read the node.

func (*Node) GetSize

func (n *Node) GetSize() int64

GetSize returns the size of the file associated with the node.

func (*Node) GetStoredTime

func (n *Node) GetStoredTime() time.Time

GetStoredTime returns the time the file associated with the node was stored.

func (*Node) HasReader

func (n *Node) HasReader(user User) bool

HasReader returns true if the given user exists in the node's list of readers.

func (*Node) WithOwner

func (n *Node) WithOwner(user User) *Node

WithOwner returns a copy of the node with the owner as specified. The new owner will also be added to the readers list.

func (*Node) WithPublic

func (n *Node) WithPublic(public bool) *Node

WithPublic returns a copy of the node with the public flag set as specified.

func (*Node) WithReaders

func (n *Node) WithReaders(readers ...User) *Node

WithReaders returns a copy of the node with the sepecified readers added.

func (*Node) WithoutReaders

func (n *Node) WithoutReaders(readers ...User) *Node

WithoutReaders returns a copy of the node without the sepecified readers. If any of the readers are the node's owner, they are not removed from the list.

type NodeStore

type NodeStore interface {

	// GetUser gets a user. If the user does not exist in the system, a new ID will be assigned
	// to the user.
	GetUser(accountName string) (*User, error)

	// StoreNode stores a node.
	// The caller is responsible for ensuring any users are valid - retrieving users via
	// GetUser() is the proper way to do so.
	// Attempting to store Nodes with the same ID is an error.
	StoreNode(node *Node) error

	// GetNode gets a node. Returns NoNodeError if the node does not exist.
	GetNode(id uuid.UUID) (*Node, error)

	// DeleteNode deletes a node. Returns NoNodeError if the node does not exist.
	DeleteNode(id uuid.UUID) error

	// SetNodePublic sets whether a node can be read by anyone, including anonymous users.
	// Returns NoNodeError if the node does not exist.
	SetNodePublic(id uuid.UUID, public bool) error

	// AddReader adds a user to a node's read ACL.
	// The caller is responsible for ensuring the user is valid - retrieving the user via
	// GetUser() is the proper way to do so.
	// Has no effect if the user is already in the read ACL.
	// Returns NoNodeError if the node does not exist.
	AddReader(id uuid.UUID, user User) error

	// RemoveReader removes a user from the node's read ACL.
	// Has no effect if the user is not in the read ACL or is the node owner.
	// Returns NoNodeError if the node does not exist.
	RemoveReader(id uuid.UUID, user User) error

	// ChangeOwner changes the owner of a node.
	// The caller is responsible for ensuring the user is valid - retrieving the user via
	// GetUser() is the proper way to do so.
	// Adds the new owner to the the read acl.
	// Setting the new owner to the current owner has no effect.
	// Returns NoNodeError if the node does not exist.
	ChangeOwner(id uuid.UUID, user User) error
}

NodeStore stores node information.

type User

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

User is a user that may own or read Nodes.

func NewUser

func NewUser(id uuid.UUID, accountName string) (*User, error)

NewUser creates a new user. The ID is a UUID assigned to the user by the system at first sight, and accountName is the name of the user in external systems.

func (*User) GetAccountName

func (u *User) GetAccountName() string

GetAccountName returns the user's name in external systems.

func (*User) GetID

func (u *User) GetID() uuid.UUID

GetID returns the user's system ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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