httpcli

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateAuthRegistration        = errors.New("duplicate auth mechanism registration")
	ErrUnregisteredFactory              = errors.New("unregistered factory requested")
	ErrIllegalDoerFactoryImplementation = errors.New("illegal DoerFactory implementation returned non-nil Doer for a nil *http.Client")
	ErrMissingConfiguration             = errors.New("missing configuration for specified authentication mechanism")
)

ErrDuplicateAuthRegistration signifies a configuration error in which the same AuthMechanism is being registered multiple times.

View Source
var ErrAuthFailed = errors.New("IAM authentication failed")

ErrAuthFailed is returned for any type of IAM authentication failure

Functions

func Register

func Register(am AuthMechanism, df DoerFactory)

Register associates an AuthMechanism with a DoerFactory

func RegistryReset

func RegistryReset()

RegistryReset unregisters all previously user-registered factory instances and resets to the default state. Intended for testing purposes.

func TLSConfig

func TLSConfig(enabled bool, caPool *x509.CertPool, cert tls.Certificate) (opt urls.Option, config *tls.Config)

TLSConfig generates and returns a recommended URL generation option and TLS configuration.

func Validate

func Validate(am AuthMechanism, cm ConfigMap) (err error)

Validate checks that the given AuthMechainsm and ConfigMap are compatible with the registered set of DoerFactory instances.

Types

type AuthMechanism

type AuthMechanism string

AuthMechanism enumerates the supported authentication strategies

const (
	AuthNone  AuthMechanism = ""      // AuthNone specifies no authentication mechanism
	AuthBasic AuthMechanism = "basic" // AuthBasic specifies to use HTTP Basic
	AuthIAM   AuthMechanism = "iam"   // AuthIAM specifies to use IAM / JDK authentication
)

AuthNone, et al. represent the complete set of supported authentication mechanisms

type ConfigMap

type ConfigMap map[AuthMechanism]interface{}

ConfigMap maps authentication configuration types to values

func (ConfigMap) FindOrPanic

func (cm ConfigMap) FindOrPanic(am AuthMechanism) interface{}

FindOrPanic returns the mapped configuration for the given auth mechanism or else panics

type ConfigMapOption

type ConfigMapOption func(ConfigMap)

ConfigMapOption is a functional option for a ConfigMap

type ConfigMapOptions

type ConfigMapOptions []ConfigMapOption

ConfigMapOptions aggregates ConfigMapOption

func (ConfigMapOptions) ToConfigMap

func (cmo ConfigMapOptions) ToConfigMap() (m ConfigMap)

ToConfigMap generates a ConfigMap from the given options. If no map entries are generated then a nil ConfigMap is returned.

type Doer

type Doer interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

Doer executes an http.Request and returns the generated http.Response; similar to http.RoundTripper but may modify an in-flight http.Request object.

func New

func New(am AuthMechanism, cm ConfigMap, options ...Option) Doer

New generates and returns an HTTP transactor given an optional IAM configuration and some set of functional options.

type DoerFactory

type DoerFactory func(ConfigMap, *http.Client) Doer

DoerFactory generates a Doer. If the given Client is nil then the returned Doer must also be nil. Specifying a nil Client is useful for asking the factory to ONLY validate the provided ConfigMap.

type DoerFunc

type DoerFunc func(req *http.Request) (resp *http.Response, err error)

DoerFunc is the functional adaptation of Doer

func (DoerFunc) Do

func (df DoerFunc) Do(req *http.Request) (*http.Response, error)

Do implements Doer for DoerFunc

type Option

type Option func(*http.Client)

Option is a functional option type

func Timeout

func Timeout(timeout time.Duration) Option

Timeout returns an Option that configures client timeout

func Transport

func Transport(tr http.RoundTripper) Option

Transport returns an Option that configures client transport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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