transport

package
v0.0.0-...-53b0845 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

dcos/http/transport

dcos/http/transport is an http.RoundTripper implementation that adds Authorization and User-Agent headers to each request.

The Authorization header is a signed Javascript web token (JWT).

The User-Agent defaults to dcos-go, and may be customized.

If request returns 401 response code, the library will generate a new token, sign it with a bouncer and retry the current request.

Warning!

This package breaks the RoundTripper interface spec defined in https://golang.org/pkg/net/http/#RoundTripper by mutating request instance.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCredentials is the error returned by NewRoundTripper if user used empty string for a credentials.
	ErrInvalidCredentials = errors.New("uid, secret and loginEndpoit cannot be empty")

	// ErrInvalidUserAgent is the error returned by NewRoundTripper if user used empty string for a user agent.
	ErrInvalidUserAgent = errors.New("userAgent cannot be empty")

	// ErrInvalidExpireDuration is the error returned by NewRoundTripper if the token expire duration is negative or
	// zero value.
	ErrInvalidExpireDuration = errors.New("token expire duration must be positive non zero value")
)
View Source
var (
	// ErrEmptyToken returned by `GenerateToken` if signed string returned empty string.
	ErrEmptyToken = errors.New("Empty token")

	// ErrWrongRoundTripperImpl returned by `CurrentToken` if http.RoundTripper does not implement implWithJWT.
	ErrWrongRoundTripperImpl = errors.New("RoundTripper does not implement OptionRoundtripperFunc")
)

Functions

func NewRoundTripper

func NewRoundTripper(rt http.RoundTripper, opts ...OptionRoundtripperFunc) (http.RoundTripper, error)

NewRoundTripper returns RoundTripper implementation with JWT handling.

func NewTransport

func NewTransport(clientOptionFuncs ...OptionTransportFunc) (http.RoundTripper, error)

NewTransport returns a DC/OS transport implementation by leveraging a roundtripper for IAM configuration if passed with a pre-configured TLS configuration.

Types

type Debug

type Debug interface {
	GenerateToken() error
	CurrentToken() string
}

Debug is an interface which defines methods to generate a token and get the latest generated token.

func DebugTransport

func DebugTransport(rt http.RoundTripper) (Debug, error)

DebugTransport is a function user can use to get a token from decorated http.RoundTripper if it implements implWithJWT.

type ErrTokenRefresh

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

ErrTokenRefresh is an error type returned by `RoundTrip` if the bouncer response was not 200.

func (ErrTokenRefresh) Error

func (e ErrTokenRefresh) Error() string

type OptionRoundtripperFunc

type OptionRoundtripperFunc func(*dcosRoundtripper) error

OptionRoundtripperFunc type sets options configurations for the DC/OS HTTP roundtripper

func OptionCredentials

func OptionCredentials(uid, secret, loginEndpoint string) OptionRoundtripperFunc

OptionCredentials is an option to set uid, secret and loginEndpoint.

func OptionReadIAMConfig

func OptionReadIAMConfig(path string) OptionRoundtripperFunc

OptionReadIAMConfig is an option to read the IAMConfig from file system and populate uid, secret and loginEndpoint.

func OptionTokenExpire

func OptionTokenExpire(t time.Duration) OptionRoundtripperFunc

OptionTokenExpire is an option to set JWT expiration date. If not set 24h is ussed by default.

func OptionUserAgent

func OptionUserAgent(userAgent string) OptionRoundtripperFunc

OptionUserAgent is an option to set userAgent

type OptionTransportFunc

type OptionTransportFunc func(*dcosTransport) error

OptionTransportFunc type sets optional configurations for the DC/OS HTTP transport

func OptionCaCertificatePath

func OptionCaCertificatePath(caCertificatePath string) OptionTransportFunc

OptionCaCertificatePath sets the CA certificate path option.

func OptionIAMConfigPath

func OptionIAMConfigPath(iamConfigPath string) OptionTransportFunc

OptionIAMConfigPath sets the IAM configuration path option.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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