auth

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CredFieldName = "client.http.auth.cred"
)

Variables

View Source
var (
	BasicAuthComponent = &app.Component{
		Constructor: constructor,
		BindFlags:   bindFlags,
		Run: func(c container.Container) error {
			config, err := container.Get[*Config](c)
			if err != nil {
				return err
			}

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

			if config.Cred == "" {
				config.Cred = configurator.GetString(CredFieldName)
			}

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

			if config.Cred == "" {
				logger.Info("http.client.middleware: middleware for basic authorization in http client not added because cred is empty")
				return nil
			}

			cred := strings.Split(config.Cred, credSeparator)

			httpClient, err := container.Get[client.Doer](c)
			if err != nil {
				return err
			}

			httpClient.Use(Basic(
				&Cred{
					UserName: cred[0],
					Password: cred[1],
				},
				logger,
			))

			return nil
		},
	}
)

Functions

func Basic

func Basic(cred *Cred, informer logger.Informer) middleware.Func

func NewBasic

func NewBasic(originalTransport http.RoundTripper, cred *Cred) http.RoundTripper

Types

type Config

type Config struct {
	Cred string `info:"secret"`
}

func NewConfig

func NewConfig() *Config

type Cred

type Cred struct {
	UserName string
	Password string
}

Jump to

Keyboard shortcuts

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