postgres

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TestConnStringEnvVar = "PG_TEST_DB"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

func NewFactory

func NewFactory(db *sql.DB) *Factory

func (*Factory) NewStorer

func (f *Factory) NewStorer(ctx context.Context) (tokens.Storer, error)

func (*Factory) TeardownStorer

func (f *Factory) TeardownStorer() error

type RefreshToken

type RefreshToken struct {
	ID          string
	CreatedAt   time.Time
	CreatedFrom string
	Scopes      pqarrays.StringArray
	ProfileID   string
	ClientID    string
	Revoked     bool
	Used        bool
}

RefreshToken represents a refresh token that can be used to obtain a new access token.

func (RefreshToken) GetSQLTableName

func (t RefreshToken) GetSQLTableName() string

GetSQLTableName returns the name of the PostgreSQL table RefreshTokens will be stored in. It is required for use with pan.

type Storer

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

Storer is an implementation of the Storer interface that is production quality and backed by a PostgreSQL database.

func NewStorer

func NewStorer(ctx context.Context, db *sql.DB) Storer

NewStorer returns an instance of Storer that is ready to be used as a Storer.

func (Storer) CreateToken

func (s Storer) CreateToken(ctx context.Context, token tokens.RefreshToken) error

CreateToken inserts the passed tokens.RefreshToken into Storer. If a tokens.RefreshToken with the same ID already exists in Storer, an ErrTokenAlreadyExists error will be returned, and the tokens.RefreshToken will not be inserted.

func (Storer) GetToken

func (s Storer) GetToken(ctx context.Context, token string) (tokens.RefreshToken, error)

GetToken retrieves the tokens.RefreshToken with an ID matching `token` from Storer. If no tokens.RefreshToken has that ID, an ErrTokenNotFound error is returned.

func (Storer) GetTokensByProfileID

func (s Storer) GetTokensByProfileID(ctx context.Context, profileID string, since, before time.Time) ([]tokens.RefreshToken, error)

GetTokensByProfileID retrieves up to NumTokenResults tokens.RefreshTokens from Storer. Only tokens.RefreshTokens with a ProfileID property matching `profileID` will be returned. If `since` is non-empty, only tokens.RefreshTokens with a CreatedAt property that is after `since` will be returned. If `before` is non-empty, only tokens.RefreshTokens with a CreatedAt property that is before `before` will be returned. tokens.RefreshTokens will be sorted by their CreatedAt property, with the most recent coming first.

func (Storer) UpdateTokens

func (s Storer) UpdateTokens(ctx context.Context, change tokens.RefreshTokenChange) error

UpdateTokens applies `change` to all the tokens.RefreshTokens in Storer that match the ID, ProfileID, or ClientID constraints of `change`.

func (Storer) UseToken

func (s Storer) UseToken(ctx context.Context, id string) error

UseToken atomically marks the token specified by `id` as used, returning a tokens.ErrTokenUsed if the token has already been marked used, or a tokens.ErrTokenNotFound if the token doesn't exist in Storer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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