Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishapi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishapi
Commits
ffdca9a8
Commit
ffdca9a8
authored
Sep 05, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GetMgmtAddr() and GetSecretPath() to vsm.
parent
1aaf1a02
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
e2e_test.go
pkg/vsm/e2e_test.go
+44
-0
vsm.go
pkg/vsm/vsm.go
+36
-0
No files found.
pkg/vsm/e2e_test.go
View file @
ffdca9a8
...
...
@@ -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()"
)
}
}
pkg/vsm/vsm.go
View file @
ffdca9a8
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment