Commit ffdca9a8 authored by Geoff Simmons's avatar Geoff Simmons

Add GetMgmtAddr() and GetSecretPath() to vsm.

parent 1aaf1a02
......@@ -238,3 +238,47 @@ func TestGet(t *testing.T) {
t.Error("Expected empty string for Get(foo, bar), got:", foobar)
}
}
func TestGetMgmtAddr(t *testing.T) {
v := New()
defer v.Destroy()
if v.VSM == nil {
t.Fatal("VSM handle is nil")
return
}
if err := v.Attach(""); err != nil {
t.Fatal("Attach(default):", err)
return
}
addr, err := v.GetMgmtAddr()
if err != nil {
t.Error("GetMgmtAddr():", err)
}
if addr == "" {
t.Error("Got empty string for GetMgmtAddr()")
}
}
func TestGetSecretPath(t *testing.T) {
v := New()
defer v.Destroy()
if v.VSM == nil {
t.Fatal("VSM handle is nil")
return
}
if err := v.Attach(""); err != nil {
t.Fatal("Attach(default):", err)
return
}
path, err := v.GetSecretPath()
if err != nil {
t.Error("GetSecretPath():", err)
}
if path == "" {
t.Error("Got empty string for GetSecretPath()")
}
}
......@@ -62,6 +62,7 @@ import "C"
import (
"errors"
"strconv"
"strings"
"time"
"unsafe"
)
......@@ -214,3 +215,38 @@ func (v *VSM) Get(class string, ident string) (string, error) {
C.free(unsafe.Pointer(cdup))
return dup, nil
}
// GetMgmtAddr is a convenience wrapper for Get() that returns the
// network address at which Varnish is listening for management
// commands, according to the protocol documented in
// varnish-cli(7). The address may have been set with the Varnish -T
// option, or Varnish may have generated the address itself (if not -T
// option was set).
//
// Clients such as the admin package or varnishadm(1) can connect to
// this address and issue commands to the Varnish management process.
//
// The address is a string of the form "address:port", so it is
// suitable for use with the Dial() method of the admin package.
func (v *VSM) GetMgmtAddr() (string, error) {
targ, err := v.Get("Arg", "-T")
if err != nil {
return "", err
}
targ = strings.TrimSpace(targ)
targ = strings.Replace(targ, " ", ":", 1)
return targ, nil
}
// GetSecretPath is a convenience wrapper for Get() that returns the
// path of the file that Varnish uses for authenticating connections
// to the management address. the authentication protocol is
// documented in varnish-cli(7).
func (v *VSM) GetSecretPath() (string, error) {
sarg, err := v.Get("Arg", "-S")
if err != nil {
return "", err
}
sarg = strings.TrimSpace(sarg)
return sarg, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment