Documentation
¶
Overview ¶
Package serverclient contains helpers for the server API client.
Index ¶
- Constants
- Variables
- func Connect(ctx context.Context, opts ...ConnectOption) (*grpc.ClientConn, error)
- func ContextConfig(opts ...ConnectOption) (*clicontext.Config, error)
- func TokenDecode(token string) (*pb.Token, error)
- func TokenFromContext(ctx context.Context) string
- func TokenWithContext(ctx context.Context, t string) context.Context
- type ConnectOption
- type ContextToken
- type StaticToken
Constants ¶
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 ¶
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 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 TokenDecode ¶
TokenDecode provides the ability to decode a waypoint token into the embedded protobuf. WARNING: This function is unable to verify the token, only the server that generate the server can do that.
func TokenFromContext ¶
TokenFromContext extracts a token (if any) from the given context.
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 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 ¶
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 ¶
func (ContextToken) RequireTransportSecurity ¶
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 (StaticToken) RequireTransportSecurity ¶
func (t StaticToken) RequireTransportSecurity() bool