Documentation ¶
Index ¶
- func FileName(filename string) func(*Node) error
- func Format(format string) func(*Node) error
- func Public(public bool) func(*Node) error
- func Reader(user User) func(*Node) error
- type MongoNodeStore
- func (s *MongoNodeStore) AddReader(id uuid.UUID, user User) error
- func (s *MongoNodeStore) ChangeOwner(id uuid.UUID, user User) error
- func (s *MongoNodeStore) DeleteNode(id uuid.UUID) error
- func (s *MongoNodeStore) GetNode(id uuid.UUID) (*Node, error)
- func (s *MongoNodeStore) GetUser(accountName string) (*User, error)
- func (s *MongoNodeStore) RemoveReader(id uuid.UUID, user User) error
- func (s *MongoNodeStore) SetNodePublic(id uuid.UUID, public bool) error
- func (s *MongoNodeStore) StoreNode(node *Node) error
- type NoNodeError
- type Node
- func (n *Node) GetFileName() string
- func (n *Node) GetFormat() string
- func (n *Node) GetID() uuid.UUID
- func (n *Node) GetMD5() values.MD5
- func (n *Node) GetOwner() User
- func (n *Node) GetPublic() bool
- func (n *Node) GetReaders() *[]User
- func (n *Node) GetSize() int64
- func (n *Node) GetStoredTime() time.Time
- func (n *Node) HasReader(user User) bool
- func (n *Node) WithOwner(user User) *Node
- func (n *Node) WithPublic(public bool) *Node
- func (n *Node) WithReaders(readers ...User) *Node
- func (n *Node) WithoutReaders(readers ...User) *Node
- type NodeStore
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format provides an arbitrary file format (e.g. json, txt) to the NewStoreFileParams() method.
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 ¶
GetFileName gets the name of the file associated with the node, if any.
func (*Node) GetReaders ¶
GetReaders gets the IDs of users that may read the node.
func (*Node) GetStoredTime ¶
GetStoredTime returns the time the file associated with the node was stored.
func (*Node) HasReader ¶
HasReader returns true if the given user exists in the node's list of readers.
func (*Node) WithOwner ¶
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 ¶
WithPublic returns a copy of the node with the public flag set as specified.
func (*Node) WithReaders ¶
WithReaders returns a copy of the node with the sepecified readers added.
func (*Node) WithoutReaders ¶
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 ¶
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 ¶
GetAccountName returns the user's name in external systems.