Documentation ¶
Index ¶
- func ApplyOAuthProfileToUser(u *User, p oauth.Profile)
- func DeleteExpiredSessions(mgr *ModelManager) cron.Job
- func MigrationGroups() []*migration.Group
- func MigrationSuite(opts ...migration.SuiteOption) *migration.Suite
- func UpgradeHTTPS(action web.Action) web.Action
- type Auth
- func (a Auth) FetchSession(ctx context.Context, sessionID string) (*web.Session, error)
- func (a Auth) LoginRedirect(ctx web.Context) *url.URL
- func (a Auth) PersistSession(ctx context.Context, session *web.Session) error
- func (a Auth) Register(app *web.App)
- func (a Auth) RemoveSession(ctx context.Context, sessionID string) error
- func (a Auth) SessionTimeout(_ *web.Session) time.Time
- type BaseController
- type Config
- type DBEntryPoint
- type DBEntryPointConfigProvider
- type DBProvider
- type EntryPoint
- type EntryPointConfigProvider
- type LoggerProvider
- type MetaProvider
- type ModelManager
- type Session
- type SessionState
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOAuthProfileToUser ¶
ApplyOAuthProfileToUser applies an oauth proflie.
func DeleteExpiredSessions ¶
func DeleteExpiredSessions(mgr *ModelManager) cron.Job
DeleteExpiredSessions returns the job to delete expired sessions.
The default cutoff is 14 days but we can tweak that a bit.
func MigrationGroups ¶
MigrationGroups are the included migrations for the tables this package requires. You can use this array directly or indirectly through `Migrations`.
func MigrationSuite ¶
func MigrationSuite(opts ...migration.SuiteOption) *migration.Suite
MigrationSuite returns a fully formed migration suite you can use to apply the `MigrationGroups` directly.
func UpgradeHTTPS ¶
UpgradeHTTPS upgrades http connections to https with a redirect in typical settings.
We do so through `X-Forwarded-Proto` header sniffs because many reverse-proxy hosted services forward all traffic to http and add forwarded headers so we know what the context of the original request was.
Normally we'd run a second http server on 80 (in addition to 443) and do this redirect, but because of the specific nature of how many systems host "https" services on http ports this is what we need to do.
Types ¶
type Auth ¶
type Auth struct { BaseController Config Config AuthedRedirectPath string CreateUserListener func(context.Context, *User) error FetchSessionListener func(context.Context, *web.Session) error OAuth *oauth.Manager DB *ModelManager }
Auth is the auth controller.
func (Auth) FetchSession ¶
FetchSession implements web.FetchSessionHandler.
func (Auth) LoginRedirect ¶
LoginRedirect implements web.LoginRedirectHandler.
func (Auth) PersistSession ¶
PersistSession implements web.PersistSessionHandler.
func (Auth) RemoveSession ¶
RemoveSession implements web.RemoveSessionHandler.
type BaseController ¶
type BaseController struct{}
BaseController holds useful common methods for controllers.
type Config ¶
type Config struct { configmeta.Meta `yaml:",inline"` Logger logutil.Config `yaml:"logger"` OAuth oauth.Config `yaml:"oauth"` Web web.Config `yaml:"web"` DB db.Config `yaml:"db"` }
func (Config) GetLogger ¶
GetLogger returns the logger config.
This is required for `EntrypointConfigProvider`
func (Config) GetMeta ¶
func (c Config) GetMeta() configmeta.Meta
GetMeta returns the meta config.
This is required for `EntrypointConfigProvider`
type DBEntryPoint ¶
type DBEntryPoint[T DBEntryPointConfigProvider] struct { Setup func(context.Context, T) error Migrate func(context.Context, T, *db.Connection) error Start func(context.Context, T, *db.Connection) error // contains filtered or unexported fields }
EntryPoint is a top level handler for a database backed app.
It handles reading the config, setting up the logger, opening the database connection, and based on comandline flags handling calling specific handlers for initializing the database and applying migrations on start.
func (*DBEntryPoint[T]) Init ¶
func (e *DBEntryPoint[T]) Init()
Init should be run before `Run` and registers flags and the like.
func (*DBEntryPoint[T]) Main ¶
func (e *DBEntryPoint[T]) Main()
Main is the actual function that needs to be called in Main.
type DBEntryPointConfigProvider ¶
type DBEntryPointConfigProvider interface { LoggerProvider DBProvider MetaProvider }
DBEntryPointConfigProvider is a type that can provide an entrypoint config.
type DBProvider ¶
DBProvider is a type that provides a db config.
type EntryPoint ¶
type EntryPoint[T EntryPointConfigProvider] struct { Setup func(context.Context, T) error Start func(context.Context, T) error // contains filtered or unexported fields }
EntryPoint is a top level handler for a simple app.
It handles reading the config, and setting up the logger.
func (*EntryPoint[T]) Init ¶
func (e *EntryPoint[T]) Init()
Init should be run before `Run` and registers flags and the like.
func (*EntryPoint[T]) Main ¶
func (e *EntryPoint[T]) Main()
Main is the actual function that needs to be called in Main.
type EntryPointConfigProvider ¶
type EntryPointConfigProvider interface { LoggerProvider }
EntryPointConfigProvider is a type that can provide an entrypoint config.
type LoggerProvider ¶
LoggerProvider is a type that provides a logger config.
type MetaProvider ¶
type MetaProvider interface {
GetMeta() configmeta.Meta
}
MetaProvider is a type that provides a db config.
type ModelManager ¶
type ModelManager struct {
dbutil.BaseManager
}
ModelManager implements database functions.
func NewModelManager ¶
func NewModelManager(conn *db.Connection, opts ...db.InvocationOption) *ModelManager
NewModelManager returns a new model manager.
func NewTest ¶
func NewTest(t *testing.T) (*ModelManager, func())
NewTest returns a new test context.
func (ModelManager) DeleteExpiredSessions ¶
DeleteExpiredSessions deletes sessions that are expired and older than 14 days.
func (ModelManager) GetUserByEmail ¶
func (m ModelManager) GetUserByEmail(ctx context.Context, email string) (output User, found bool, err error)
GetUserByEmail gets a user by email.
type Session ¶
type Session struct { SessionID string `db:"session_id,pk"` UserID uuid.UUID `db:"user_id"` BaseURL string `db:"base_url"` CreatedUTC time.Time `db:"created_utc"` ExpiresUTC time.Time `db:"expires_utc"` LastSeenUTC time.Time `db:"last_seen_utc"` UserAgent string `db:"user_agent"` RemoteAddr string `db:"remote_addr"` Locale string `db:"locale"` }
Session holds session information for a user.
func CreateTestSession ¶
func CreateTestSession(t *testing.T, mgr *ModelManager, user *User) *Session
CreateTestSession creates a test session.
func NewTestSession ¶
NewTestSession returns a test session.
type User ¶
type User struct { ID uuid.UUID `db:"id,pk"` CreatedUTC time.Time `db:"created_utc"` LastLoginUTC time.Time `db:"last_login_utc"` LastSeenUTC time.Time `db:"last_seen_utc"` ProfileID string `db:"profile_id"` GivenName string `db:"given_name"` FamilyName string `db:"family_name"` PictureURL string `db:"picture_url"` Locale string `db:"locale"` Email string `db:"email"` }
User is a user
func CreateTestUser ¶
func CreateTestUser(t *testing.T, mgr *ModelManager) *User
CreateTestUser creates a test user.