factory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTestConfig

func CreateTestConfig() *config.Config

CreateTestConfig creates a minimal valid configuration for testing

func CreateTestConfigWithEmail

func CreateTestConfigWithEmail() *config.Config

CreateTestConfigWithEmail creates a test config with email authentication enabled

func CreateTestConfigWithOAuth2

func CreateTestConfigWithOAuth2() *config.Config

CreateTestConfigWithOAuth2 creates a test config with a Google OAuth2 provider

Types

type DefaultFactory

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

DefaultFactory is the default implementation of Factory. It can be embedded in custom factories to override specific methods.

func NewDefaultFactory

func NewDefaultFactory(host string, port int, logger logging.Logger) *DefaultFactory

NewDefaultFactory creates a new DefaultFactory

func (*DefaultFactory) CreateAuthzChecker

func (f *DefaultFactory) CreateAuthzChecker(authzCfg config.AuthorizationConfig) authz.Checker

CreateAuthzChecker creates an authorization checker based on config

func (*DefaultFactory) CreateEmailHandler

func (f *DefaultFactory) CreateEmailHandler(
	emailAuthCfg config.EmailAuthConfig,
	serviceCfg config.ServiceConfig,
	serverCfg config.ServerConfig,
	sessionCfg config.SessionConfig,
	host string,
	port int,
	authzChecker authz.Checker,
	translator *i18n.Translator,
	tokenKVS kvs.Store,
	rateLimitKVS kvs.Store,
) (*email.Handler, error)

CreateEmailHandler creates an email authentication handler if enabled

func (*DefaultFactory) CreateForwarder

func (f *DefaultFactory) CreateForwarder(forwardingCfg config.ForwardingConfig, providers []config.OAuth2Provider) forwarding.Forwarder

CreateForwarder creates a forwarder for user info forwarding (may return nil)

func (*DefaultFactory) CreateKVSStores

func (f *DefaultFactory) CreateKVSStores(cfg *config.Config) (session kvs.Store, token kvs.Store, rateLimit kvs.Store, err error)

CreateKVSStores creates all required KVS stores from configuration. This consolidates the KVS creation logic that was previously in serve.go.

func (*DefaultFactory) CreateMiddleware

func (f *DefaultFactory) CreateMiddleware(
	cfg *config.Config,
	sessionStore session.Store,
	proxyHandler http.Handler,
	logger logging.Logger,
) (*middleware.Middleware, error)

CreateMiddleware creates a complete Middleware instance with all components

func (*DefaultFactory) CreateOAuth2Manager

func (f *DefaultFactory) CreateOAuth2Manager(oauth2Cfg config.OAuth2Config, serverCfg config.ServerConfig, host string, port int) *oauth2.Manager

CreateOAuth2Manager creates an OAuth2 manager with configured providers

func (*DefaultFactory) CreateRateLimitKVS

func (f *DefaultFactory) CreateRateLimitKVS() kvs.Store

CreateRateLimitKVS creates a KVS store for rate limiting

func (*DefaultFactory) CreateRulesEvaluator

func (f *DefaultFactory) CreateRulesEvaluator(rulesCfg *rules.Config) (*rules.Evaluator, error)

CreateRulesEvaluator creates a rules evaluator from configuration

func (*DefaultFactory) CreateSessionStore

func (f *DefaultFactory) CreateSessionStore(kvsStore kvs.Store) session.Store

CreateSessionStore creates a session store using the provided KVS Since session.Store is now an alias for kvs.Store, this just returns the input

func (*DefaultFactory) CreateTokenKVS

func (f *DefaultFactory) CreateTokenKVS() kvs.Store

CreateTokenKVS creates a KVS store for email authentication tokens

func (*DefaultFactory) CreateTranslator

func (f *DefaultFactory) CreateTranslator() *i18n.Translator

CreateTranslator creates an i18n translator

type Factory

type Factory interface {
	// CreateMiddleware is the main factory method that creates a complete Middleware instance.
	// It uses other factory methods internally to build all required components.
	CreateMiddleware(
		cfg *config.Config,
		sessionStore session.Store,
		proxyHandler http.Handler,
		logger logging.Logger,
	) (*middleware.Middleware, error)

	// CreateOAuth2Manager creates an OAuth2 manager with configured providers
	CreateOAuth2Manager(oauth2Cfg config.OAuth2Config, serverCfg config.ServerConfig, host string, port int) *oauth2.Manager

	// CreateEmailHandler creates an email authentication handler if enabled
	CreateEmailHandler(
		emailAuthCfg config.EmailAuthConfig,
		serviceCfg config.ServiceConfig,
		serverCfg config.ServerConfig,
		sessionCfg config.SessionConfig,
		host string,
		port int,
		authzChecker authz.Checker,
		translator *i18n.Translator,
		tokenKVS kvs.Store,
		rateLimitKVS kvs.Store,
	) (*email.Handler, error)

	// CreateAuthzChecker creates an authorization checker based on config
	CreateAuthzChecker(authzCfg config.AuthorizationConfig) authz.Checker

	// CreateForwarder creates a forwarder for user info forwarding (may return nil)
	CreateForwarder(forwardingCfg config.ForwardingConfig, providers []config.OAuth2Provider) forwarding.Forwarder

	// CreateRulesEvaluator creates a rules evaluator from configuration
	CreateRulesEvaluator(rulesCfg *rules.Config) (*rules.Evaluator, error)

	// CreateTranslator creates an i18n translator
	CreateTranslator() *i18n.Translator

	// CreateTokenKVS creates a KVS store for email authentication tokens
	CreateTokenKVS() kvs.Store

	// CreateRateLimitKVS creates a KVS store for rate limiting
	CreateRateLimitKVS() kvs.Store

	// CreateKVSStores creates all required KVS stores from configuration.
	// Returns stores in order: sessionKVS, tokenKVS, rateLimitKVS, error
	CreateKVSStores(cfg *config.Config) (session kvs.Store, token kvs.Store, rateLimit kvs.Store, err error)

	// CreateSessionStore creates a session store using the provided KVS
	CreateSessionStore(kvsStore kvs.Store) session.Store
}

Factory is the interface for creating middleware and its components. It serves as a simple DI container, allowing customization of specific components.

type TestingFactory

type TestingFactory struct {
	*DefaultFactory
}

TestingFactory is a factory implementation for testing purposes. It embeds DefaultFactory and overrides specific methods to use in-memory stores and mock components suitable for testing.

func NewTestingFactory

func NewTestingFactory(host string, port int) *TestingFactory

NewTestingFactory creates a new TestingFactory with test-friendly defaults. It always uses in-memory KVS stores and a simple logger.

func NewTestingFactoryWithLogger

func NewTestingFactoryWithLogger(host string, port int, logger logging.Logger) *TestingFactory

NewTestingFactoryWithLogger creates a TestingFactory with a custom logger.

func (*TestingFactory) CreateKVSStores

func (f *TestingFactory) CreateKVSStores(cfg *config.Config) (session kvs.Store, token kvs.Store, rateLimit kvs.Store, err error)

CreateKVSStores creates all in-memory KVS stores for testing. Unlike the production implementation, this always uses memory stores regardless of configuration, making tests faster and isolated.

func (*TestingFactory) CreateRateLimitKVS

func (f *TestingFactory) CreateRateLimitKVS() kvs.Store

CreateRateLimitKVS creates an in-memory KVS for rate limiting with short cleanup interval

func (*TestingFactory) CreateTokenKVS

func (f *TestingFactory) CreateTokenKVS() kvs.Store

CreateTokenKVS creates an in-memory KVS for email tokens with short cleanup interval

Jump to

Keyboard shortcuts

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