management

package
v0.0.0-...-64126c4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright 2020 BlockDev AG SPDX-License-Identifier: AGPL-3.0-only

Copyright 2020 BlockDev AG SPDX-License-Identifier: AGPL-3.0-only

Copyright 2020 BlockDev AG SPDX-License-Identifier: AGPL-3.0-only

Copyright 2020 BlockDev AG SPDX-License-Identifier: AGPL-3.0-only

Copyright 2020 BlockDev AG SPDX-License-Identifier: AGPL-3.0-only

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(ctx context.Context, addr Addr) *Management

NewManagement creates new manager for given sock address

func (*Management) AddMiddleware

func (m *Management) AddMiddleware(mw Middleware)

AddMiddleware adds middleware to the management interface.

func (*Management) Listen

func (m *Management) Listen() error

Listen starts listening for incoming connections on given address. It's expected that only one connection will be accepted.

func (*Management) Stop

func (m *Management) Stop()

Stop initiates shutdown of management interface

type Middleware

type Middleware interface {
	Start(CommandWriter) error
	Stop(CommandWriter) error
	ProcessEvent(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