auth

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CredsFieldName      = "server.http.auth.creds"
	TokensFieldName     = "server.http.auth.tokens"
	HeaderNameFieldName = "server.http.auth.header_name"

	HeaderNameDefault = "X-Auth-Token"
)

Variables

View Source
var (
	BasicAuthComponent = &app.Component{
		Dependencies: app.Components{
			logger.Component,
			configurator.Component,
			router.Component,
		},
		Constructor: func(container container.Container) error {
			return container.Provides(
				NewCredConfig,
				NewBasicReConfigurationWithConfigurator,
			)
		},
		BindFlags: func(flagSet *pflag.FlagSet, container container.Container) error {
			return container.Invoke(func(config *CredConfig) {
				flagSet.StringSliceVar(&config.Creds, CredsFieldName, nil, "pairs login:password for basic authorization via http")
			})
		},
		Run: func(c container.Container) error {
			basic, err := container.Get[*BasicReConfiguration](c)
			if err != nil {
				return err
			}

			router, err := container.Get[router.Router](c)
			if err != nil {
				return err
			}

			reConfiguration, err := container.Get[configurator.ReConfiguration](c)
			if err != nil {
				return err
			}

			informer, err := container.Get[logger.Informer](c)
			if err != nil {
				return err
			}

			reConfiguration.Registration(basic)
			informer.Info("http.client.middleware.auth.basic: registration in the reConfigurator")

			router.Use(basic)

			return nil
		},
	}

	TokenAuthComponent = &app.Component{
		Dependencies: app.Components{
			logger.Component,
			configurator.Component,
			router.Component,
		},
		Constructor: func(container container.Container) error {
			return container.Provides(
				NewTokenConfig,
				NewTokenReConfigurationWithConfigurator,
			)
		},
		BindFlags: func(flagSet *pflag.FlagSet, container container.Container) error {
			return container.Invoke(func(config *TokenConfig) {
				flagSet.StringSliceVar(&config.Tokens, TokensFieldName, nil, "list of access tokens")
				flagSet.StringVar(&config.HeaderName, HeaderNameFieldName, HeaderNameDefault, "header name with token")
			})
		},
		Run: func(c container.Container) error {
			token, err := container.Get[*TokenReConfiguration](c)
			if err != nil {
				return err
			}

			router, err := container.Get[router.Router](c)
			if err != nil {
				return err
			}

			reConfiguration, err := container.Get[configurator.ReConfiguration](c)
			if err != nil {
				return err
			}

			informer, err := container.Get[logger.Informer](c)
			if err != nil {
				return err
			}

			reConfiguration.Registration(token)
			informer.Info("http.client.middleware.auth.token: registration in the reConfigurator")

			router.Use(token)

			return nil
		},
	}
)

Functions

This section is empty.

Types

type Basic

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

func NewBasic

func NewBasic(creds ...*Cred) *Basic

func NewBasicWithConfigurator

func NewBasicWithConfigurator(config *CredConfig, configurator configurator.Configurator) *Basic

func (*Basic) Middleware

func (middleware *Basic) Middleware(next http.Handler) http.Handler

type BasicReConfiguration

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

func NewBasicReConfiguration

func NewBasicReConfiguration(informer logger.Informer, config *CredConfig) *BasicReConfiguration

func NewBasicReConfigurationWithConfigurator

func NewBasicReConfigurationWithConfigurator(informer logger.Informer, config *CredConfig, configurator configurator.Configurator) *BasicReConfiguration

func (*BasicReConfiguration) Middleware

func (reConfiguration *BasicReConfiguration) Middleware(next http.Handler) http.Handler

func (*BasicReConfiguration) ReConfiguration

func (reConfiguration *BasicReConfiguration) ReConfiguration(configurator configurator.Configurator) error

type Cred

type Cred struct {
	UserName string
	Password string
}

type CredConfig

type CredConfig struct {
	Creds []string `info:"secret"`
}

func BasicConfiguration

func BasicConfiguration(config *CredConfig, configurator configurator.Configurator) *CredConfig

func NewCredConfig

func NewCredConfig() *CredConfig

type Token

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

func NewToken

func NewToken(config *TokenConfig) *Token

func NewTokenWithConfigurator

func NewTokenWithConfigurator(config *TokenConfig, configurator configurator.Configurator) *Token

func (*Token) Middleware

func (middleware *Token) Middleware(next http.Handler) http.Handler

type TokenConfig

type TokenConfig struct {
	HeaderName string
	Tokens     []string `info:"secret"`
}

func NewTokenConfig

func NewTokenConfig() *TokenConfig

func TokenConfiguration

func TokenConfiguration(config *TokenConfig, configurator configurator.Configurator) *TokenConfig

type TokenReConfiguration

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

func NewTokenReConfiguration

func NewTokenReConfiguration(informer logger.Informer, config *TokenConfig) *TokenReConfiguration

func NewTokenReConfigurationWithConfigurator

func NewTokenReConfigurationWithConfigurator(informer logger.Informer, config *TokenConfig, configurator configurator.Configurator) *TokenReConfiguration

func (*TokenReConfiguration) Middleware

func (reConfiguration *TokenReConfiguration) Middleware(next http.Handler) http.Handler

func (*TokenReConfiguration) ReConfiguration

func (reConfiguration *TokenReConfiguration) ReConfiguration(configurator configurator.Configurator) error

Jump to

Keyboard shortcuts

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