Documentation
¶
Index ¶
- Constants
- func ApplyMigrations(connection *sql.DB, direction migrate.MigrationDirection) error
- func MigrationsSource() migrate.MigrationSource
- type Factory
- type Grant
- type Storer
- func (s Storer) CreateGrant(ctx context.Context, grant grants.Grant) error
- func (s Storer) ExchangeGrant(ctx context.Context, g grants.GrantUse) (grants.Grant, error)
- func (s Storer) GetGrant(ctx context.Context, id string) (grants.Grant, error)
- func (s Storer) GetGrantBySource(ctx context.Context, sourceType, sourceID string) (grants.Grant, error)
Constants ¶
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 ¶
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) TeardownStorers ¶
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 ¶
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 ¶
NewStorer returns a PostgreSQL Storer instance that is ready to be used as a Storer.
func (Storer) CreateGrant ¶
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 ¶
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
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.