Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
Addr struct represents local address on which listener waits for incoming management connections
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) 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)