client

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigNamespaceNameAPIEndpoint = "/api/v1/configs/%s/%s"
	ConfigsNamespaceAPIEndpoint    = "/api/v1/configs/%s"
	AllConfigsAPIEndpoint          = "/api/v1/configs"
	LicenseStatusEndpoint          = "/api/v1/license"
)

Variables

View Source
var (
	// Send pings to the CDS server with this period. Must be less than PongWait.
	PingPeriod = 5 * time.Second

	// Time allowed to read the next pong message from the CDS server.
	PongWait = 8 * time.Second

	// Time allowed to write a message to the CDS server.
	WriteWait = 2 * time.Second

	// Period for retrying failed CDS connections.
	RetryPeriod = 1 * time.Second
)

Functions

func EmptyConfig

func EmptyConfig() *stnrv2.StunnerConfig

EmptyConfig builds a minimal configuration. The minimal config has a default authentication policy, static with a dummy username and password, and no listeners, servers or clusters.

func IsConfigDeleted

func IsConfigDeleted(conf *stnrv2.StunnerConfig) bool

IsConfigDeleted is a helper that allows to decide whether a config is being deleted. When a config is being removed (say, because the corresponding Gateway is deleted), the CDS server sends a validated zero-config for the client. This function is a quick helper to decide whether the config received is such a zero-config.

func IsZeroConfig

func IsZeroConfig(req *stnrv2.StunnerConfig) bool

IsZeroConfig checks whether the given config is a bootstrap config.

func ParseConfig

func ParseConfig(c []byte) (*stnrv2.StunnerConfig, error)

ParseConfig parses a YAML or JSON config of either version as it is, returning it as v2: a v1 config is converted. The v1 config API is deprecated.

func Substitute

func Substitute(c *stnrv2.StunnerConfig) (*stnrv2.StunnerConfig, error)

Substitute substitutes the environment of this process into a config with os.ExpandEnv, as a dataplane does with its own config: the placeholders stand for the environment of the dataplane pod. The credentials are taken as they are, so a password holding a "$" stays intact.

func ZeroConfig

func ZeroConfig(id string) *stnrv2.StunnerConfig

ZeroConfig builds a zero configuration used for bootstrapping STUNner.

Types

type AllConfigsAPI

type AllConfigsAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

AllConfigsAPI is the API for listing all configs in a namespace.

func (*AllConfigsAPI) Endpoint

func (a *AllConfigsAPI) Endpoint() (string, string)

func (*AllConfigsAPI) Get

func (*AllConfigsAPI) Poll

func (a *AllConfigsAPI) Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

func (*AllConfigsAPI) Watch

func (a *AllConfigsAPI) Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

type CDSClient

type CDSClient struct {
	CdsApi
	// contains filtered or unexported fields
}

CDSClient is a client for the config discovery service that knows how to poll configs for a specific gateway. Use the CDSAPI to access the general CDS client set.

func (*CDSClient) Load

func (p *CDSClient) Load() (*stnrv2.StunnerConfig, error)

Load grabs a new configuration from the config discovery server.

func (*CDSClient) String

func (p *CDSClient) String() string

String outputs the status of the client.

type CdsApi

type CdsApi interface {
	// Endpoint returns the address of the server plus the WebSocket API endpoint.
	Endpoint() (string, string)
	// Get loads the config(s) from the API endpoint.
	Get(ctx context.Context) ([]*stnrv2.StunnerConfig, error)
	// Watch watches config(s) from the API endpoint of a CDS server. If the server is not
	// available watch will retry, and if the connection goes away it will create a new one. If
	// set, the suppressDelete instructs the API to ignore config delete updates from the
	// server.
	Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error
	// Poll creates a one-shot config watcher without the retry mechanics of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error
	logging.LeveledLogger
}

func NewAllConfigsAPI

func NewAllConfigsAPI(addr string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

func NewConfigNamespaceNameAPI

func NewConfigNamespaceNameAPI(addr, namespace, name string, labels map[string]string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

func NewConfigsNamespaceAPI

func NewConfigsNamespaceAPI(addr, namespace string, logger logging.LeveledLogger, opts ...ClientOption) (CdsApi, error)

type Client

type Client interface {
	// Load grabs a new configuration from the config client.
	Load() (*stnrv2.StunnerConfig, error)
	// Watch listens to new configs from a config origin (config file or CDS server) and
	// returns them on the given channel. The context cancels the watcher. If the origin is not
	// available watch will retry. If set, the suppressDelete flag instructs the client to
	// ignore delete config (essentially zero-configs) from the origin.
	Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error
	// Poll creates a one-shot config watcher without the retry mechanics of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error
	fmt.Stringer
}

Client represents a generic config client. Currently supported config providers: http, ws, or file.

func New

func New(origin string, id string, labels map[string]string, logger logging.LoggerFactory) (Client, error)

New creates a generic config client. Origin is either a network address in the form "<IP>:<port>" or a proper HTTP/WS URI, in which case a CDS client is returned, or a proper file URL "file://<path>/<filename>" in which case a config file watcher is returned.

func NewCDSClient

func NewCDSClient(addr, id string, labels map[string]string, logger logging.LeveledLogger) (Client, error)

NewCDSClient creates a config discovery service client that can be used to load or watch STUNner configurations from a CDS remote server.

func NewConfigFileClient

func NewConfigFileClient(origin, id string, logger logging.LeveledLogger) (Client, error)

NewConfigFileClient creates a client that load or watch STUNner configurations from a local file.

type ClientOption

type ClientOption = api.ClientOption

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

type ConfigFileClient

type ConfigFileClient struct {
	// contains filtered or unexported fields
}

ConfigFileClient is the implementation of the Client interface for config files.

func (*ConfigFileClient) Load

Load grabs a new configuration from a config file.

func (*ConfigFileClient) Poll

func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

Poll watches the config file and emits new configs on the specified channel. Returns an error if further action is needed (tryWatchConfig is to be started) or nil on normal exit.

func (*ConfigFileClient) String

func (w *ConfigFileClient) String() string

String outputs the status of the client.

func (*ConfigFileClient) Watch

func (w *ConfigFileClient) Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

Watch watches a configuration file for changes. If no file exists at the given path, it will periodically retry until the file appears.

type ConfigList

type ConfigList struct {
	Version string            `json:"version"`
	Items   []json.RawMessage `json:"items"`
}

ConfigList is the config list the CDS server serves; items are decoded one by one, as either config version.

type ConfigNamespaceNameAPI

type ConfigNamespaceNameAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

func (*ConfigNamespaceNameAPI) Endpoint

func (a *ConfigNamespaceNameAPI) Endpoint() (string, string)

func (*ConfigNamespaceNameAPI) Get

func (*ConfigNamespaceNameAPI) Poll

func (a *ConfigNamespaceNameAPI) Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

func (*ConfigNamespaceNameAPI) Watch

func (a *ConfigNamespaceNameAPI) Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

type ConfigSkeleton

type ConfigSkeleton struct {
	ApiVersion string `json:"version"`
}

type ConfigsNamespaceAPI

type ConfigsNamespaceAPI struct {
	logging.LeveledLogger
	// contains filtered or unexported fields
}

ConfigsNamespaceAPI is the API for listing all configs in a namespace.

func (*ConfigsNamespaceAPI) Endpoint

func (a *ConfigsNamespaceAPI) Endpoint() (string, string)

func (*ConfigsNamespaceAPI) Get

func (*ConfigsNamespaceAPI) Poll

func (a *ConfigsNamespaceAPI) Poll(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

func (*ConfigsNamespaceAPI) Watch

func (a *ConfigsNamespaceAPI) Watch(ctx context.Context, ch chan<- *stnrv2.StunnerConfig, suppressDelete bool) error

type HttpRequestDoer

type HttpRequestDoer = api.HttpRequestDoer

type JSONPathArg

type JSONPathArg interface {
	Parse(arg string) (bool, error)
	Evaluate(data interface{}) (string, error)
}

JSONPathArg parses a `-jsonpath="... {jsonpath} ..."` expression and knows how to evaluate the parsed JSONpath query/queries on any data.

func NewJSONPath

func NewJSONPath() JSONPathArg

NewJSONPath creates a new JSONPathArg instance

type LicenseStatusClient

type LicenseStatusClient interface {
	LicenseStatus(ctx context.Context) (stnrv2.LicenseStatus, error)
}

func NewLicenseStatusClient

func NewLicenseStatusClient(addr string, logger logging.LeveledLogger, opts ...ClientOption) (LicenseStatusClient, error)

type Segment

type Segment struct {
	// String is the actual text of the segment (if any).
	String string
	// JSONQuery is the actual query in the segment.
	JSONQuery *jsonpath.JSONPath
	// Type indicates whether this is a regular string or an expression.
	Type SegmentType
}

Segment represents a part of a JSONPath string

type SegmentType

type SegmentType int

SegmentType identifies the type of string segment in JSONPath.

const (
	// String represents a plain text segment.
	String SegmentType = iota
	// Expression represents a segment enclosed in curly braces.
	Expression
)

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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