auth

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Базовая HTTP авторизая.

Копмпонент - BasicAuthComponent, автоматически добавляет все нужные middleware для базовой авторизации.

Объект конфигурации.

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

Описание полей:

Поле Описание Значение по умолчанию
Cred Пара логин:пароль, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --client.http.auth.cred
- переменная окружения CLIENT_HTTP_AUTH_CRED
- значение в конфиг файле client.http.auth.cred

Documentation

Index

Constants

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

Variables

View Source
var (
	BasicAuthComponent = &app.Component{
		Constructor: app.Constructor(func(container container.Container) error {
			return container.Provide(NewConfig)
		}),
		BindFlags: app.BindFlags(func(flagSet *pflag.FlagSet, container container.Container) error {
			return container.Invoke(func(config *Config) {
				flagSet.StringVar(&config.Cred, CredFieldName, "", "login:password pairs for basic authorization in http request")
			})
		}),
		Run: app.Run(func(container container.Container) error {
			return container.Invoke(func(
				config *Config,
				configurator configurator.Configurator,
				logger logger.Logger,
				httpClient client.Doer,
			) error {
				if config.Cred == "" {
					config.Cred = configurator.GetString(CredFieldName)
				}

				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.Use(Basic(
					&Cred{
						UserName: cred[0],
						Password: cred[1],
					},
					logger,
				))

				return nil
			})
		}),
	}
)

Functions

func Basic

func Basic(cred *Cred, informer logger.Informer) client.MiddlewareFunc

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