Documentation ¶
Overview ¶
Package sqlite implements the SQLite backend of the roomdb interfaces.
It uses sql-migrate (github.com/rubenv/sql-migrate) for it's schema definition and maintenance. For query construction/ORM it uses SQLBoiler (https://github.com/volatiletech/sqlboiler).
The process of updating the schema and ORM can be summarized as follows:
- Make changes to the interfaces in package roomdb
- Add a new migration to the 'migrations' folder
- Run 'go test -run Simple', which applies all the migrations
- Run sqlboiler to generate package models
- Implement the interface as needed by using the models package
For convenience step 3 and 4 are combined in the generate_models bash script.
Index ¶
- type Aliases
- func (a Aliases) GetByID(ctx context.Context, id int64) (roomdb.Alias, error)
- func (a Aliases) List(ctx context.Context) ([]roomdb.Alias, error)
- func (a Aliases) Register(ctx context.Context, alias string, userFeed refs.FeedRef, signature []byte) error
- func (a Aliases) Resolve(ctx context.Context, name string) (roomdb.Alias, error)
- func (a Aliases) Revoke(ctx context.Context, alias string) error
- type AuthFallback
- func (af AuthFallback) Check(login, password string) (interface{}, error)
- func (af AuthFallback) CreateResetToken(ctx context.Context, createdByMember, forMember int64) (string, error)
- func (af AuthFallback) SetPassword(ctx context.Context, memberID int64, password string) error
- func (af AuthFallback) SetPasswordWithToken(ctx context.Context, resetToken string, password string) error
- type AuthWithSSB
- func (a AuthWithSSB) CheckToken(ctx context.Context, token string) (int64, error)
- func (a AuthWithSSB) CreateToken(ctx context.Context, memberID int64) (string, error)
- func (a AuthWithSSB) RemoveToken(ctx context.Context, token string) error
- func (a AuthWithSSB) WipeTokensForMember(ctx context.Context, memberID int64) error
- type Config
- func (c Config) GetDefaultLanguage(ctx context.Context) (string, error)
- func (c Config) GetPrivacyMode(ctx context.Context) (roomdb.PrivacyMode, error)
- func (c Config) SetDefaultLanguage(ctx context.Context, langTag string) error
- func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error
- type Database
- type DeniedKeys
- func (dk DeniedKeys) Add(ctx context.Context, a refs.FeedRef, comment string) error
- func (dk DeniedKeys) Count(ctx context.Context) (uint, error)
- func (dk DeniedKeys) GetByID(ctx context.Context, id int64) (roomdb.ListEntry, error)
- func (dk DeniedKeys) HasFeed(ctx context.Context, h refs.FeedRef) bool
- func (dk DeniedKeys) HasID(ctx context.Context, id int64) bool
- func (dk DeniedKeys) List(ctx context.Context) ([]roomdb.ListEntry, error)
- func (dk DeniedKeys) RemoveFeed(ctx context.Context, r refs.FeedRef) error
- func (dk DeniedKeys) RemoveID(ctx context.Context, id int64) error
- type Invites
- func (i Invites) Consume(ctx context.Context, token string, newMember refs.FeedRef) (roomdb.Invite, error)
- func (i Invites) Count(ctx context.Context) (uint, error)
- func (i Invites) Create(ctx context.Context, createdBy int64) (string, error)
- func (i Invites) GetByID(ctx context.Context, id int64) (roomdb.Invite, error)
- func (i Invites) GetByToken(ctx context.Context, token string) (roomdb.Invite, error)
- func (i Invites) List(ctx context.Context) ([]roomdb.Invite, error)
- func (i Invites) Revoke(ctx context.Context, id int64) error
- type Members
- func (m Members) Add(ctx context.Context, pubKey refs.FeedRef, role roomdb.Role) (int64, error)
- func (m Members) Count(ctx context.Context) (uint, error)
- func (m Members) GetByFeed(ctx context.Context, h refs.FeedRef) (roomdb.Member, error)
- func (m Members) GetByID(ctx context.Context, mid int64) (roomdb.Member, error)
- func (m Members) List(ctx context.Context) ([]roomdb.Member, error)
- func (m Members) RemoveFeed(ctx context.Context, r refs.FeedRef) error
- func (m Members) RemoveID(ctx context.Context, id int64) error
- func (m Members) SetRole(ctx context.Context, id int64, r roomdb.Role) error
- type Notices
- type PinnedNotices
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aliases ¶
type Aliases struct {
// contains filtered or unexported fields
}
func (Aliases) Register ¶
func (a Aliases) Register(ctx context.Context, alias string, userFeed refs.FeedRef, signature []byte) error
Register receives an alias and signature for it. Validation needs to happen before this.
type AuthFallback ¶
type AuthFallback struct {
// contains filtered or unexported fields
}
func (AuthFallback) Check ¶
func (af AuthFallback) Check(login, password string) (interface{}, error)
Check receives the loging and password (in clear) and checks them accordingly. Login might be a registered alias or a ssb id who belongs to a member. If it's a valid combination it returns the user ID, or an error if they are not.
func (AuthFallback) CreateResetToken ¶
func (AuthFallback) SetPassword ¶
func (AuthFallback) SetPasswordWithToken ¶
type AuthWithSSB ¶
type AuthWithSSB struct {
// contains filtered or unexported fields
}
func (AuthWithSSB) CheckToken ¶
CheckToken checks if the passed token is still valid and returns the member id if so
func (AuthWithSSB) CreateToken ¶
CreateToken is used to generate a token that is stored inside a cookie. It is used after a valid solution for a challenge was provided.
func (AuthWithSSB) RemoveToken ¶
func (a AuthWithSSB) RemoveToken(ctx context.Context, token string) error
RemoveToken removes a single token from the database
func (AuthWithSSB) WipeTokensForMember ¶
func (a AuthWithSSB) WipeTokensForMember(ctx context.Context, memberID int64) error
WipeTokensForMember deletes all tokens currently held for that member
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config basically enables long-term memory for the server when it comes to storing settings. Currently, the only
* stored settings is the privacy mode of the room.
func (Config) GetDefaultLanguage ¶
func (Config) GetPrivacyMode ¶
func (Config) SetDefaultLanguage ¶
func (Config) SetPrivacyMode ¶
type Database ¶
type Database struct { AuthFallback AuthFallback AuthWithSSB AuthWithSSB Members Members Aliases Aliases Invites Invites Config Config DeniedKeys DeniedKeys PinnedNotices PinnedNotices Notices Notices // contains filtered or unexported fields }
type DeniedKeys ¶
type DeniedKeys struct {
// contains filtered or unexported fields
}
The DeniedKeys is backed by the members table
func (DeniedKeys) HasID ¶
func (dk DeniedKeys) HasID(ctx context.Context, id int64) bool
HasID returns true if a feed is on the list.
func (DeniedKeys) RemoveFeed ¶
RemoveFeed removes the feed from the list.
type Invites ¶
type Invites struct {
// contains filtered or unexported fields
}
Invites implements the roomdb.InviteService. Tokens are stored as sha256 hashes on disk to protect against attackers gaining database read-access.
func (Invites) Consume ¶
func (i Invites) Consume(ctx context.Context, token string, newMember refs.FeedRef) (roomdb.Invite, error)
Consume checks if the passed token is still valid. If it is it adds newMember to the members of the room and invalidates the token. If the token isn't valid, it returns an error. Tokens need to be base64 URL encoded and when decoded be of inviteTokenLength.
func (Invites) Create ¶
Create creates a new invite for a new member. It returns the token or an error. createdBy is user ID of the admin or moderator who created it. aliasSuggestion is optional (empty string is fine) but can be used to disambiguate open invites. (See https://github.com/ssb-ngi-pointer/rooms2/issues/21) The returned token is base64 URL encoded and has inviteTokenLength when decoded.
func (Invites) GetByToken ¶
type Members ¶
type Members struct {
// contains filtered or unexported fields
}
func (Members) RemoveFeed ¶
RemoveFeed removes the feed from the list.
type Notices ¶
type Notices struct {
// contains filtered or unexported fields
}
type PinnedNotices ¶
type PinnedNotices struct {
// contains filtered or unexported fields
}
func (PinnedNotices) Get ¶
func (pn PinnedNotices) Get(ctx context.Context, name roomdb.PinnedNoticeName, lang string) (*roomdb.Notice, error)
func (PinnedNotices) List ¶
func (pn PinnedNotices) List(ctx context.Context) (roomdb.PinnedNotices, error)
List returns a sortable map of all the pinned notices
func (PinnedNotices) Set ¶
func (pn PinnedNotices) Set(ctx context.Context, name roomdb.PinnedNoticeName, noticeID int64) error