serverclient

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package serverclient contains helpers for the server API client.

Index

Constants

View Source
const (
	// ServerAddr is the address for the Waypoint server. This should be
	// in the format of "ip:port" for TCP.
	EnvServerAddr = "WAYPOINT_SERVER_ADDR"

	// ServerTls should be any value that strconv.ParseBool parses as
	// true to connect to the server with TLS.
	EnvServerTls           = "WAYPOINT_SERVER_TLS"
	EnvServerTlsSkipVerify = "WAYPOINT_SERVER_TLS_SKIP_VERIFY"

	// EnvServerToken is the token for authenticated with the server.
	EnvServerToken = "WAYPOINT_SERVER_TOKEN"

	// EnvServerCookie is the optional cookie value for API requests.
	EnvServerCookie = "WAYPOINT_SERVER_COOKIE"

	// EnvContext specifies a named context to load.
	EnvContext = "WAYPOINT_CONTEXT"
)

Common environment variables.

Variables

View Source
var ErrNoServerConfig = errors.New("no server connection configuration found")

ErrNoServerConfig is the error when there is no server configuration found for connection.

Functions

func Connect

func Connect(ctx context.Context, opts ...ConnectOption) (*grpc.ClientConn, error)

Connect connects to the Waypoint server. This returns the raw gRPC connection. You'll have to wrap it in NewWaypointClient to get the Waypoint client. We return the raw connection so that you have control over how to close it, and to support potentially alternate services in the future.

Authentication is done using a ContextToken type. You can replace the token at runtime by changing the context in use on a per-RPC basis.

func ContextConfig

func ContextConfig(opts ...ConnectOption) (*clicontext.Config, error)

ContextConfig will return the context configuration for the given connection options.

func TokenFromContext added in v0.8.0

func TokenFromContext(ctx context.Context) string

TokenFromContext extracts a token (if any) from the given context.

func TokenWithContext added in v0.8.0

func TokenWithContext(ctx context.Context, t string) context.Context

TokenWithContext stores a token on the given context. If this context is used by a connection created by serverclient, this token will take priority for requests.

Types

type ConnectOption

type ConnectOption func(*connectConfig) error

ConnectOption is used to configure how Waypoint server connection configuration is sourced.

func Auth

func Auth() ConnectOption

Auth specifies that this server should require auth and therefore a token should be sourced from the environment and sent.

func FromContext

func FromContext(st *clicontext.Storage, n string) ConnectOption

FromContext loads the context. This will prefer the given name. If name is empty, we'll respect the WAYPOINT_CONTEXT env var followed by the default context.

func FromContextConfig

func FromContextConfig(cfg *clicontext.Config) ConnectOption

FromContextConfig loads a specific context config.

func FromEnv

func FromEnv() ConnectOption

FromEnv sources the connection information from the environment using standard environment variables.

func Logger added in v0.6.0

func Logger(v hclog.Logger) ConnectOption

Logger is the logger to use.

func Optional

func Optional() ConnectOption

Optional specifies that getting server connection information is optional. If this is specified and no credentials are found, Connect will return (nil, nil). If this is NOT specified and no credentials are found, it is an error.

func Timeout

func Timeout(t time.Duration) ConnectOption

Timeout specifies a connection timeout. This defaults to 5 seconds.

type ContextToken added in v0.8.0

type ContextToken string

ContextToken implements grpc.WithPerRPCCredentials and extracts the token from the context or otherwise falls back to a default string value (which might be empty).

func (ContextToken) GetRequestMetadata added in v0.8.0

func (t ContextToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (ContextToken) RequireTransportSecurity added in v0.8.0

func (t ContextToken) RequireTransportSecurity() bool

type StaticToken

type StaticToken string

This is a weird type that only exists to satisify the interface required by grpc.WithPerRPCCredentials. That api is designed to incorporate things like OAuth but in our case, we really just want to send this static token through, but we still need to the dance.

func (StaticToken) GetRequestMetadata

func (t StaticToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (StaticToken) RequireTransportSecurity

func (t StaticToken) RequireTransportSecurity() bool

Jump to

Keyboard shortcuts

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