|
@@ -1,10 +1,32 @@
|
|
package cmd
|
|
package cmd
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "errors"
|
|
|
|
+
|
|
"github.com/mudler/edgevpn/pkg/edgevpn"
|
|
"github.com/mudler/edgevpn/pkg/edgevpn"
|
|
"github.com/urfave/cli"
|
|
"github.com/urfave/cli"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func cliNameAddress(c *cli.Context) (name, address string, err error) {
|
|
|
|
+ name = c.Args().Get(0)
|
|
|
|
+ address = c.Args().Get(1)
|
|
|
|
+ if name == "" && c.String("name") == "" {
|
|
|
|
+ err = errors.New("Either a file UUID as first argument or with --name needs to be provided")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if address == "" && c.String("address") == "" {
|
|
|
|
+ err = errors.New("Either a file UUID as first argument or with --name needs to be provided")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if c.String("name") != "" {
|
|
|
|
+ name = c.String("name")
|
|
|
|
+ }
|
|
|
|
+ if c.String("address") != "" {
|
|
|
|
+ address = c.String("address")
|
|
|
|
+ }
|
|
|
|
+ return name, address, nil
|
|
|
|
+}
|
|
|
|
+
|
|
func ServiceAdd() cli.Command {
|
|
func ServiceAdd() cli.Command {
|
|
return cli.Command{
|
|
return cli.Command{
|
|
Name: "service-add",
|
|
Name: "service-add",
|
|
@@ -12,21 +34,23 @@ func ServiceAdd() cli.Command {
|
|
Usage: "Expose a service to the network without creating a VPN",
|
|
Usage: "Expose a service to the network without creating a VPN",
|
|
Description: `Expose a local or a remote endpoint connection as a service in the VPN.
|
|
Description: `Expose a local or a remote endpoint connection as a service in the VPN.
|
|
The host will act as a proxy between the service and the connection`,
|
|
The host will act as a proxy between the service and the connection`,
|
|
- UsageText: "edgevpn service-add --name 'unique-id' --remoteaddress 'ip:port'",
|
|
|
|
|
|
+ UsageText: "edgevpn service-add unique-id ip:port",
|
|
Flags: append(CommonFlags,
|
|
Flags: append(CommonFlags,
|
|
cli.StringFlag{
|
|
cli.StringFlag{
|
|
- Name: "name",
|
|
|
|
- Usage: `Unique name of the service to be server over the network.`,
|
|
|
|
- Required: true,
|
|
|
|
|
|
+ Name: "name",
|
|
|
|
+ Usage: `Unique name of the service to be server over the network.`,
|
|
},
|
|
},
|
|
cli.StringFlag{
|
|
cli.StringFlag{
|
|
- Name: "remoteaddress",
|
|
|
|
- Required: true,
|
|
|
|
|
|
+ Name: "address",
|
|
Usage: `Remote address that the service is running to. That can be a remote webserver, a local SSH server, etc.
|
|
Usage: `Remote address that the service is running to. That can be a remote webserver, a local SSH server, etc.
|
|
For example, '192.168.1.1:80', or '127.0.0.1:22'.`,
|
|
For example, '192.168.1.1:80', or '127.0.0.1:22'.`,
|
|
},
|
|
},
|
|
),
|
|
),
|
|
Action: func(c *cli.Context) error {
|
|
Action: func(c *cli.Context) error {
|
|
|
|
+ name, address, err := cliNameAddress(c)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
e := edgevpn.New(cliToOpts(c)...)
|
|
e := edgevpn.New(cliToOpts(c)...)
|
|
|
|
|
|
displayStart(e)
|
|
displayStart(e)
|
|
@@ -37,7 +61,7 @@ For example, '192.168.1.1:80', or '127.0.0.1:22'.`,
|
|
}
|
|
}
|
|
|
|
|
|
// Join the node to the network, using our ledger
|
|
// Join the node to the network, using our ledger
|
|
- e.ExposeService(ledger, c.String("name"), c.String("remoteaddress"))
|
|
|
|
|
|
+ e.ExposeService(ledger, name, address)
|
|
// Join the node to the network, using our ledger
|
|
// Join the node to the network, using our ledger
|
|
if err := e.Join(); err != nil {
|
|
if err := e.Join(); err != nil {
|
|
return err
|
|
return err
|
|
@@ -57,21 +81,23 @@ func ServiceConnect() cli.Command {
|
|
Description: `Bind a local port to connect to a remote service in the network.
|
|
Description: `Bind a local port to connect to a remote service in the network.
|
|
Creates a local listener which connects over the service in the network without creating a VPN.
|
|
Creates a local listener which connects over the service in the network without creating a VPN.
|
|
`,
|
|
`,
|
|
- UsageText: "edgevpn service-connect --name 'unique-id' --srcaddress '(ip):port'",
|
|
|
|
|
|
+ UsageText: "edgevpn service-connect unique-id (ip):port",
|
|
Flags: append(CommonFlags,
|
|
Flags: append(CommonFlags,
|
|
cli.StringFlag{
|
|
cli.StringFlag{
|
|
- Name: "name",
|
|
|
|
- Usage: `Unique name of the service in the network.`,
|
|
|
|
- Required: true,
|
|
|
|
|
|
+ Name: "name",
|
|
|
|
+ Usage: `Unique name of the service in the network.`,
|
|
},
|
|
},
|
|
cli.StringFlag{
|
|
cli.StringFlag{
|
|
- Name: "srcaddress",
|
|
|
|
|
|
+ Name: "address",
|
|
Usage: `Address where to bind locally. E.g. ':8080'. A proxy will be created
|
|
Usage: `Address where to bind locally. E.g. ':8080'. A proxy will be created
|
|
to the service over the network`,
|
|
to the service over the network`,
|
|
- Required: true,
|
|
|
|
},
|
|
},
|
|
),
|
|
),
|
|
Action: func(c *cli.Context) error {
|
|
Action: func(c *cli.Context) error {
|
|
|
|
+ name, address, err := cliNameAddress(c)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
e := edgevpn.New(cliToOpts(c)...)
|
|
e := edgevpn.New(cliToOpts(c)...)
|
|
|
|
|
|
displayStart(e)
|
|
displayStart(e)
|
|
@@ -82,7 +108,7 @@ to the service over the network`,
|
|
}
|
|
}
|
|
|
|
|
|
ledger, _ := e.Ledger()
|
|
ledger, _ := e.Ledger()
|
|
- return e.ConnectToService(ledger, c.String("name"), c.String("srcaddress"))
|
|
|
|
|
|
+ return e.ConnectToService(ledger, name, address)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|