bufconnect

package
v0.0.0-...-a078c60 Latest Latest
Warning

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

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

Documentation

Overview

Package bufconnect provides buf-specific Connect functionality.

Index

Constants

View Source
const (
	// AuthenticationHeader is the standard OAuth header used for authenticating
	// a user. Ignore the misnomer.
	AuthenticationHeader = "Authorization"
	// AuthenticationTokenPrefix is the standard OAuth token prefix.
	// We use it for familiarity.
	AuthenticationTokenPrefix = "Bearer "
	// CliVersionHeaderName is the name of the header carrying the buf CLI version.
	CliVersionHeaderName = "buf-version"
	// CLIWarningHeaderName is the name of the header carrying a base64-encoded warning message
	// from the server to the CLI.
	CLIWarningHeaderName = "buf-warning-bin"
	// DefaultRemote is the default remote if none can be inferred from a module name.
	DefaultRemote = "buf.build"
)

Variables

This section is empty.

Functions

func NewAuthorizationInterceptorProvider

func NewAuthorizationInterceptorProvider(tokenProviders ...TokenProvider) func(string) connect.UnaryInterceptorFunc

NewAuthorizationInterceptorProvider returns a new provider function which, when invoked, returns an interceptor which will set the auth token into the request header by the provided option.

Note that the interceptor returned from this provider is always applied LAST in the series of interceptors added to a client.

func NewCLIWarningInterceptor

func NewCLIWarningInterceptor(container applog.Container) connect.UnaryInterceptorFunc

NewCLIWarningInterceptor returns a new Connect Interceptor that logs CLI warnings returned by server responses.

func NewSetCLIVersionInterceptor

func NewSetCLIVersionInterceptor(version string) connect.UnaryInterceptorFunc

NewSetCLIVersionInterceptor returns a new Connect Interceptor that sets the Buf CLI version into all request headers

Types

type AuthError

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

AuthError wraps the error returned in the auth provider to add additional context.

func AsAuthError

func AsAuthError(err error) (*AuthError, bool)

AsAuthError uses errors.As to unwrap any error and look for an *AuthError.

func (*AuthError) Error

func (e *AuthError) Error() string

Error implements the error interface and returns the error message.

func (*AuthError) TokenEnvKey

func (e *AuthError) TokenEnvKey() string

TokenEnvKey returns the environment variable used, if any, for authentication.

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

Unwrap returns the underlying error.

type TokenProvider

type TokenProvider interface {
	// RemoteToken returns the remote token from the remote address.
	RemoteToken(address string) string
	// IsFromEnvVar returns true if the TokenProvider is generated from an environment variable.
	IsFromEnvVar() bool
}

TokenProvider finds the token for NewAuthorizationInterceptorProvider.

func NewNetrcTokenProvider

func NewNetrcTokenProvider(container app.EnvContainer, getMachineForName func(app.EnvContainer, string) (netrc.Machine, error)) TokenProvider

NewNetrcTokenProvider returns a TokenProvider for a .netrc in a container.

func NewTokenProviderFromContainer

func NewTokenProviderFromContainer(container app.EnvContainer) (TokenProvider, error)

NewTokenProviderFromContainer creates a singleTokenProvider from the BUF_TOKEN environment variable

func NewTokenProviderFromString

func NewTokenProviderFromString(token string) (TokenProvider, error)

NewTokenProviderFromString creates a singleTokenProvider by the token provided

Jump to

Keyboard shortcuts

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