client

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Kubernetes HTTP auth client interface for reading client IDs and building requests.

Index

Constants

View Source
const (
	// DefaultIDHeader is the default header key used via
	// Interface.WithHeader. This constant is exported so that the
	// middleware can also use it as a default value.
	DefaultIDHeader = "X-Client-Id"
)

Variables

View Source
var (
	// LongLivedTokenOptions contains values that match the default
	// behavior for long-lived (no expiry) service account tokens.
	LongLivedTokenOptions = &Options{
		IDHeader:    DefaultIDHeader,
		TokenPath:   "/var/run/secrets/kubernetes.io/serviceaccount/token",
		TokenExpiry: -1 * time.Second,
	}

	// ExpiringTokenOptions contains values that match those used
	// in the tutorial at
	// https://learnk8s.io/microservices-authentication-kubernetes.
	ExpiringTokenOptions = &Options{
		IDHeader:    DefaultIDHeader,
		TokenPath:   "/var/run/secrets/tokens/api-token",
		TokenExpiry: 5 * time.Minute,
	}
)

Functions

This section is empty.

Types

type IDer

type IDer interface {
	// ID returns the client ID as typically defined in a service
	// account token.
	ID(context.Context) (string, error)
}

type Interface

type Interface interface {
	IDer
	WithHeaderer
}

Interface provides methods for working with client IDs as provided by service account tokens.

func New

func New(ctx context.Context, opts *Options) Interface

New creates a new client interface for use with building requests that contain the necessary auth headers. A nil value for the *Options argument is allowed and will result in the ExpiringTokenOptions being used.

type Options

type Options struct {
	// IDHeader is the header key used when building a request
	// via Interface.WithHeader.
	IDHeader string

	// TokenPath is the file path from which the client ID will be
	// read via Interface.ID.
	TokenPath string

	// TokenExpiry defines the expected expiry time of the token
	// read from TokenPath. A TokenExpiry value that is less than
	// zero will build a long lived token reader that caches the
	// token value indefinitely.
	TokenExpiry time.Duration
}

Options may be passed to New when creating a client Interface.

type WithHeaderer

type WithHeaderer interface {
	// WithHeader returns a clone of the given request that
	// includes the client ID set as the value of the configured
	// header.
	WithHeader(*http.Request) (*http.Request, error)
}

Jump to

Keyboard shortcuts

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