authorizedapp

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package authorizedapp handles allowed applications.

Index

Constants

This section is empty.

Variables

View Source
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

func (c *Config) AuthorizedApp() *Config

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

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

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.

func NewMemoryProvider

func NewMemoryProvider(_ context.Context, _ *Config) (Provider, error)

NewMemoryProvider creates a new Provider that is in memory.

Directories

Path Synopsis
Package database is a database interface to authorized apps.
Package database is a database interface to authorized apps.
Package model is a model abstraction of authorized apps.
Package model is a model abstraction of authorized apps.

Jump to

Keyboard shortcuts

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