sqlite

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 24 Imported by: 0

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:

  1. Make changes to the interfaces in package roomdb
  2. Add a new migration to the 'migrations' folder
  3. Run 'go test -run Simple', which applies all the migrations
  4. Run sqlboiler to generate package models
  5. 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

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) GetByID

func (a Aliases) GetByID(ctx context.Context, id int64) (roomdb.Alias, error)

GetByID returns the alias for that ID or an error

func (Aliases) List

func (a Aliases) List(ctx context.Context) ([]roomdb.Alias, error)

List returns a list of all registerd aliases

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.

func (Aliases) Resolve

func (a Aliases) Resolve(ctx context.Context, name string) (roomdb.Alias, error)

Resolve returns all the relevant information for that alias or an error if it doesnt exist

func (Aliases) Revoke

func (a Aliases) Revoke(ctx context.Context, alias string) error

Revoke removes an alias from the system

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 (af AuthFallback) CreateResetToken(ctx context.Context, createdByMember, forMember int64) (string, error)

func (AuthFallback) SetPassword

func (af AuthFallback) SetPassword(ctx context.Context, memberID int64, password string) error

func (AuthFallback) SetPasswordWithToken

func (af AuthFallback) SetPasswordWithToken(ctx context.Context, resetToken string, password string) error

type AuthWithSSB

type AuthWithSSB struct {
	// contains filtered or unexported fields
}

func (AuthWithSSB) CheckToken

func (a AuthWithSSB) CheckToken(ctx context.Context, token string) (int64, error)

CheckToken checks if the passed token is still valid and returns the member id if so

func (AuthWithSSB) CreateToken

func (a AuthWithSSB) CreateToken(ctx context.Context, memberID int64) (string, error)

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 (c Config) GetDefaultLanguage(ctx context.Context) (string, error)

func (Config) GetPrivacyMode

func (c Config) GetPrivacyMode(ctx context.Context) (roomdb.PrivacyMode, error)

func (Config) SetDefaultLanguage

func (c Config) SetDefaultLanguage(ctx context.Context, langTag string) error

func (Config) SetPrivacyMode

func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error

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
}

func Open

func Open(r repo.Interface) (*Database, error)

Open looks for a database file 'fname'

func (Database) Close

func (t Database) Close() error

Close closes the contained sql database object

type DeniedKeys

type DeniedKeys struct {
	// contains filtered or unexported fields
}

The DeniedKeys is backed by the members table

func (DeniedKeys) Add

func (dk DeniedKeys) Add(ctx context.Context, a refs.FeedRef, comment string) error

Add adds the feed to the list.

func (DeniedKeys) Count

func (dk DeniedKeys) Count(ctx context.Context) (uint, error)

func (DeniedKeys) GetByID

func (dk DeniedKeys) GetByID(ctx context.Context, id int64) (roomdb.ListEntry, error)

GetByID returns the entry if a feed with that ID is on the list.

func (DeniedKeys) HasFeed

func (dk DeniedKeys) HasFeed(ctx context.Context, h refs.FeedRef) bool

HasFeed returns true if a feed is on the list.

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) List

func (dk DeniedKeys) List(ctx context.Context) ([]roomdb.ListEntry, error)

List returns a list of all the feeds.

func (DeniedKeys) RemoveFeed

func (dk DeniedKeys) RemoveFeed(ctx context.Context, r refs.FeedRef) error

RemoveFeed removes the feed from the list.

func (DeniedKeys) RemoveID

func (dk DeniedKeys) RemoveID(ctx context.Context, id int64) error

RemoveID 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) Count

func (i Invites) Count(ctx context.Context) (uint, error)

func (Invites) Create

func (i Invites) Create(ctx context.Context, createdBy int64) (string, error)

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) GetByID

func (i Invites) GetByID(ctx context.Context, id int64) (roomdb.Invite, error)

func (Invites) GetByToken

func (i Invites) GetByToken(ctx context.Context, token string) (roomdb.Invite, error)

func (Invites) List

func (i Invites) List(ctx context.Context) ([]roomdb.Invite, error)

List returns a list of all the valid invites

func (Invites) Revoke

func (i Invites) Revoke(ctx context.Context, id int64) error

Revoke removes a active invite and invalidates it for future use.

type Members

type Members struct {
	// contains filtered or unexported fields
}

func (Members) Add

func (m Members) Add(ctx context.Context, pubKey refs.FeedRef, role roomdb.Role) (int64, error)

func (Members) Count

func (m Members) Count(ctx context.Context) (uint, error)

func (Members) GetByFeed

func (m Members) GetByFeed(ctx context.Context, h refs.FeedRef) (roomdb.Member, error)

GetByFeed returns the member if it exists

func (Members) GetByID

func (m Members) GetByID(ctx context.Context, mid int64) (roomdb.Member, error)

func (Members) List

func (m Members) List(ctx context.Context) ([]roomdb.Member, error)

List returns a list of all the feeds.

func (Members) RemoveFeed

func (m Members) RemoveFeed(ctx context.Context, r refs.FeedRef) error

RemoveFeed removes the feed from the list.

func (Members) RemoveID

func (m Members) RemoveID(ctx context.Context, id int64) error

RemoveID removes the feed from the list.

func (Members) SetRole

func (m Members) SetRole(ctx context.Context, id int64, r roomdb.Role) error

SetRole updates the role r of the passed memberID.

type Notices

type Notices struct {
	// contains filtered or unexported fields
}

func (Notices) GetByID

func (n Notices) GetByID(ctx context.Context, id int64) (roomdb.Notice, error)

func (Notices) RemoveID

func (n Notices) RemoveID(ctx context.Context, id int64) error

func (Notices) Save

func (n Notices) Save(ctx context.Context, p *roomdb.Notice) error

type PinnedNotices

type PinnedNotices struct {
	// contains filtered or unexported fields
}

func (PinnedNotices) Get

func (PinnedNotices) List

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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