lockout

package
v0.0.0-...-09efcc3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = apierrors.TooManyRequest.WithReason("AccountLockout")

Functions

func NewErrLocked

func NewErrLocked(until time.Time) error

Types

type LockoutSpec

type LockoutSpec struct {
	Name      string
	Arguments []string

	Enabled         bool
	MaxAttempts     int
	HistoryDuration time.Duration
	MinimumDuration time.Duration
	MaximumDuration time.Duration
	BackoffFactor   float64
	IsGlobal        bool
}

func NewAccountAuthenticationSpecForAttempt

func NewAccountAuthenticationSpecForAttempt(cfg *config.AuthenticationLockoutConfig, userID string, methods []config.AuthenticationLockoutMethod) LockoutSpec

func NewAccountAuthenticationSpecForCheck

func NewAccountAuthenticationSpecForCheck(cfg *config.AuthenticationLockoutConfig, userID string) LockoutSpec

func (LockoutSpec) Key

func (s LockoutSpec) Key() string

type Logger

type Logger struct{ *log.Logger }

func NewLogger

func NewLogger(lf *log.Factory) Logger

type MakeAttemptResult

type MakeAttemptResult struct {
	LockedUntil *time.Time
	// contains filtered or unexported fields
}

func (*MakeAttemptResult) ErrorIfLocked

func (m *MakeAttemptResult) ErrorIfLocked() error

type Service

type Service struct {
	Logger  Logger
	Storage Storage
}

func (*Service) ClearAttempts

func (s *Service) ClearAttempts(ctx context.Context, spec LockoutSpec, contributor string) error

func (*Service) MakeAttempts

func (s *Service) MakeAttempts(ctx context.Context, spec LockoutSpec, contributor string, attempts int) (result *MakeAttemptResult, err error)

type Storage

type Storage interface {
	Update(ctx context.Context, spec LockoutSpec, contributor string, delta int) (isSuccess bool, lockedUntil *time.Time, err error)
	Clear(ctx context.Context, spec LockoutSpec, contributor string) error
}

type StorageRedis

type StorageRedis struct {
	AppID config.AppID
	Redis *appredis.Handle
}

func (StorageRedis) Clear

func (s StorageRedis) Clear(ctx context.Context, spec LockoutSpec, contributor string) (err error)

func (StorageRedis) Update

func (s StorageRedis) Update(ctx context.Context, spec LockoutSpec, contributor string, delta int) (isSuccess bool, lockedUntil *time.Time, err error)

Jump to

Keyboard shortcuts

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