accounts

package
v4.15.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: AGPL-3.0 Imports: 6 Imported by: 3

Documentation

Overview

Package accounts implements tools to manage account information for Mr. Plotter. Account information is stored in etcd, so a Version 3 etcd client is needed for most of the API functions.

Index

Constants

View Source
const PublicTag = "public"

PublicTag is the name of the t ag used to specify streams viewable to all users, even those who are not logged in.

Variables

This section is empty.

Functions

func DeleteAccount

func DeleteAccount(ctx context.Context, etcdClient *etcd.Client, username string) error

Deletes the account of the user with the provided username.

func DeleteMultipleAccounts

func DeleteMultipleAccounts(ctx context.Context, etcdClient *etcd.Client, usernameprefix string) (int64, error)

Deletes the accounts of all users whose username begins with the provided prefix.

func DeleteMultipleTagDefs

func DeleteMultipleTagDefs(ctx context.Context, etcdClient *etcd.Client, tagprefix string) (int64, error)

Deletes all tag definitions beginning with the given prefix.

func DeleteTagDef

func DeleteTagDef(ctx context.Context, etcdClient *etcd.Client, tag string) error

Deletes the tag definition with the provided name

func GetAccountEtcdPath

func GetAccountEtcdPath() string

Gets the base path for account data in etcd.

func GetTagEtcdPath

func GetTagEtcdPath() string

Gets the base path for tag definitions in etcd.

func SetEtcdKeyPrefix

func SetEtcdKeyPrefix(prefix string)

Sets the prefix added to keys in the etcd database. The keys used are of the form <prefix>mrplotter/accounts/<username>. The prefix allows multiple configurations for Mr. Plotter to coexist in a single etcd database system.

Modifying the prefix while an operation is in progress results in undefined behavior. Furthermore, MrPlotterAccount structs returned by RetrieveAccount or RetrieveMultipleAccounts must always be used with the same prefix with which they were generated.

func UpsertAccount

func UpsertAccount(ctx context.Context, etcdClient *etcd.Client, acc *MrPlotterAccount) error

Updates the account according to the provided account information, creating a new user account if a user with that username does not exist.

func UpsertAccountAtomically

func UpsertAccountAtomically(ctx context.Context, etcdClient *etcd.Client, acc *MrPlotterAccount) (bool, error)

Same as UpsertAccount, but fails if the account was updated meanwhile. This allows one to ensure that the read-modify-write operation required to update account information can be done atomically. Returns true if the operation succeeds, and returns false otherwise.

The rules are as follows: if the MrPlotterAccount struct was created directly, the operation fails if the account already exists in etcd. If the MrPlotterAccount struct was returned by RetrieveAccount or RetrieveMultipleAccounts, the operation fails if the data stored in etcd was updated after the account information was retrieved. You should not modify the "Username" field of a struct returned by RetrieveAccount or RetrieveMultipleAccounts and then use it with this function. Setting the "Username" field of a struct to be used with this function is only allowed for structs that are created directly.

func UpsertTagDef

func UpsertTagDef(ctx context.Context, etcdClient *etcd.Client, tdef *MrPlotterTagDef) error

Same as UpsertAccount, but for Tag Definitions

func UpsertTagDefAtomically

func UpsertTagDefAtomically(ctx context.Context, etcdClient *etcd.Client, tdef *MrPlotterTagDef) (bool, error)

Same as UpsertAccountAtomically, but for Tag Definitions.

Types

type MrPlotterAccount

type MrPlotterAccount struct {
	Username     string
	Tags         map[string]struct{}
	PasswordHash []byte
	// contains filtered or unexported fields
}

MrPlotterAccount abstracts account information for a single user.

func RetrieveAccount

func RetrieveAccount(ctx context.Context, etcdClient *etcd.Client, username string) (acc *MrPlotterAccount, err error)

Retrieves the account information for the specified user. Setting the "Username" field in the returned struct renders it unsuitable for use with the "UpsertAccountAtomically" function.

func RetrieveMultipleAccounts

func RetrieveMultipleAccounts(ctx context.Context, etcdClient *etcd.Client, usernameprefix string) ([]*MrPlotterAccount, error)

Retrieves the account information of all users whose username begins with the provided prefix. If one entry is in a corrupt state and cannot be decoded, its Tags set will be set to nil and decoding will continue. Setting the "Username" field in the returned struct renders it unsuitable for use with the "UpsertAccountAtomically" function.

func (*MrPlotterAccount) CheckPassword

func (acc *MrPlotterAccount) CheckPassword(password []byte) (bool, error)

Checks whether the provided password matches the user's password. Returns true if the provided password is correct, and false if it is not. If the returned error is not nil, then the returned boolean should be ignored.

func (*MrPlotterAccount) GetRetrievedRevision

func (acc *MrPlotterAccount) GetRetrievedRevision() int64

func (*MrPlotterAccount) SetPassword

func (acc *MrPlotterAccount) SetPassword(newPassword []byte) error

Sets the password for a user.

func (*MrPlotterAccount) SetRetrievedRevision

func (acc *MrPlotterAccount) SetRetrievedRevision(rev int64)

type MrPlotterTagDef

type MrPlotterTagDef struct {
	Tag        string
	PathPrefix map[string]struct{}
	// contains filtered or unexported fields
}

MrPlotterTagDef abstracts a mapping from a Tag to set of collection prefixes.

func RetrieveMultipleTagDefs

func RetrieveMultipleTagDefs(ctx context.Context, etcdClient *etcd.Client, tagprefix string) ([]*MrPlotterTagDef, error)

Retrieves the account information of all users whose username begins with the provided prefix. If one entry is in a corrupt state and cannot be decoded, its Tags set will be set to nil and decoding will continue. Setting the "Username" field in the returned struct renders it unsuitable for use with the "UpsertAccountAtomically" function.

func RetrieveTagDef

func RetrieveTagDef(ctx context.Context, etcdClient *etcd.Client, tag string) (tdef *MrPlotterTagDef, err error)

Retrieves the tag definition for the specified tag. Setting the "Tag" field in the returned struct renders it unsuitable for use with the "UpsertTagDefAtomically" function.

func (*MrPlotterTagDef) GetRetrievedRevision

func (tdef *MrPlotterTagDef) GetRetrievedRevision() int64

func (*MrPlotterTagDef) SetRetrievedRevision

func (tdef *MrPlotterTagDef) SetRetrievedRevision(rev int64)

Jump to

Keyboard shortcuts

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