client

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConfigNamespaceNameAPIEndpoint = "/api/v1/configs/%s/%s"
	ConfigsNamespaceAPIEndpoint    = "/api/v1/configs/%s"
	AllConfigsAPIEndpoint          = "/api/v1/configs"
)
View Source
const (
	DefaultCDSServerPort  = 13478
	CDSServerAddrEnv      = "CDS_SERVER_ADDR"
	CDSServerNamespaceEnv = "CDS_SERVER_NAME"
	CDSServerPortEnv      = "CDS_SERVER_PORT"
)

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 DiscoverK8sCDSServer added in v0.17.6

func DiscoverK8sCDSServer(ctx context.Context, k8sFlags *cliopt.ConfigFlags, cdsFlags *CDSConfigFlags, log logging.LeveledLogger) (string, error)

DiscoverK8sCDSServer discovers a CDS Server located in a Kubernetes cluster and returns an address that a CDS client can be opened to for reaching that CDS server. If necessary, opens a port-forward connection to the remote cluster.

func ParseConfig

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

ParseConfig parses a raw buffer holding a configuration, substituting environment variables for placeholders in the configuration. Returns the new configuration or error if parsing fails.

func ZeroConfig

func ZeroConfig(id string) *stnrv1.StunnerConfig

ZeroConfig builds a zero configuration useful for bootstrapping STUNner. The minimal config defaults to static authentication with a dummy username and password and opens no listeners or clusters.

Types

type AllConfigsAPI added in v0.16.2

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

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

func (*AllConfigsAPI) Endpoint added in v0.16.2

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

func (*AllConfigsAPI) Get added in v0.16.2

func (*AllConfigsAPI) Poll added in v0.16.2

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

func (*AllConfigsAPI) Watch added in v0.16.2

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

type CDSClient added in v0.16.2

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 added in v0.16.2

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

Load grabs a new configuration from the config doscovery server.

func (*CDSClient) String added in v0.16.2

func (p *CDSClient) String() string

String outputs the status of the client.

type CDSConfigFlags added in v0.17.6

type CDSConfigFlags struct {
	// ServerAddr is an explicit IP address for the CDS server.
	ServerAddr string
	// ServerNamespace is the namespace of the CDS server pod.
	ServerNamespace string
	// ServerPort is the port of the CDS server pod.
	ServerPort int
}

CDSConfigFlags composes a set of flags for CDS server discovery

func NewCDSConfigFlags added in v0.17.6

func NewCDSConfigFlags() *CDSConfigFlags

NewCDSConfigFlags returns CDS service discovery flags with default values set.

func (*CDSConfigFlags) AddFlags added in v0.17.6

func (f *CDSConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds CDS server discovery configuration flags to a given flagset.

type CdsApi added in v0.17.1

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) ([]*stnrv1.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.
	Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	logging.LeveledLogger
}

func NewAllConfigsAPI added in v0.16.2

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

func NewConfigNamespaceNameAPI added in v0.16.2

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

func NewConfigsNamespaceAPI added in v0.16.2

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() (*stnrv1.StunnerConfig, error)
	// Watch grabs new configs from a config origin (config file or CDS server) and returns
	// them on the channel. The context cancels the watcher. If the origin is not available
	// watch will retry.
	Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	// Poll creates a one-shot config watcher without the retry mechanincs of Watch.
	Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) error
	fmt.Stringer
}

Client represents a generic config client. Currently supported config providers: http, ws, or file. Configuration obtained through the client are not validated, make sure to validate on the receiver side.

func New added in v0.16.2

func New(origin string, id string, logger logging.LoggerFactory) (Client, error)

New creates a generic config client.

func NewCDSClient added in v0.16.2

func NewCDSClient(addr, id 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 added in v0.16.2

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 added in v0.17.6

type ClientOption = api.ClientOption

func WithHTTPClient added in v0.17.6

func WithHTTPClient(doer HttpRequestDoer) ClientOption

type ConfigFileClient added in v0.16.2

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

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

func (*ConfigFileClient) Load added in v0.16.2

Load grabs a new configuration from a config file.

func (*ConfigFileClient) Poll added in v0.16.2

func (w *ConfigFileClient) Poll(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) 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 added in v0.16.2

func (w *ConfigFileClient) String() string

String outputs the status of the client.

func (*ConfigFileClient) Watch added in v0.16.2

func (w *ConfigFileClient) Watch(ctx context.Context, ch chan<- *stnrv1.StunnerConfig) 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 added in v0.16.2

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

type ConfigNamespaceNameAPI added in v0.16.2

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

func (*ConfigNamespaceNameAPI) Endpoint added in v0.16.2

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

func (*ConfigNamespaceNameAPI) Get added in v0.16.2

func (*ConfigNamespaceNameAPI) Poll added in v0.16.2

func (*ConfigNamespaceNameAPI) Watch added in v0.16.2

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

type ConfigSkeleton added in v0.16.1

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

type ConfigsNamespaceAPI added in v0.16.2

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

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

func (*ConfigsNamespaceAPI) Endpoint added in v0.16.2

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

func (*ConfigsNamespaceAPI) Get added in v0.16.2

func (*ConfigsNamespaceAPI) Poll added in v0.16.2

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

func (*ConfigsNamespaceAPI) Watch added in v0.16.2

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

type HttpRequestDoer added in v0.17.6

type HttpRequestDoer = api.HttpRequestDoer

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