management

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LocalhostOnRandomPort = Addr{
	IP:   "127.0.0.1",
	Port: 0,
}

LocalhostOnRandomPort defines localhost address with randomly bound port

Functions

This section is empty.

Types

type Addr

type Addr struct {
	IP   string
	Port int
}

Addr struct represents local address on which listener waits for incoming management connections

func (*Addr) String

func (addr *Addr) String() string

String returns address string representation

type CommandWriter

type CommandWriter interface {
	SingleLineCommand(template string, args ...interface{}) (string, error)
	MultiLineCommand(template string, args ...interface{}) (string, []string, error)
}

CommandWriter represents openvpn management interface abstraction for middlewares to be able to send commands to openvpn process

type Management

type Management struct {
	BoundAddress Addr
	Connected    chan bool
	// contains filtered or unexported fields
}

Management structure represents connection and interface to openvpn management

func NewManagement

func NewManagement(socketAddress Addr, logPrefix string, middlewares ...Middleware) *Management

NewManagement creates new manager for given sock address, uses given log prefix for logging and takes a list of middlewares

func (*Management) Stop

func (management *Management) Stop()

Stop initiates managemnt shutdown

func (*Management) WaitForConnection

func (management *Management) WaitForConnection() error

WaitForConnection method starts listener on bind address and returns "real" bound address (with port not zero) and channel which receives true when connection is accepted or false overwise (i.e. listener stop requested). It returns non nil error on any error condition

type Middleware

type Middleware interface {
	Start(CommandWriter) error
	Stop(CommandWriter) error
	ConsumeLine(line string) (consumed bool, err error)
}

Middleware used to control openvpn process through management interface It's guaranteed that ConsumeLine callback will be called AFTER Start callback is finished CommandWriter passed on Stop callback can be already closed - expect errors when sending commands For efficiency and simplicity purposes ConsumeLine for each middleware is called from the same goroutine which consumes events from channel - avoid long running operations at all costs

type MockConnection

type MockConnection struct {
	WrittenLines      []string
	LastLine          string
	CommandResult     string
	MultilineResponse []string
}

MockConnection is mock openvpn management interface used for middleware testing

func (*MockConnection) MultiLineCommand

func (conn *MockConnection) MultiLineCommand(format string, args ...interface{}) (string, []string, error)

MultiLineCommand sends command to mocked connection and expects multiple line command response with END marker

func (*MockConnection) SingleLineCommand

func (conn *MockConnection) SingleLineCommand(format string, args ...interface{}) (string, error)

SingleLineCommand sends command to mocked connection and expects single line as command output (error or success)

Jump to

Keyboard shortcuts

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