postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Err3PIDInUse = errors.New("This third-party identifier is already in use")

Err3PIDInUse is the error returned when trying to save an association involving a third-party identifier which is already associated to a local user.

Functions

This section is empty.

Types

type Database

type Database struct {
	sqlutil.PartitionOffsetStatements
	// contains filtered or unexported fields
}

Database represents an account database

func NewDatabase

func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserverlib.ServerName, bcryptCost int, openIDTokenLifetimeMS int64) (*Database, error)

NewDatabase creates a new accounts and profiles database

func (*Database) CheckAccountAvailability

func (d *Database) CheckAccountAvailability(ctx context.Context, localpart string) (bool, error)

CheckAccountAvailability checks if the username/localpart is already present in the database. If the DB returns sql.ErrNoRows the Localpart isn't taken.

func (*Database) CountBackupKeys added in v0.5.0

func (d *Database) CountBackupKeys(
	ctx context.Context, version, userID string,
) (count int64, err error)

func (*Database) CreateAccount

func (d *Database) CreateAccount(
	ctx context.Context, localpart, plaintextPassword, appserviceID string,
) (acc *api.Account, err error)

CreateAccount makes a new account with the given login name and password, and creates an empty profile for this account. If no password is supplied, the account will be a passwordless account. If the account already exists, it will return nil, sqlutil.ErrUserExists.

func (*Database) CreateGuestAccount

func (d *Database) CreateGuestAccount(ctx context.Context) (acc *api.Account, err error)

CreateGuestAccount makes a new guest account and creates an empty profile for this account.

func (*Database) CreateKeyBackup added in v0.5.0

func (d *Database) CreateKeyBackup(
	ctx context.Context, userID, algorithm string, authData json.RawMessage,
) (version string, err error)

func (*Database) CreateOpenIDToken added in v0.4.0

func (d *Database) CreateOpenIDToken(
	ctx context.Context,
	token, localpart string,
) (int64, error)

CreateOpenIDToken persists a new token that was issued through OpenID Connect

func (*Database) DeactivateAccount

func (d *Database) DeactivateAccount(ctx context.Context, localpart string) (err error)

DeactivateAccount deactivates the user's account, removing all ability for the user to login again.

func (*Database) DeleteKeyBackup added in v0.5.0

func (d *Database) DeleteKeyBackup(
	ctx context.Context, userID, version string,
) (exists bool, err error)

func (*Database) GetAccountByLocalpart

func (d *Database) GetAccountByLocalpart(ctx context.Context, localpart string,
) (*api.Account, error)

GetAccountByLocalpart returns the account associated with the given localpart. This function assumes the request is authenticated or the account data is used only internally. Returns sql.ErrNoRows if no account exists which matches the given localpart.

func (*Database) GetAccountByPassword

func (d *Database) GetAccountByPassword(
	ctx context.Context, localpart, plaintextPassword string,
) (*api.Account, error)

GetAccountByPassword returns the account associated with the given localpart and password. Returns sql.ErrNoRows if no account exists which matches the given localpart.

func (*Database) GetAccountData

func (d *Database) GetAccountData(ctx context.Context, localpart string) (
	global map[string]json.RawMessage,
	rooms map[string]map[string]json.RawMessage,
	err error,
)

GetAccountData returns account data related to a given localpart If no account data could be found, returns an empty arrays Returns an error if there was an issue with the retrieval

func (*Database) GetAccountDataByType

func (d *Database) GetAccountDataByType(
	ctx context.Context, localpart, roomID, dataType string,
) (data json.RawMessage, err error)

GetAccountDataByType returns account data matching a given localpart, room ID and type. If no account data could be found, returns nil Returns an error if there was an issue with the retrieval

func (*Database) GetBackupKeys added in v0.5.0

func (d *Database) GetBackupKeys(
	ctx context.Context, version, userID, filterRoomID, filterSessionID string,
) (result map[string]map[string]api.KeyBackupSession, err error)

func (*Database) GetKeyBackup added in v0.5.0

func (d *Database) GetKeyBackup(
	ctx context.Context, userID, version string,
) (versionResult, algorithm string, authData json.RawMessage, etag string, deleted bool, err error)

func (*Database) GetLocalpartForThreePID

func (d *Database) GetLocalpartForThreePID(
	ctx context.Context, threepid string, medium string,
) (localpart string, err error)

GetLocalpartForThreePID looks up the localpart associated with a given third-party identifier. If no association involves the given third-party idenfitier, returns an empty string. Returns an error if there was a problem talking to the database.

func (*Database) GetNewNumericLocalpart

func (d *Database) GetNewNumericLocalpart(
	ctx context.Context,
) (int64, error)

GetNewNumericLocalpart generates and returns a new unused numeric localpart

func (*Database) GetOpenIDTokenAttributes added in v0.4.0

func (d *Database) GetOpenIDTokenAttributes(
	ctx context.Context,
	token string,
) (*api.OpenIDTokenAttributes, error)

GetOpenIDTokenAttributes gets the attributes of issued an OIDC auth token

func (*Database) GetProfileByLocalpart

func (d *Database) GetProfileByLocalpart(
	ctx context.Context, localpart string,
) (*authtypes.Profile, error)

GetProfileByLocalpart returns the profile associated with the given localpart. Returns sql.ErrNoRows if no profile exists which matches the given localpart.

func (*Database) GetThreePIDsForLocalpart

func (d *Database) GetThreePIDsForLocalpart(
	ctx context.Context, localpart string,
) (threepids []authtypes.ThreePID, err error)

GetThreePIDsForLocalpart looks up the third-party identifiers associated with a given local user. If no association is known for this user, returns an empty slice. Returns an error if there was an issue talking to the database.

func (*Database) RemoveThreePIDAssociation

func (d *Database) RemoveThreePIDAssociation(
	ctx context.Context, threepid string, medium string,
) (err error)

RemoveThreePIDAssociation removes the association involving a given third-party identifier. If no association exists involving this third-party identifier, returns nothing. If there was a problem talking to the database, returns an error.

func (*Database) SaveAccountData

func (d *Database) SaveAccountData(
	ctx context.Context, localpart, roomID, dataType string, content json.RawMessage,
) error

SaveAccountData saves new account data for a given user and a given room. If the account data is not specific to a room, the room ID should be an empty string If an account data already exists for a given set (user, room, data type), it will update the corresponding row with the new content Returns a SQL error if there was an issue with the insertion/update

func (*Database) SaveThreePIDAssociation

func (d *Database) SaveThreePIDAssociation(
	ctx context.Context, threepid, localpart, medium string,
) (err error)

SaveThreePIDAssociation saves the association between a third party identifier and a local Matrix user (identified by the user's ID's local part). If the third-party identifier is already part of an association, returns Err3PIDInUse. Returns an error if there was a problem talking to the database.

func (*Database) SearchProfiles

func (d *Database) SearchProfiles(ctx context.Context, searchString string, limit int,
) ([]authtypes.Profile, error)

SearchProfiles returns all profiles where the provided localpart or display name match any part of the profiles in the database.

func (*Database) SetAvatarURL

func (d *Database) SetAvatarURL(
	ctx context.Context, localpart string, avatarURL string,
) error

SetAvatarURL updates the avatar URL of the profile associated with the given localpart. Returns an error if something went wrong with the SQL query

func (*Database) SetDisplayName

func (d *Database) SetDisplayName(
	ctx context.Context, localpart string, displayName string,
) error

SetDisplayName updates the display name of the profile associated with the given localpart. Returns an error if something went wrong with the SQL query

func (*Database) SetPassword

func (d *Database) SetPassword(
	ctx context.Context, localpart, plaintextPassword string,
) error

SetPassword sets the account password to the given hash.

func (*Database) UpdateKeyBackupAuthData added in v0.5.0

func (d *Database) UpdateKeyBackupAuthData(
	ctx context.Context, userID, version string, authData json.RawMessage,
) (err error)

func (*Database) UpsertBackupKeys added in v0.5.0

func (d *Database) UpsertBackupKeys(
	ctx context.Context, version, userID string, uploads []api.InternalKeyBackupSession,
) (count int64, etag string, err error)

nolint:nakedret

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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