transport

package
v0.0.0-...-f82c1dc Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

README

dcos-go/jwt/transport

Warning.
  • package works only with github.com/dgrijalva/jwt-go v2.6.0. Please make sure you vendor the right version.
  • package breaks RoundTripper interface spec defined in https://golang.org/pkg/net/http/#RoundTripper by mutating request instance.

jwt/transport is an http.RoundTripper implementation that automatically adds Authorization header to each request with a signed token. If request returns 401 response code, the library will generate a new token, sign it with a bouncer and retry the current request.

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")

	// 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.

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