postgres

package
v0.6.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: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// TestConnStringEnvVar is the name of the environment variable
	// to set to the connection string when running tests.
	TestConnStringEnvVar = "PG_TEST_DB"
)

Variables

This section is empty.

Functions

func ApplyMigrations added in v0.5.0

func ApplyMigrations(connection *sql.DB, direction migrate.MigrationDirection) error

ApplyMigrations runs the necessary database migrations to make the database match the expected schema against the passed connection.

func MigrationsSource added in v0.6.0

func MigrationsSource() migrate.MigrationSource

MigrationsSource returns a migrate.MigrationSource to apply the migrations for this storer.

Types

type Factory

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

Factory implements the grants.Factory interface for the Storer type; it offers a consistent interface for setting up and tearing down Storers for testing purposes.

func NewFactory

func NewFactory(db *sql.DB) *Factory

NewFactory returns a Factory, ready to be used. NewFactory must be called to obtain a usable Factory, because Factory types have internal state that must be initialized.

func (*Factory) NewStorer

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

NewStorer creates a new Storer and returns it.

func (*Factory) TeardownStorers

func (f *Factory) TeardownStorers() error

TeardownStorers drops all the databases created by NewStorer, cleaning up after the Factory.

type Grant

type Grant struct {
	ID         string
	SourceType string
	SourceID   string
	CreatedAt  time.Time
	UsedAt     time.Time
	Scopes     pqarrays.StringArray
	AccountID  string
	ProfileID  string
	ClientID   string
	CreateIP   string
	UseIP      string
	Used       bool
}

Grant is a representation of a Grant suitable for storage in our Storer.

func (Grant) GetSQLTableName

func (g Grant) GetSQLTableName() string

GetSQLTableName allows us to use Grant with pan.

type Storer

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

Storer is a PostgreSQL implementation of the Storer interface.

func NewStorer

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

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

func (Storer) CreateGrant

func (s Storer) CreateGrant(ctx context.Context, grant grants.Grant) error

CreateGrant inserts the passed Grant into the Storer, returning an ErrGrantAlreadyExists error if a Grant with the same ID alreday exists in the Storer, or am ErrGrantSourceAlreadyExists error if a Grant with the same SourceType and SourceID already exists in the Storer.

func (Storer) ExchangeGrant

func (s Storer) ExchangeGrant(ctx context.Context, g grants.GrantUse) (grants.Grant, error)

ExchangeGrant applies the GrantUse to the Storer, marking the Grant in the Storer with an ID matching the Grant property of the GrantUse as used and recording metadata about the IP and time the Grant was used. If no Grant has an ID matching the Grant property of the GrantUse, an ErrGrantNotFound error is returned. If the Grant in the Storer with an ID matching the Grant propery of the GrantUse is already marked as used, an ErrGrantAlreadyUsed error will be returned.

func (Storer) GetGrant added in v0.4.0

func (s Storer) GetGrant(ctx context.Context, id string) (grants.Grant, error)

GetGrant retrieves the Grant specified by `id` from the Storer, returning an ErrGrantNotFound error if no Grant in the Storer has an ID matching `id`.

func (Storer) GetGrantBySource added in v0.5.0

func (s Storer) GetGrantBySource(ctx context.Context, sourceType, sourceID string) (grants.Grant, error)

GetGrantBySource retrieves the Grant specified by `sourceType` and `sourceID` from the Storer, returning an ErrGrantNotFound error if no Grant in the Storer has a SourceType and SourceID matching those parameters.

Jump to

Keyboard shortcuts

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