mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-10-26 10:10:36 +08:00
gvproxy: command: Add AddServiceEndpoint
This adds GvproxyCommand.AddServiceEndpoint() for the newly added --services argument. This API is a helper for users of gvproxy to have a more convenient way to generate its command line. Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
@@ -19,6 +19,9 @@ type GvproxyCommand struct {
|
|||||||
// List of endpoints the user wants to listen to
|
// List of endpoints the user wants to listen to
|
||||||
endpoints []string
|
endpoints []string
|
||||||
|
|
||||||
|
// List of service endpoints the user wants to listen to
|
||||||
|
servicesEndpoints []string
|
||||||
|
|
||||||
// Map of different sockets provided by user (socket-type flag:socket)
|
// Map of different sockets provided by user (socket-type flag:socket)
|
||||||
sockets map[string]string
|
sockets map[string]string
|
||||||
|
|
||||||
@@ -62,6 +65,14 @@ func (c *GvproxyCommand) AddEndpoint(endpoint string) {
|
|||||||
c.endpoints = append(c.endpoints, endpoint)
|
c.endpoints = append(c.endpoints, endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GvproxyCommand) AddServiceEndpoint(endpoint string) {
|
||||||
|
if len(c.servicesEndpoints) < 1 {
|
||||||
|
c.servicesEndpoints = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.servicesEndpoints = append(c.servicesEndpoints, endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *GvproxyCommand) AddVpnkitSocket(socket string) {
|
func (c *GvproxyCommand) AddVpnkitSocket(socket string) {
|
||||||
c.checkSocketsInitialized()
|
c.checkSocketsInitialized()
|
||||||
c.sockets["listen-vpnkit"] = socket
|
c.sockets["listen-vpnkit"] = socket
|
||||||
@@ -152,6 +163,18 @@ func (c *GvproxyCommand) endpointsToCmdline() []string {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GvproxyCommand) servicesEndpointsToCmdline() []string {
|
||||||
|
args := []string{}
|
||||||
|
|
||||||
|
for _, endpoint := range c.servicesEndpoints {
|
||||||
|
if endpoint != "" {
|
||||||
|
args = append(args, "-services", endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
// ToCmdline converts Command to a properly formatted command for gvproxy based
|
// ToCmdline converts Command to a properly formatted command for gvproxy based
|
||||||
// on its fields
|
// on its fields
|
||||||
func (c *GvproxyCommand) ToCmdline() []string {
|
func (c *GvproxyCommand) ToCmdline() []string {
|
||||||
@@ -160,6 +183,8 @@ func (c *GvproxyCommand) ToCmdline() []string {
|
|||||||
// listen (endpoints)
|
// listen (endpoints)
|
||||||
args = append(args, c.endpointsToCmdline()...)
|
args = append(args, c.endpointsToCmdline()...)
|
||||||
|
|
||||||
|
args = append(args, c.servicesEndpointsToCmdline()...)
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
args = append(args, "-debug")
|
args = append(args, "-debug")
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ var _ = ginkgo.Describe("command-line format", func() {
|
|||||||
ginkgo.It("should convert Command to command line format", func() {
|
ginkgo.It("should convert Command to command line format", func() {
|
||||||
command := types.NewGvproxyCommand()
|
command := types.NewGvproxyCommand()
|
||||||
command.AddEndpoint("unix:///tmp/network.sock")
|
command.AddEndpoint("unix:///tmp/network.sock")
|
||||||
|
command.AddServiceEndpoint("unix:///tmp/services.sock")
|
||||||
command.Debug = true
|
command.Debug = true
|
||||||
command.AddQemuSocket("tcp://0.0.0.0:1234")
|
command.AddQemuSocket("tcp://0.0.0.0:1234")
|
||||||
command.PidFile = "~/gv-pidfile.txt"
|
command.PidFile = "~/gv-pidfile.txt"
|
||||||
@@ -33,6 +34,7 @@ var _ = ginkgo.Describe("command-line format", func() {
|
|||||||
cmd := command.ToCmdline()
|
cmd := command.ToCmdline()
|
||||||
gomega.Expect(cmd).To(gomega.Equal([]string{
|
gomega.Expect(cmd).To(gomega.Equal([]string{
|
||||||
"-listen", "unix:///tmp/network.sock",
|
"-listen", "unix:///tmp/network.sock",
|
||||||
|
"-services", "unix:///tmp/services.sock",
|
||||||
"-debug",
|
"-debug",
|
||||||
"-mtu", "1500",
|
"-mtu", "1500",
|
||||||
"-ssh-port", "2222",
|
"-ssh-port", "2222",
|
||||||
|
|||||||
Reference in New Issue
Block a user