proxy

package module
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package proxy provides a proxy that allows clients, such as Magma, to communicate with the pcas infrastructure. Communication in JSON format.

Overview

  1. Upon connection the client should write a Handshake.
  2. The client may then write Request objects to the proxy, one at a time.
  3. Upon receiving and processing a Request, the proxy will write a Response.
  4. The client should read the Response before writing the next Request.

Handshake

The Handshake describes configuration options, and should be written by the client immediately upon connecting to the proxy. The Handshake is of the form:

{
	"SendLengthPrefix":	bool
}

If SendLengthPrefix is true then the proxy writes JSON objects to the port as strings of the form

s\nt

where s is a string representation of an integer N, t is a string containing the JSON, and t has length N bytes. If bool is false then the proxy writes JSON objects to the port as strings of the form

t

as above, without the length prefix.

Request

A Request describes a request from the client to the proxy:

{
	"ID": ULID,
	"Timeout": Duration,
	"Endpoint": string,
	"Operation": string,
	"Arguments": Arguments
}

All keys are optional.

  • ID is a client-provided request ULID. This client can use this, if desired, to associate requests with responses.
  • Timeout is a timeout duration for handling this request. If Timeout is not specified, or if the Duration is <= 0, then the request will not timeout.
  • Endpoint names the endpoint for this requests.
  • Operation names the operation on this given endpoint. It is an error for Operation to be set, but for Endpoint to be omitted.
  • Arguments are operation-specific arguments for this request. It is an error for Arguments to be set, but for either Operation or Endpoint to be omitted.

Upon handling a Request, proxy will write a Response.

Response

A Response describes a response from the proxy to a Request from the client:

{
	"ID": ULID,
	"Endpoint": string,
	"Operation": string,
	"Result": Result,
	"Error": string
}

Here:

  • ID is the client-provided request ULID set on the Request. If the request ID was omitted from the Request, this will be omitted from the response.
  • Endpoint is the endpoint named in the request. If the endpoint was omitted from the Request, or is equal to the empty string, this will be omitted from the response.
  • Operation is the operation named in the request. If the operation was omitted from the Request, or is equal to the empty string, this will be omitted from the response.
  • Result is the operation-specific result.
  • Error is a string describing any error performing this operation.

Error is set only if the request failed; if Error is not set then the request succeeded. At most one of Result or Error will be set.

Duration

A Duration is defined by the JSON:

integer|string

In the case where Duration is given by an integer, it gives the number of nanoseconds in the duration. In the case where Duration is given by a string, this will be converted to a time.Duration via time.ParseDuration.

ULID

A ULID is defined by the JSON:

string

which must consist of exactly 26 characters taken from the alphabet:

0123456789ABCDEFGHJKMNPQRSTVWXYZ

A ULID is used to encode a bitbucket.org/pcastools/ulid.ULID.

Available endpoints

The available endpoints can be obtained by submitting a Request with empty Endpoint (and hence empty Operation and Arguments). The Response will have Result of the form:

{
	"Endpoints": [string, ..., string]
}

where Endpoints is an array of all available endpoints.

Available operations

The available operations can be obtained for a given endpoint can be obtained by submitting a Request with Endpoint set (and non-empty) and empty Operation (and hence empty Arguments). The Response will have Result of the form:

{
	"Operations": [string, ..., string]
}

where Operations is an array of all available operations for this endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlagSets added in v0.0.27

func FlagSets() []flag.Set

FlagSets returns the slice of flagsets for each registered endpoint.

func Run added in v0.0.27

func Run(ctx context.Context, l net.Listener, options ...Option) error

Run listens for and handles connections, terminating when the context fires. Upon return the listener will be closed.

Types

type Config

type Config struct {
	SSLCert     []byte // The SSL certificate
	SSLDisabled bool   // Is SSL disabled?
}

Config describes the configuration options that a proxy can set on an endpoint.

func (*Config) Copy added in v0.0.27

func (c *Config) Copy() *Config

Copy returns a copy of the configuration.

type CreationFunc added in v0.0.27

type CreationFunc func(context.Context, *Config, log.Interface) (Endpoint, error)

CreationFunc is the creation function for an endpoint.

type Description added in v0.0.27

type Description struct {
	Name       string       // The name of the endpoint
	Operations []string     // The supported operations
	Create     CreationFunc // The creation function for the endpoint
	Flag       flag.Flag    // An optional flag
	FlagSet    flag.Set     // An optional flag.Set
}

Description describes an endpoint

func (Description) Register added in v0.0.27

func (d Description) Register()

Register registers an endpoint handler.

type Endpoint

type Endpoint interface {
	io.Closer
	// Handle handles requests for operation 'op' with arguments 'args'.
	Handle(ctx context.Context, op string, args Message, lg log.Interface) (Message, error)
}

Endpoint is an endpoint.

type Message added in v0.0.27

type Message map[string]interface{}

Message is the unstructured message type.

func (Message) Keys added in v0.0.27

func (m Message) Keys() []string

Keys returns the keys, sorted in lex order.

func (Message) OnlyKeys added in v0.0.27

func (m Message) OnlyKeys(k ...string) error

OnlyKeys asserts that only (a subset of) the given keys are set.

func (Message) RequireKeys added in v0.0.27

func (m Message) RequireKeys(k ...string) error

RequireKeys asserts that the given keys are set.

func (Message) ToBool added in v0.0.27

func (m Message) ToBool(key string) (bool, bool, error)

ToBool attempts to return the entry for the given key as a boolean. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToBoolSlice added in v0.0.27

func (m Message) ToBoolSlice(key string) ([]bool, bool, error)

ToBoolSlice attempts to return the entry for the given key as a []bool. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToDuration added in v0.0.27

func (m Message) ToDuration(key string) (time.Duration, bool, error)

ToDuration attempts to return the entry for the given key as a time.Duration. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

A Duration is defined by the JSON:

integer|string

In the case where Duration is given by an integer, it gives the number of nanoseconds in the duration. In the case where Duration is given by a string, this will be converted to a time.Duration via time.ParseDuration. See [time#ParseDuration] for details on the format.

func (Message) ToFloat64 added in v0.0.27

func (m Message) ToFloat64(key string) (float64, bool, error)

ToFloat64 attempts to return the entry for the given key as a float64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToFloat64Slice added in v0.0.27

func (m Message) ToFloat64Slice(key string) ([]float64, bool, error)

ToFloat64Slice attempts to return the entry for the given key as a []float64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToInt added in v0.0.27

func (m Message) ToInt(key string) (int, bool, error)

ToInt attempts to return the entry for the given key as an int. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToInt64 added in v0.0.27

func (m Message) ToInt64(key string) (int64, bool, error)

ToInt64 attempts to return the entry for the given key as an int64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToInt64Slice added in v0.0.27

func (m Message) ToInt64Slice(key string) ([]int64, bool, error)

ToInt64Slice attempts to return the entry for the given key as a []int64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToIntSlice added in v0.0.27

func (m Message) ToIntSlice(key string) ([]int, bool, error)

ToIntSlice attempts to return the entry for the given key as a []int. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToMessage added in v0.0.27

func (m Message) ToMessage(key string) (Message, bool, error)

ToMessage attempts to return the entry for the given key as a Message. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToMessageSlice added in v0.0.27

func (m Message) ToMessageSlice(key string) ([]Message, bool, error)

ToMessageSlice attempts to return the entry for the given key as a []Message. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToString added in v0.0.27

func (m Message) ToString(key string) (string, bool, error)

ToString attempts to return the entry for the given key as a string. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToStringSlice added in v0.0.27

func (m Message) ToStringSlice(key string) ([]string, bool, error)

ToStringSlice attempts to return the entry for the given key as a []string. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.

func (Message) ToULID added in v0.0.27

func (m Message) ToULID(key string) (ulid.ULID, bool, error)

ToULID attempts to return the entry for the given key as a ulid.ULID. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion. Any record will be validated before being returned.

A ULID is defined by the JSON:

string

which must consist of exactly 26 characters taken from the alphabet:

0123456789ABCDEFGHJKMNPQRSTVWXYZ

A ULID is used to encode a ulid.ULID: see bitbucket.org/pcastools/ulid.

type Option added in v0.0.27

type Option interface {
	// contains filtered or unexported methods
}

Option sets options on a kvdb server.

func Log added in v0.0.27

func Log(lg log.Interface) Option

Log sets the logger.

func SSLCert added in v0.0.27

func SSLCert(crt []byte) Option

SSLCert adds the given SSL public certificate.

func SSLDisabled added in v0.0.27

func SSLDisabled() Option

SSLDisabled disables SSL.

Directories

Path Synopsis
cmd
Package fs is an endpoint for fsd.
Package fs is an endpoint for fsd.
Package gob is an endpoint for encoding and decoding of mathematical objects.
Package gob is an endpoint for encoding and decoding of mathematical objects.
internal
Package keyvalue is an abstract endpoint for key-value connections.
Package keyvalue is an abstract endpoint for key-value connections.
Package kvdb is an endpoint for the kvdb key-value driver.
Package kvdb is an endpoint for the kvdb key-value driver.
Package log is an endpoint for log messages.
Package log is an endpoint for log messages.
Package metrics is an endpoint for collecting metrics data.
Package metrics is an endpoint for collecting metrics data.
Package mongodb is an endpoint for the mongodb key-value driver.
Package mongodb is an endpoint for the mongodb key-value driver.
Package mysql is an endpoint for the mysql key-value driver.
Package mysql is an endpoint for the mysql key-value driver.
Package postgres is an endpoint for the postgres key-value driver.
Package postgres is an endpoint for the postgres key-value driver.
Package queue is an endpoint for the pcas queue system.
Package queue is an endpoint for the pcas queue system.
Package rangedb is an endpoint for rangedb.
Package rangedb is an endpoint for rangedb.
Package sqlite is an endpoint for the SQLite key-value driver.
Package sqlite is an endpoint for the SQLite key-value driver.
Package version is an endpoint for version information.
Package version is an endpoint for version information.

Jump to

Keyboard shortcuts

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