Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skywire-cli vpn subcommands + separate-systray #1317

Merged
merged 16 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clihv
package clidmsgpty

import (
"fmt"
Expand All @@ -11,9 +11,7 @@ import (
)

func init() {
RootCmd.AddCommand(dmsgCmd)
dmsgCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address")
dmsgCmd.AddCommand(
RootCmd.AddCommand(
dmsgUICmd,
dmsgURLCmd,
)
Expand All @@ -25,11 +23,6 @@ func init() {
dmsgURLCmd.Flags().StringVarP(&pk, "visor", "v", "", "public key of visor to connect to")
}

var dmsgCmd = &cobra.Command{
Use: "dmsg",
Short: "DMSGPTY UI",
}

var dmsgUICmd = &cobra.Command{
Use: "ui",
Short: "Open dmsgpty UI in default browser",
Expand Down
22 changes: 15 additions & 7 deletions cmd/skywire-cli/commands/dmsgpty/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ import (
"github.com/skycoin/skywire/pkg/visor"
)

var rpcAddr string
var ptyPort string
var masterLogger = logging.NewMasterLogger()
var packageLogger = masterLogger.PackageLogger("dmsgpty")
var (
ptyPort string
masterLogger = logging.NewMasterLogger()
packageLogger = masterLogger.PackageLogger("dmsgpty")
logger = logging.MustGetLogger("skywire-cli")
rpcAddr string
path string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these variables seem unsued.

pk string
url string
pkg bool
)

func init() {
RootCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address")
RootCmd.PersistentFlags().StringVarP(&ptyPort, "port", "p", "22", "port of remote visor dmsgpty")
visorsCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address")
shellCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address")
shellCmd.PersistentFlags().StringVarP(&ptyPort, "port", "p", "22", "port of remote visor dmsgpty")
}

// RootCmd is the command that contains sub-commands which interacts with dmsgpty.
Expand Down Expand Up @@ -61,7 +69,7 @@ var visorsCmd = &cobra.Command{

var shellCmd = &cobra.Command{
Use: "start <pk>",
Short: "Start dmsgpty for specific visor by its dmsg address pk:port",
Short: "Start dmsgpty session",
Args: cobra.MinimumNArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
cli := dmsgpty.DefaultCLI()
Expand Down
97 changes: 0 additions & 97 deletions cmd/skywire-cli/commands/hv/hvvpn.go

This file was deleted.

20 changes: 1 addition & 19 deletions cmd/skywire-cli/commands/hv/root.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
package clihv

import (
"net"
"time"

"github.com/spf13/cobra"

"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire/pkg/visor"
)

var (
logger = logging.MustGetLogger("skywire-cli")
rpcAddr string
path string
pk string
url string
pkg bool
logger = logging.MustGetLogger("skywire-cli")
)

// RootCmd contains commands that interact with the skywire-visor
var RootCmd = &cobra.Command{
Use: "hv",
Short: "Open HVUI in browser",
}

func rpcClient() visor.API {
const rpcDialTimeout = time.Second * 5
conn, err := net.DialTimeout("tcp", rpcAddr, rpcDialTimeout)
if err != nil {
logger.Fatal("RPC connection failed; is skywire running?\n", err)
}
return visor.NewRPCClient(logger, conn, visor.RPCPrefix, 0)
}
3 changes: 3 additions & 0 deletions cmd/skywire-cli/commands/mdisc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var packageLogger = masterLogger.PackageLogger("mdisc:disc")

func init() {
RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", utilenv.DmsgDiscAddr, "address of DMSG discovery server\n")
var helpflag bool
RootCmd.Flags().BoolVarP(&helpflag, "help", "h", false, "help for "+RootCmd.Use)
RootCmd.Flags().MarkHidden("help") //nolint
}

// RootCmd is the command that contains sub-commands which interacts with DMSG services.
Expand Down
8 changes: 8 additions & 0 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
clidmsgpty "github.com/skycoin/skywire/cmd/skywire-cli/commands/dmsgpty"
clihv "github.com/skycoin/skywire/cmd/skywire-cli/commands/hv"
climdisc "github.com/skycoin/skywire/cmd/skywire-cli/commands/mdisc"
clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
clirtfind "github.com/skycoin/skywire/cmd/skywire-cli/commands/rtfind"
clivisor "github.com/skycoin/skywire/cmd/skywire-cli/commands/visor"
clivpn "github.com/skycoin/skywire/cmd/skywire-cli/commands/vpn"
)

var rootCmd = &cobra.Command{
Expand All @@ -33,10 +35,16 @@ func init() {
clidmsgpty.RootCmd,
clivisor.RootCmd,
clihv.RootCmd,
clivpn.RootCmd,
clirtfind.RootCmd,
climdisc.RootCmd,
clicompletion.RootCmd,
)
var helpflag bool
rootCmd.PersistentFlags().StringVarP(&clirpc.RPCAddr, "rpc", "", "localhost:3435", "RPC server address")
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
rootCmd.PersistentFlags().MarkHidden("help") //nolint
}

// Execute executes root CLI command.
Expand Down
25 changes: 25 additions & 0 deletions cmd/skywire-cli/commands/rpc/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package clirpc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package may as well just be called rpc in my opinion and function could be called Client() This would make obsolete to use RPC as prefix for variables as well.


import (
"net"
"time"

"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire/pkg/visor"
)

var (
// RPCAddr is the address to reach the rpc server
RPCAddr string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this set via the persistent flag in the parent dir or where is this coming from? Does it need to be exported?

logger = logging.MustGetLogger("skywire-cli")
)

// RPCClient is used by the other cli commands to query the visor rpc
func RPCClient() visor.API {
const rpcDialTimeout = time.Second * 5
conn, err := net.DialTimeout("tcp", RPCAddr, rpcDialTimeout)
if err != nil {
logger.Fatal("RPC connection failed; is skywire running?\n", err)
}
return visor.NewRPCClient(logger, conn, visor.RPCPrefix, 0)
}
3 changes: 3 additions & 0 deletions cmd/skywire-cli/commands/rtfind/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func init() {
RootCmd.Flags().Uint16VarP(&frMinHops, "min-hops", "n", 1, "minimum hops")
RootCmd.Flags().Uint16VarP(&frMaxHops, "max-hops", "x", 1000, "maximum hops")
RootCmd.Flags().DurationVarP(&timeout, "timeout", "t", 10*time.Second, "request timeout")
var helpflag bool
RootCmd.Flags().BoolVarP(&helpflag, "help", "h", false, "help for "+RootCmd.Use)
RootCmd.Flags().MarkHidden("help") //nolint
}

// RootCmd is the command that queries the route finder.
Expand Down
11 changes: 6 additions & 5 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/spf13/cobra"

clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/app/appserver"
)
Expand All @@ -34,7 +35,7 @@ var lsAppsCmd = &cobra.Command{
Use: "ls",
Short: "List apps",
Run: func(_ *cobra.Command, _ []string) {
states, err := rpcClient().Apps()
states, err := clirpc.RPCClient().Apps()
internal.Catch(err)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err = fmt.Fprintln(w, "app\tports\tauto_start\tstatus")
Expand All @@ -59,7 +60,7 @@ var startAppCmd = &cobra.Command{
Short: "Launch app",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
internal.Catch(rpcClient().StartApp(args[0]))
internal.Catch(clirpc.RPCClient().StartApp(args[0]))
fmt.Println("OK")
},
}
Expand All @@ -69,7 +70,7 @@ var stopAppCmd = &cobra.Command{
Short: "Halt app",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
internal.Catch(rpcClient().StopApp(args[0]))
internal.Catch(clirpc.RPCClient().StopApp(args[0]))
fmt.Println("OK")
},
}
Expand All @@ -88,7 +89,7 @@ var setAppAutostartCmd = &cobra.Command{
default:
internal.Catch(fmt.Errorf("invalid args[1] value: %s", args[1]))
}
internal.Catch(rpcClient().SetAutoStart(args[0], autostart))
internal.Catch(clirpc.RPCClient().SetAutoStart(args[0], autostart))
fmt.Println("OK")
},
}
Expand All @@ -107,7 +108,7 @@ var appLogsSinceCmd = &cobra.Command{
t, err = time.Parse(time.RFC3339Nano, strTime)
internal.Catch(err)
}
logs, err := rpcClient().LogsSince(t, args[0])
logs, err := clirpc.RPCClient().LogsSince(t, args[0])
internal.Catch(err)
if len(logs) > 0 {
fmt.Println(logs)
Expand Down
3 changes: 2 additions & 1 deletion cmd/skywire-cli/commands/visor/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
)

Expand All @@ -20,7 +21,7 @@ var execCmd = &cobra.Command{
Short: "Execute a command",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
out, err := rpcClient().Exec(strings.Join(args, " "))
out, err := clirpc.RPCClient().Exec(strings.Join(args, " "))
internal.Catch(err)
fmt.Print(string(out))
},
Expand Down
9 changes: 5 additions & 4 deletions cmd/skywire-cli/commands/visor/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/spf13/cobra"

clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ var pkCmd = &cobra.Command{
}
fmt.Println(conf.PK.Hex())
} else {
client := rpcClient()
client := clirpc.RPCClient()
overview, err := client.Overview()
if err != nil {
logger.Fatal("Failed to connect:", err)
Expand Down Expand Up @@ -71,7 +72,7 @@ var hvpkCmd = &cobra.Command{
}
fmt.Println(conf.Hypervisors)
} else {
client := rpcClient()
client := clirpc.RPCClient()
overview, err := client.Overview()
if err != nil {
logger.Fatal("Failed to connect:", err)
Expand All @@ -85,7 +86,7 @@ var summaryCmd = &cobra.Command{
Use: "info",
Short: "Summary of visor info",
Run: func(_ *cobra.Command, _ []string) {
summary, err := rpcClient().Summary()
summary, err := clirpc.RPCClient().Summary()
if err != nil {
log.Fatal("Failed to connect:", err)
}
Expand All @@ -100,7 +101,7 @@ var buildInfoCmd = &cobra.Command{
Use: "version",
Short: "Version and build info",
Run: func(_ *cobra.Command, _ []string) {
client := rpcClient()
client := clirpc.RPCClient()
overview, err := client.Overview()
if err != nil {
log.Fatal("Failed to connect:", err)
Expand Down
Loading