config

package
v0.0.0-...-baa1a54 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 13 Imported by: 233

Documentation

Overview

Package config contains a Config struct for kites.

Index

Constants

View Source
const (
	WebSocket = iota
	XHRPolling
	Auto
)

Variables

View Source
var CookieJar, _ = cookiejar.New(nil)

CookieJar ignoring err: the implementation of New() doesn't have any error to be returned yet it returns, so it's totally safe to neglect the error

View Source
var DefaultConfig = &Config{
	Username:    "unknown",
	Environment: "unknown",
	Region:      "unknown",
	IP:          "0.0.0.0",
	Port:        0,
	Transport:   Auto,
	Timeout:     15 * time.Second,
	XHR: &http.Client{
		Jar: CookieJar,
	},
	Client: &http.Client{
		Timeout: 15 * time.Second,
		Jar:     CookieJar,
	},
	Websocket: &websocket.Dialer{
		HandshakeTimeout: 15 * time.Second,
		Jar:              CookieJar,
	},
	SockJS: &sockjs.Options{
		Websocket:       sockjs.DefaultOptions.Websocket,
		JSessionID:      sockjs.DefaultOptions.JSessionID,
		SockJSURL:       sockjs.DefaultOptions.SockJSURL,
		HeartbeatDelay:  10 * time.Second,
		DisconnectDelay: 10 * time.Second,
		ResponseLimit:   sockjs.DefaultOptions.ResponseLimit,
	},
}

DefaultConfig contains the default settings.

View Source
var Transports = map[string]Transport{
	"WebSocket":  WebSocket,
	"XHRPolling": XHRPolling,
	"auto":       Auto,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	// Options for Kite
	Username              string    // Username to set when registering to Kontrol.
	Environment           string    // Kite environment to set when registering to Kontrol.
	Region                string    // Kite region to set when registering to Kontrol.
	Id                    string    // Kite ID to use when registering to Kontrol.
	KiteKey               string    // The kite.key value to use for "kiteKey" authentication.
	DisableAuthentication bool      // Do not require authentication for requests.
	DisableConcurrency    bool      // Do not process messages concurrently.
	Transport             Transport // SockJS transport to use.

	IP   string // IP of the kite server.
	Port int    // Port number of the kite server.

	// VerifyFunc is used to verify the public key of the signed token.
	//
	// If the pub key is not to be trusted, the function must return
	// kite.ErrKeyNotTrusted error.
	//
	// If nil, the default verify is used. By default the public key
	// is verified by calling Kontrol and the result cached for
	// VerifyTTL seconds if KontrolVerify is true. Otherwise
	// only public keys that are the same as the KontrolKey one are
	// accepted.
	VerifyFunc func(pub string) error

	// VerifyTTL is used to control time after result of a single
	// VerifyFunc's call expires.
	//
	// When <0, the result is not cached.
	//
	// When 0, the default value of 300s is used.
	VerifyTTL time.Duration

	// VerifyAudienceFunc is used to verify the audience of JWT token.
	//
	// If nil, the default audience verify function is used which
	// expects the aud to be a kite path that matches the username,
	// environment and name of the client.
	VerifyAudienceFunc func(client *protocol.Kite, aud string) error

	// XHR is a HTTP client used for polling on responses for a XHR transport.
	//
	// Required.
	XHR *http.Client

	// Timeout specified max time waiting for the following operations to complete:
	//
	//   - polling on an XHR connection
	//   - default timeout for certain kite requests (Kontrol API)
	//   - HTTP heartbeats and register method
	//
	// NOTE: Ensure the Timeout is higher than SockJS.HeartbeatDelay, otherwise
	// XHR connections may get randomly closed.
	//
	// TODO(rjeczalik): Make kite heartbeats configurable as well.
	Timeout time.Duration

	// Client is a HTTP client used for issuing HTTP register request and
	// HTTP heartbeats.
	Client *http.Client

	// Websocket is used for creating a client for a websocket transport.
	//
	// If custom one is used, ensure any complemenrary field is also
	// set in sockjs.WebSocketUpgrader value (for server connections).
	//
	// Required.
	Websocket *websocket.Dialer

	// SockJS are used to configure SockJS handler.
	//
	// Required.
	SockJS *sockjs.Options

	// Serve is serving HTTP requests using handler on requests
	// comming from the given listener.
	//
	// If Serve is nil, http.Serve is used by default.
	Serve func(net.Listener, http.Handler) error

	KontrolURL  string
	KontrolKey  string
	KontrolUser string

	// UseWebRTC is the flag for Kite's to communicate over WebRTC if possible.
	UseWebRTC bool
}

Options is passed to kite.New when creating new instance.

func Get

func Get() (*Config, error)

func MustGet

func MustGet() *Config

func New

func New() *Config

New returns a new Config initialized with defaults.

func NewFromKiteKey

func NewFromKiteKey(file string) (*Config, error)

NewFromKiteKey parses the given kite key file and gives a new Config value.

func (*Config) Copy

func (c *Config) Copy() *Config

Copy returns a new copy of the config object.

func (*Config) ReadEnvironmentVariables

func (c *Config) ReadEnvironmentVariables() error

func (*Config) ReadKiteKey

func (c *Config) ReadKiteKey() error

ReadKiteKey parsed the user's kite key and returns a new Config.

func (*Config) ReadToken

func (c *Config) ReadToken(key *jwt.Token) error

ReadToken reads Kite Claims from JWT token and uses them to initialize Config.

type Transport

type Transport int

Transport defines the underlying transport to be used

func (Transport) String

func (t Transport) String() string

Jump to

Keyboard shortcuts

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