db

package
v0.0.0-...-7cc0ef5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCredentials

func CheckCredentials(username, password string, s Storer) error

Check credentials in storage s. If they are valid credentials, this function returns nil. Otherwise it returns an error telling you what's wrong with the credentials.

Types

type FedEmbeddedStorage

type FedEmbeddedStorage struct {
	Filepath string
	// contains filtered or unexported fields
}

func (*FedEmbeddedStorage) Begin

func (fs *FedEmbeddedStorage) Begin() (Tx, error)

func (*FedEmbeddedStorage) Close

func (fs *FedEmbeddedStorage) Close() error

func (*FedEmbeddedStorage) DeleteObject

func (fs *FedEmbeddedStorage) DeleteObject(iri *url.URL) error

func (*FedEmbeddedStorage) Open

func (fs *FedEmbeddedStorage) Open() (err error)

func (*FedEmbeddedStorage) RetrieveCode

func (fs *FedEmbeddedStorage) RetrieveCode(code string) (*FedOAuthCode, error)

func (*FedEmbeddedStorage) RetrieveObject

func (fs *FedEmbeddedStorage) RetrieveObject(iri *url.URL) (obj vocab.Type, err error)

func (*FedEmbeddedStorage) RetrieveToken

func (fs *FedEmbeddedStorage) RetrieveToken(token string) (*FedOAuthToken, error)

func (*FedEmbeddedStorage) RetrieveUser

func (fs *FedEmbeddedStorage) RetrieveUser(username string) (user *FedUser, err error)

func (*FedEmbeddedStorage) StoreCode

func (fs *FedEmbeddedStorage) StoreCode(code *FedOAuthCode) error

func (*FedEmbeddedStorage) StoreObject

func (fs *FedEmbeddedStorage) StoreObject(iri *url.URL, obj vocab.Type) error

func (*FedEmbeddedStorage) StoreToken

func (fs *FedEmbeddedStorage) StoreToken(token *FedOAuthToken) error

func (*FedEmbeddedStorage) StoreUser

func (fs *FedEmbeddedStorage) StoreUser(user *FedUser) error

type FedEmptyStorage

type FedEmptyStorage struct{}

Implements FedStorage, Storer and Tx, but never returns any errors or actual content.

Can be used in tests where we do not want to retrieve anything from storage.

func (FedEmptyStorage) Begin

func (f FedEmptyStorage) Begin() (Tx, error)

func (FedEmptyStorage) Close

func (f FedEmptyStorage) Close() error

func (FedEmptyStorage) Commit

func (f FedEmptyStorage) Commit() error

func (FedEmptyStorage) DeleteObject

func (f FedEmptyStorage) DeleteObject(iri *url.URL) error

func (FedEmptyStorage) Open

func (f FedEmptyStorage) Open() error

func (FedEmptyStorage) RetrieveCode

func (f FedEmptyStorage) RetrieveCode(code string) (*FedOAuthCode, error)

func (FedEmptyStorage) RetrieveObject

func (f FedEmptyStorage) RetrieveObject(iri *url.URL) (vocab.Type, error)

func (FedEmptyStorage) RetrieveToken

func (f FedEmptyStorage) RetrieveToken(token string) (*FedOAuthToken, error)

func (FedEmptyStorage) RetrieveUser

func (f FedEmptyStorage) RetrieveUser(username string) (*FedUser, error)

func (FedEmptyStorage) Rollback

func (f FedEmptyStorage) Rollback() error

func (FedEmptyStorage) StoreCode

func (f FedEmptyStorage) StoreCode(code *FedOAuthCode) error

func (FedEmptyStorage) StoreObject

func (f FedEmptyStorage) StoreObject(iri *url.URL, obj vocab.Type) error

func (FedEmptyStorage) StoreToken

func (f FedEmptyStorage) StoreToken(token *FedOAuthToken) error

func (FedEmptyStorage) StoreUser

func (f FedEmptyStorage) StoreUser(user *FedUser) error

type FedOAuthCode

type FedOAuthCode struct {
	Code     string
	Username string
	IssuedOn time.Time
}

func NewFedOAuthCode

func NewFedOAuthCode(username, password string, target Storer) (*FedOAuthCode, error)

If username/password are valid credentials, create a new code, store it into target and return it.

func (*FedOAuthCode) Expired

func (c *FedOAuthCode) Expired() bool

Return whether this code is expired.

func (*FedOAuthCode) UnmarshalJSON

func (c *FedOAuthCode) UnmarshalJSON(data []byte) error

Unmarshal override to avoid confusion with FedOAuthToken.

type FedOAuthToken

type FedOAuthToken struct {
	Token    string
	Username string
	IssuedOn time.Time
}

func NewFedOAuthToken

func NewFedOAuthToken(username, password string, target Storer) (*FedOAuthToken, error)

If username/password are valid credentials, create a new token, store it into target and return it.

func NewFedOAuthTokenFor

func NewFedOAuthTokenFor(username string, target Storer) (*FedOAuthToken, error)

Create a new token for username, store it into target and return it.

func (*FedOAuthToken) Expired

func (c *FedOAuthToken) Expired() bool

Return whether this token is expired.

func (*FedOAuthToken) UnmarshalJSON

func (c *FedOAuthToken) UnmarshalJSON(data []byte) error

Unmarshal override to avoid confusion with FedOAuthCode.

type FedStorage

type FedStorage interface {
	// Open the underlying connection to the database. Before using
	// any of the other methods of a FedStorage,  call Open first.
	Open() error

	// Close the connection to the underlying database.
	Close() error

	// Start a new transaction. Remember to call Rollback or Commit!
	Begin() (Tx, error)

	// FedStorage implements Storer. Calling its methods creates
	// a single-operation transaction and automatically commits.
	Storer
}

Represents a connection to some database that takes care of storing all fed related data that isn't configuration, that is user meta data, active session tokens and the actual activities and objects.

FedStorage provides the Begin method which returns a transaction. A transaction combines any number of operations (as defined by Storer) and allows us to apply them atomically.

If you just want to run a single operation, you can also call the Storer methods directly.

type FedUser

type FedUser struct {
	Name           string
	PasswordSHA256 []byte

	Inbox     []*url.URL
	Outbox    []*url.URL
	Following []*url.URL
	Followers []*url.URL
	Liked     []*url.URL
}

Represents a user registered with the service.

func (*FedUser) Collections

func (u *FedUser) Collections() [][]*url.URL

Return a slice that contains all collections (i.e. Inbox, Outbox, Following, Followers and Liked).

func (*FedUser) HasLiked

func (u *FedUser) HasLiked(id *url.URL) bool

Returns whether this user liked whawtever is at id.

func (*FedUser) IsFollowedBy

func (u *FedUser) IsFollowedBy(id *url.URL) bool

Returns whether id is following this user.

func (*FedUser) IsFollowing

func (u *FedUser) IsFollowing(id *url.URL) bool

Returns whether this user is following whatever is at id.

func (*FedUser) PasswordOK

func (u *FedUser) PasswordOK(password string) bool

Return whether plaintext password, when hashed, matches the assigned password.

func (*FedUser) SetPassword

func (u *FedUser) SetPassword(password string)

Hash the plaintext password and assign the result to FedUser.PasswordSHA256.

func (*FedUser) String

func (u *FedUser) String() string

type Storer

type Storer interface {
	// Retrieve the metadata for a user with the given username.
	// If no such user exists, an error is returned.
	RetrieveUser(username string) (*FedUser, error)

	// Write metadata for user. If a user with matching user.Name
	// already exists, it is overwritten.
	StoreUser(user *FedUser) error

	// Retreive metadta for given code. If no such code is recorded
	// or if it is expired, an error is returned.
	RetrieveCode(code string) (*FedOAuthCode, error)

	// Write metadata for code. If a code with matching code.Code
	// already exists, it is overwritten.
	StoreCode(code *FedOAuthCode) error

	// Retreive metadta for given token. If no such token is recorded
	// or if it is expired, an error is returned.
	RetrieveToken(token string) (*FedOAuthToken, error)

	// Write metadata for token. If a token with matching token.Token
	// already exists, it is overwritten.
	StoreToken(token *FedOAuthToken) error

	// Retrieve the object at iri.
	RetrieveObject(iri *url.URL) (vocab.Type, error)

	// Write the object at iri. If there already is an object
	// stored at the given iri, it is overwritten.
	StoreObject(iri *url.URL, obj vocab.Type) error

	// Delete the object at iri.
	DeleteObject(iri *url.URL) error
}

Defines operations on a database required by fed.

type Tx

type Tx interface {
	// Commit all changes made within this transaction. You can
	// call this method as often as you want, only the first call
	// to Commit or Rollback for a given instance will be applied.
	Commit() error

	// Undo all changes made by this transaction. You can call
	// this method as often as you want, only the first call to Commit
	// or Rollback for a given instance will be applied.
	Rollback() error

	// Tx implements Storer. Calling its methods is only applied
	// after a successful call to Commit. If you wish to undo
	// the changes, call Rollback instead.
	Storer
}

A single transaction. Create one if you do operations on the database you may want to revert. You absolutly musn't forget to call either Commit or Rollback, otherwise fed will deadlock.

Jump to

Keyboard shortcuts

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