Documentation ¶
Overview ¶
Package bufconnect provides buf-specific Connect functionality.
Index ¶
- Constants
- func NewAugmentedConnectErrorInterceptor() connect.UnaryInterceptorFunc
- func NewAuthorizationInterceptorProvider(tokenProviders ...TokenProvider) func(string) connect.UnaryInterceptorFunc
- func NewCLIWarningInterceptor(container appext.LoggerContainer) connect.UnaryInterceptorFunc
- func NewDebugLoggingInterceptor(container appext.LoggerContainer) connect.UnaryInterceptorFunc
- func NewSetCLIVersionInterceptor(version string) connect.UnaryInterceptorFunc
- type AugmentedConnectError
- type AuthError
- type TokenProvider
Constants ¶
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" )
const (
// TokenEnvKey is the environment variable key for the auth token
TokenEnvKey = "BUF_TOKEN"
)
Variables ¶
This section is empty.
Functions ¶
func NewAugmentedConnectErrorInterceptor ¶ added in v1.32.0
func NewAugmentedConnectErrorInterceptor() connect.UnaryInterceptorFunc
NewAugmentedConnectErrorInterceptor returns a new Connect Interceptor that wraps [connect.Error]s in an AugmentedConnectError.
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 ¶ added in v1.22.0
func NewCLIWarningInterceptor(container appext.LoggerContainer) connect.UnaryInterceptorFunc
NewCLIWarningInterceptor returns a new Connect Interceptor that logs CLI warnings returned by server responses.
func NewDebugLoggingInterceptor ¶ added in v1.48.0
func NewDebugLoggingInterceptor(container appext.LoggerContainer) connect.UnaryInterceptorFunc
NewDebugLoggingInterceptor returns a new Connect Interceptor that adds debug log statements for each rpc call.
The following information is collected for logging: duration, status code, peer name, rpc system, request size, and response size.
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 AugmentedConnectError ¶ added in v1.32.0
type AugmentedConnectError struct {
// contains filtered or unexported fields
}
AugmentedConnectError wraps an error, providing the Procedure and Addr of the request for introspection in callers.
func (*AugmentedConnectError) Addr ¶ added in v1.32.0
func (e *AugmentedConnectError) Addr() string
Addr returns the connect.AnyRequest's Peer().Addr.
func (*AugmentedConnectError) Error ¶ added in v1.32.0
func (e *AugmentedConnectError) Error() string
Error implements the error interface and returns the error message.
func (*AugmentedConnectError) Procedure ¶ added in v1.32.0
func (e *AugmentedConnectError) Procedure() string
Procedure returns the connect.AnyRequest's Spec().Procedure.
func (*AugmentedConnectError) Unwrap ¶ added in v1.32.0
func (e *AugmentedConnectError) Unwrap() error
Unwrap returns the underlying error.
type AuthError ¶ added in v1.13.0
type AuthError struct {
// contains filtered or unexported fields
}
AuthError wraps the error returned in the auth provider to add additional context.
func AsAuthError ¶ added in v1.10.0
AsAuthError uses errors.As to unwrap any error and look for an *AuthError.
func (*AuthError) Error ¶ added in v1.13.0
Error implements the error interface and returns the error message.
func (*AuthError) HasToken ¶ added in v1.34.0
HasToken returns whether a token was included in the request.
func (*AuthError) TokenEnvKey ¶ added in v1.13.0
TokenEnvKey returns the environment variable used, if any, for authentication.
type TokenProvider ¶ added in v1.13.0
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 ¶ added in v1.13.0
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 ¶ added in v1.13.0
func NewTokenProviderFromContainer(container app.EnvContainer) (TokenProvider, error)
NewTokenProviderFromContainer creates a singleTokenProvider from the BUF_TOKEN environment variable
func NewTokenProviderFromString ¶ added in v1.13.0
func NewTokenProviderFromString(token string) (TokenProvider, error)
NewTokenProviderFromString creates a singleTokenProvider by the token provided