serverclient

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 16 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")
	ErrInvalidToken   = errors.New("invalid token detected")
)

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

Functions

func BuildDialOptions added in v0.11.0

func BuildDialOptions() []grpc.DialOption

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

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

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.

Jump to

Keyboard shortcuts

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