Documentation ¶
Overview ¶
Package authorizedapp handles allowed applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAppNotFound = errors.New("app not found")
ErrAppNotFound is the sentinel error returned when AppConfig fails to find an app with the given name.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // CacheDuration is the amount of time AuthorizedApp should be cached before // being re-read from their provider. CacheDuration time.Duration `env:"AUTHORIZED_APP_CACHE_DURATION,default=5m"` }
func (*Config) AuthorizedApp ¶
AuthorizedApp implements an interface for setup.
type DatabaseProvider ¶
type DatabaseProvider struct {
// contains filtered or unexported fields
}
DatabaseProvider is a Provider that pulls from the database and caches and refreshes values on failure.
func (*DatabaseProvider) Add ¶
func (p *DatabaseProvider) Add(ctx context.Context, app *model.AuthorizedApp) error
Add adds a new authorized app to the system.
func (*DatabaseProvider) AppConfig ¶
func (p *DatabaseProvider) AppConfig(ctx context.Context, name string) (*model.AuthorizedApp, error)
AppConfig returns the config for the given app package name.
type DatabaseProviderOption ¶
type DatabaseProviderOption func(*DatabaseProvider) *DatabaseProvider
DatabaseProviderOption is used as input to the database provider.
type MemoryProvider ¶
type MemoryProvider struct {
// contains filtered or unexported fields
}
MemoryProvider is an Provider that stores values in-memory. It is primarily used for testing.
func (*MemoryProvider) Add ¶
func (p *MemoryProvider) Add(_ context.Context, app *model.AuthorizedApp) error
Add inserts the app. It returns an error if the app already exists.
func (*MemoryProvider) AppConfig ¶
func (p *MemoryProvider) AppConfig(_ context.Context, name string) (*model.AuthorizedApp, error)
AppConfig returns the config for the given app package name.
type Provider ¶
type Provider interface { // AppConfig returns the application-specific configuration for the given // name. An error is returned if the configuration fails to load. An error is // returned if no app with the given name is registered in the system. // // The name field is case-insensitive. Implementers should adjust accordingly // to handle mixed case. com.MyApp is the same as com.myapp. AppConfig(context.Context, string) (*model.AuthorizedApp, error) // Add inserts a model into the provider. Add(context.Context, *model.AuthorizedApp) error }
Provider defines possible AuthorizedApp providers.
func NewDatabaseProvider ¶
func NewDatabaseProvider(ctx context.Context, db *database.DB, config *Config, opts ...DatabaseProviderOption) (Provider, error)
NewDatabaseProvider creates a new Provider that reads from a database.