spoe

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

README

GoDoc

SPOE in Go

An implementation of the SPOP protocol in Go. (https://www.haproxy.org/download/2.0/doc/SPOE.txt)

SPOE

From Haproxy's documentation :

SPOE is a feature introduced in HAProxy 1.7. It makes possible the communication with external components to retrieve some info. The idea started with the problems caused by most ldap libs not working fine in event-driven systems (often at least the connect() is blocking). So, it is hard to properly implement Single Sign On solution (SSO) in HAProxy. The SPOE will ease this kind of processing, or we hope so.

Now, the aim of SPOE is to allow any kind of offloading on the streams. First releases, besides being experimental, won't do lot of things. As we will see, there are few handled events and even less actions supported. Actually, for now, the SPOE can offload the processing before "tcp-request content", "tcp-response content", "http-request" and "http-response" rules. And it only supports variables definition. But, in spite of these limited features, we can easily imagine to implement SSO solution, ip reputation or ip geolocation services.

How to use

package main

import (
	"fmt"
	"net"

	"log"

	spoe "github.com/criteo/haproxy-spoe-go"
)

func getReputation(ip net.IP) (float64, error) {
	// implement IP reputation code here
	return 1.0, nil
}

func main() {
	agent := spoe.New(func(messages *spoe.MessageIterator) ([]spoe.Action, error) {
		reputation := 0.0

		for messages.Next() {
			msg := messages.Message

			if msg.Name != "ip-rep" {
				continue
			}

			var ip net.IP
			for msg.Args.Next() {
				arg := msg.Args.Arg

				if arg.Name == "ip" {
					var ok bool
					ip, ok = arg.Value.(net.IP)
					if !ok {
						return nil, fmt.Errorf("spoe handler: expected ip in message, got %+v", ip)
					}
				}
			}

			var err error
			reputation, err = getReputation(ip)
			if err != nil {
				return nil, fmt.Errorf("spoe handler: error processing request: %s", err)
			}
		}

		return []spoe.Action{
			spoe.ActionSetVar{
				Name:  "reputation",
				Scope: spoe.VarScopeSession,
				Value: reputation,
			},
		}, nil
	})

	if err := agent.ListenAndServe("tcp", ":9000"); err != nil {
		log.Fatal(err)
	}
}


Documentation

Index

Constants

View Source
const (
	VarScopeProcess     varScope = 0
	VarScopeSession     varScope = 1
	VarScopeTransaction varScope = 2
	VarScopeRequest     varScope = 3
	VarScopeResponse    varScope = 4
)

Variables

This section is empty.

Functions

func DecodeHeaders

func DecodeHeaders(headers []byte) (http.Header, error)

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

type ActionSetVar

type ActionSetVar struct {
	Name  string
	Scope varScope
	Value interface{}
}

type ActionUnsetVar

type ActionUnsetVar struct {
	Name  string
	Scope varScope
}

type Agent

type Agent struct {
	Handler Handler
	// contains filtered or unexported fields
}

func New

func New(h Handler) *Agent

func NewWithConfig

func NewWithConfig(h Handler, cfg Config) *Agent

func (*Agent) ListenAndServe

func (a *Agent) ListenAndServe(proto, addr string) error

func (*Agent) Serve

func (a *Agent) Serve(lis net.Listener) error

type Arg

type Arg struct {
	Name  string
	Value interface{}
}

type ArgIterator

type ArgIterator struct {
	Arg Arg
	// contains filtered or unexported fields
}

func (*ArgIterator) Count

func (i *ArgIterator) Count() int

func (*ArgIterator) Map

func (i *ArgIterator) Map() map[string]interface{}

func (*ArgIterator) Next

func (i *ArgIterator) Next() bool

type Config

type Config struct {
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	IdleTimeout    time.Duration
	MaxConnections int
}

type EngKey

type EngKey struct {
	FrameSize int
	Engine    string
	Conn      net.Conn
}

type Engine

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

type Frame

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

type Handler

type Handler func(msgs *MessageIterator) ([]Action, error)

type Message

type Message struct {
	Name string
	Args *ArgIterator
}

type MessageIterator

type MessageIterator struct {
	Message Message
	// contains filtered or unexported fields
}

func (*MessageIterator) Error

func (i *MessageIterator) Error() error

func (*MessageIterator) Next

func (i *MessageIterator) Next() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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