configfilter

package module
v0.0.0-...-cc69dfe Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2017 License: MIT Imports: 10 Imported by: 0

README

Configfilter for Skipper

Configfilter implements a data client and a filter for Skipper (https://github.com/zalando/skipper) that provides a push API for route configuration.

Please, find the documentation here: https://godoc.org/github.com/aryszka/configfilter

Documentation

Overview

Package configfilter implements a Skipper data client that receives route configuration through a filter in a Skipper route.

The route containing the config filter can be defined in the initialization options of the data client (see SelfRoutes), or in routes taken from another data client. The data client needs to be passed to Skipper among the custom data clients.

The config filter provides an HTTP API to get/set/delete all or individual routes. It has two endpoints, one for accessing all the routes, and one for accessing individual routes with their ID. For individual routes, the routing needs to include the :routeid wildcard in the path predicate.

See the value of the APIDescription constant for the API description.

Example
package main

import (
	"bytes"
	"io"
	"log"
	"net/http"
	"os"

	"github.com/aryszka/configfilter"
	"github.com/zalando/skipper"
	"github.com/zalando/skipper/filters"
	"github.com/zalando/skipper/routing"
)

func main() {
	go func() {
		cf := configfilter.New(configfilter.Options{
			DefaultRoutes: configfilter.SelfRoutes,
		})
		defer cf.Close()

		if err := skipper.Run(skipper.Options{
			Address:           ":9090",
			CustomFilters:     []filters.Spec{cf},
			CustomDataClients: []routing.DataClient{cf},
		}); err != nil {
			log.Println(err)
		}
	}()

	rsp, err := http.Post("http://localhost:9090/__config", "text/plain", bytes.NewBufferString(`
		foo: Path("/foo") -> "https://foo.example.org";
		bar: Path("/bar") -> "https://bar.example.org"
	`))
	if err != nil {
		log.Println(err)
		return
	}
	defer rsp.Body.Close()

	rsp, err = http.Get("http://localhost:9090/__config")
	if err != nil {
		log.Println(err)
		return
	}
	defer rsp.Body.Close()

	io.Copy(os.Stdout, rsp.Body)

}
Output:

foo: Path("/foo")
  -> "https://foo.example.org";
bar: Path("/bar")
  -> "https://bar.example.org";
__config: Path("/__config")
  -> config()
  -> <shunt>;
__config__singleRoute: Path("/__config/:routeid")
  -> config()
  -> <shunt>

Index

Examples

Constants

View Source
const (
	// Name is the name of the config filter in eskip documents.
	Name = "config"

	// DefaultSelfID is used as the default route ID for the API root endpoint.
	DefaultSelfID = "__config"

	// DefaultRoot is the default path of the API root endpoint.
	DefaultRoot = "/" + DefaultSelfID
)
View Source
const APIDescription = `` /* 2052-byte string literal not displayed */

APIDescription is printed when help content is requested.

Variables

View Source
var SelfRoutes = []*eskip.Route{{
	Id:      DefaultSelfID,
	Path:    DefaultRoot,
	Filters: []*eskip.Filter{{Name: Name}},
	Shunt:   true,
}, {
	Id:      DefaultSelfID + "__singleRoute",
	Path:    DefaultRoot + "/:routeid",
	Filters: []*eskip.Filter{{Name: Name}},
	Shunt:   true,
}}

SelfRoutes contain route specifications that can be used in the Options as API endpoints for the data client.

Functions

This section is empty.

Types

type Options

type Options struct {

	// DefaultRoutes contains routes that the data client will always include
	// in the routing. They cannot be changed or deleted through the API.
	//
	// It is a good practice to include two routes to the API endpoint: an API root
	// endpoint with all the routes and an endpoint for the individual routes. The
	// route for the individual routes is expected to have a path predicate with a
	// wildcard called routeid, e.g. Path("/__config/:routeid").
	DefaultRoutes []*eskip.Route
	// contains filtered or unexported fields
}

Options is used to provide initialization options for the config filter.

type Spec

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

Spec implements a Skipper data client and a filter specification, where the data client for the routing table accepts route updates through an API served by itself as a filter.

func New

func New(o Options) *Spec

New initializes a data client/filter specification for Skipper route configurations.

func (*Spec) Close

func (s *Spec) Close()

Close releases the resource taken by the data client.

func (*Spec) CreateFilter

func (s *Spec) CreateFilter(_ []interface{}) (filters.Filter, error)

CreateFilter creates a config filter. It iscalled by the routing package. (Skipper's filters.Spec implementation.)

func (*Spec) LoadAll

func (s *Spec) LoadAll() ([]*eskip.Route, error)

LoadAll returns all the current routes. (Skipper's routing.DataClient implementation.)

func (*Spec) LoadUpdate

func (s *Spec) LoadUpdate() ([]*eskip.Route, []string, error)

LoadUpdate returns all changes since the last call to LoadAll or LoadUpdate. (Skipper's routing.DataClient implementation.)

func (*Spec) Name

func (s *Spec) Name() string

Name returns the name of the filter in eskip documents ("config"). (Skipper's filters.Spec implementation.)

Jump to

Keyboard shortcuts

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