options

package
v0.0.0-...-d32eb86 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package options provides configurable options for server setup and runtime.

Index

Constants

View Source
const (
	DefaultBindAddress   = "0.0.0.0"
	DefaultBindPort      = 8443
	DefaultPairName      = "apiserver"
	DefaultCertDirectory = "/var/run/apiserver"
)

Default values for secure serving options

Variables

This section is empty.

Functions

func CreateListener

func CreateListener(addr string) (net.Listener, int, error)

CreateListener sets up a TCP listener on the specified address.

Types

type CertKey

type CertKey struct {
	CertFile string `json:"cert-file"        mapstructure:"cert-file"`
	KeyFile  string `json:"private-key-file" mapstructure:"private-key-file"`
}

CertKey holds paths for a certificate and its corresponding key file.

type FeatureOptions

type FeatureOptions struct {
	EnableProfiling bool `json:"profiling"      mapstructure:"profiling"`
	EnableMetrics   bool `json:"enable-metrics" mapstructure:"enable-metrics"`
}

FeatureOptions contains configuration items related to API server features.

func NewFeatureOptions

func NewFeatureOptions() *FeatureOptions

NewFeatureOptions creates a FeatureOptions object with default parameters.

func (*FeatureOptions) AddFlags

func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags related to features for a specific api server to the specified FlagSet.

func (*FeatureOptions) ApplyTo

func (o *FeatureOptions) ApplyTo(c *server.Config) error

ApplyTo applies the run options to the method receiver and returns self.

func (*FeatureOptions) Validate

func (o *FeatureOptions) Validate() []error

Validate is used to parse and validate the parameters entered by the user at the command line when the program starts.

type GRPCOptions

type GRPCOptions struct {
	BindAddress string `json:"bind-address" mapstructure:"bind-address"`
	BindPort    int    `json:"bind-port"    mapstructure:"bind-port"`
	MaxMsgSize  int    `json:"max-msg-size" mapstructure:"max-msg-size"`
}

GRPCOptions are for creating an unauthenticated, unauthorized, insecure port. No one should be using these anymore.

func NewGRPCOptions

func NewGRPCOptions() *GRPCOptions

NewGRPCOptions is for creating an unauthenticated, unauthorized, insecure port. No one should be using these anymore.

func (*GRPCOptions) AddFlags

func (s *GRPCOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags related to features for a specific api server to the specified FlagSet.

func (*GRPCOptions) Validate

func (s *GRPCOptions) Validate() []error

Validate is used to parse and validate the parameters entered by the user at the command line when the program starts.

type GeneratableKeyCert

type GeneratableKeyCert struct {
	CertKey CertKey `json:"cert-key" mapstructure:"cert-key"`

	CertDirectory string `json:"cert-dir"  mapstructure:"cert-dir"`

	PairName string `json:"pair-name" mapstructure:"pair-name"`
}

GeneratableKeyCert holds configuration for generating or locating key and cert files.

type InsecureServingOptions

type InsecureServingOptions struct {
	BindAddress string `json:"bind-address" mapstructure:"bind-address"` // IP address to bind the server.
	BindPort    int    `json:"bind-port"    mapstructure:"bind-port"`    // Port number to bind the server.
}

InsecureServingOptions represents configuration options for insecure server communication (HTTP).

func NewInsecureServingOptions

func NewInsecureServingOptions() *InsecureServingOptions

NewInsecureServingOptions initializes a new InsecureServingOptions object with default values.

func (*InsecureServingOptions) AddFlags

func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds the InsecureServingOptions flags to the provided FlagSet.

func (*InsecureServingOptions) ApplyTo

func (s *InsecureServingOptions) ApplyTo(c *server.Config) error

ApplyTo updates the provided server.Config with the settings from InsecureServingOptions.

func (*InsecureServingOptions) Validate

func (s *InsecureServingOptions) Validate() []error

Validate checks if the settings of InsecureServingOptions are valid.

type JwtOptions

type JwtOptions struct {
	Realm      string        `json:"realm"       mapstructure:"realm" validate:"required"`
	Key        string        `json:"key"         mapstructure:"key" validate:"required,len=32"`
	Timeout    time.Duration `json:"timeout"     mapstructure:"timeout" validate:"required"`
	MaxRefresh time.Duration `json:"max-refresh" mapstructure:"max-refresh" validate:"required"`
}

JwtOptions defines the configuration options related to JWT tokens.

func NewJwtOptions

func NewJwtOptions() *JwtOptions

NewJwtOptions returns a JwtOptions object with default values.

func (*JwtOptions) AddFlags

func (s *JwtOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds the JWT-related flags to the provided FlagSet.

func (*JwtOptions) ApplyTo

func (s *JwtOptions) ApplyTo(c *server.Config) error

ApplyTo applies the current options to the provided server configuration.

func (*JwtOptions) Validate

func (s *JwtOptions) Validate() []error

Validate checks and validates the user-provided parameters during program startup.

type MySQLOptions

type MySQLOptions struct {
	Host                  string        `json:"host,omitempty"                     mapstructure:"host"`
	Username              string        `json:"username,omitempty"                 mapstructure:"username"`
	Password              string        `json:"-"                                  mapstructure:"password"`
	Database              string        `json:"database"                           mapstructure:"database"`
	MaxIdleConnections    int           `json:"max-idle-connections,omitempty"     mapstructure:"max-idle-connections"`
	MaxOpenConnections    int           `json:"max-open-connections,omitempty"     mapstructure:"max-open-connections"`
	MaxConnectionLifeTime time.Duration `json:"max-connection-life-time,omitempty" mapstructure:"max-connection-life-time"`
	LogLevel              int           `json:"log-level"                          mapstructure:"log-level"`
}

MySQLOptions defines options for mysql database.

func NewMySQLOptions

func NewMySQLOptions() *MySQLOptions

NewMySQLOptions create a `zero` value instance.

func (*MySQLOptions) AddFlags

func (o *MySQLOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags related to mysql storage for a specific APIServer to the specified FlagSet.

func (*MySQLOptions) NewClient

func (o *MySQLOptions) NewClient() (*gorm.DB, error)

NewClient create mysql store with the given config.

func (*MySQLOptions) Validate

func (o *MySQLOptions) Validate() []error

Validate verifies flags passed to MySQLOptions. Validate verifies fields of MySQLOptions.

type RateLimit

type RateLimit struct {
	RequestsPerSecond float64 `json:"requests-per-second" mapstruct ure:"requests-per-second"`
	BurstSize         int     `json:"burst-size" mapstructure:"burst-size"`
}

RateLimit struct defines the settings for rate limiting.

type RateLimitOptions

type RateLimitOptions struct {
	RequestsPerSecond float64              `json:"requests-per-second" mapstructure:"requests-per-second"`
	BurstSize         int                  `json:"burst-size" mapstructure:"burst-size"`
	CustomLimits      map[string]RateLimit `json:"custom-limits" mapstructure:"custom-limits"`
}

func NewRateLimitOptions

func NewRateLimitOptions() *RateLimitOptions

func (*RateLimitOptions) ApplyTo

func (r *RateLimitOptions) ApplyTo(c *server.Config) error

func (*RateLimitOptions) Validate

func (r *RateLimitOptions) Validate() []error

Validate checks and validates the user-provided parameters during program startup.

type RedisOptions

type RedisOptions struct {
	Host                  string   `json:"host"                     mapstructure:"host"                     description:"Redis service host address"`
	Port                  int      `json:"port"`
	Addrs                 []string `json:"addrs"                    mapstructure:"addrs"`
	Username              string   `json:"username"                 mapstructure:"username"`
	Password              string   `json:"password"                 mapstructure:"password"`
	Database              int      `json:"database"                 mapstructure:"database"`
	MasterName            string   `json:"master-name"              mapstructure:"master-name"`
	MaxIdle               int      `json:"optimisation-max-idle"    mapstructure:"optimisation-max-idle"`
	MaxActive             int      `json:"optimisation-max-active"  mapstructure:"optimisation-max-active"`
	Timeout               int      `json:"timeout"                  mapstructure:"timeout"`
	EnableCluster         bool     `json:"enable-cluster"           mapstructure:"enable-cluster"`
	UseSSL                bool     `json:"use-ssl"                  mapstructure:"use-ssl"`
	SSLInsecureSkipVerify bool     `json:"ssl-insecure-skip-verify" mapstructure:"ssl-insecure-skip-verify"`
}

RedisOptions defines options for redis cluster.

func NewRedisOptions

func NewRedisOptions() *RedisOptions

NewRedisOptions create a `zero` value instance.

func (*RedisOptions) AddFlags

func (o *RedisOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet.

func (*RedisOptions) Validate

func (o *RedisOptions) Validate() []error

Validate verifies flags passed to RedisOptions.

type SecureServingOptions

type SecureServingOptions struct {
	BindAddress string `json:"bind-address" mapstructure:"bind-address"`
	BindPort    int    `json:"bind-port"    mapstructure:"bind-port"`
	Required    bool
	ServerCert  GeneratableKeyCert `json:"tls"          mapstructure:"tls"`
}

SecureServingOptions represents configuration for securely serving requests (usually over HTTPS).

func NewSecureServingOptions

func NewSecureServingOptions() *SecureServingOptions

NewSecureServingOptions creates a new instance of SecureServingOptions with default values.

func (*SecureServingOptions) AddFlags

func (s *SecureServingOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags for the secure serving options to the given flag set.

func (*SecureServingOptions) ApplyTo

func (s *SecureServingOptions) ApplyTo(c *server.Config) error

ApplyTo sets up the secure serving info on the given server Config.

func (*SecureServingOptions) Complete

func (s *SecureServingOptions) Complete() error

Complete finalizes the SecureServingOptions after flag parsing.

func (*SecureServingOptions) Validate

func (s *SecureServingOptions) Validate() []error

Validate checks for any errors in the secure serving options.

type ServerRunOptions

type ServerRunOptions struct {
	Mode        string   `json:"mode"        mapstructure:"mode"`        // Mode specifies the server's operating mode (e.g., debug, test, release).
	Healthz     bool     `json:"healthz"     mapstructure:"healthz"`     // Healthz indicates whether a /healthz endpoint should be established for readiness checks.
	Middlewares []string `json:"middlewares" mapstructure:"middlewares"` // Middlewares lists the middlewares allowed for the server.
}

ServerRunOptions represents the customizable options for running the server. It includes fields such as Mode, Healthz status, and the middlewares used.

func NewServerRunOptions

func NewServerRunOptions() *ServerRunOptions

NewServerRunOptions initializes a new ServerRunOptions instance with default settings from the server's configuration.

func (*ServerRunOptions) AddFlags

func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet)

AddFlags binds the ServerRunOptions fields to command-line flags using the given FlagSet (fs). This allows users to customize server behavior via command-line options.

func (*ServerRunOptions) ApplyTo

func (s *ServerRunOptions) ApplyTo(c *server.Config) error

ApplyTo updates the given server configuration (c) with the values from the ServerRunOptions.

func (*ServerRunOptions) Validate

func (s *ServerRunOptions) Validate() []error

Validate checks the ServerRunOptions for any inconsistencies or errors. Currently, it always returns an empty error slice but can be extended for more complex validations.

Jump to

Keyboard shortcuts

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