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

Group skywire-cli visor subcommands #1132

Merged
merged 68 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
3a3da6c
group `skywire-cli visor` subcommands
0pcom Mar 11, 2022
e63d513
update skywire cli interface
0pcom Mar 12, 2022
d1ce4bd
`make format && make check`
0pcom Mar 13, 2022
484c502
`skywire-cli config gen -o STDOUT`
0pcom Mar 13, 2022
0816418
update documentation
0pcom Mar 14, 2022
2a32e0f
update documentation
0pcom Mar 14, 2022
1ce1aea
fix make check error
0pcom Mar 14, 2022
a7cb39e
update documentation
0pcom Mar 14, 2022
3b1a47e
fix typo
0pcom Mar 14, 2022
048198b
fix typo
0pcom Mar 14, 2022
99f9f8d
fix documentation formatting
0pcom Mar 14, 2022
b19953b
fix typo
0pcom Mar 14, 2022
1cd2b05
eliminate writes when only reads are needed
0pcom Mar 18, 2022
5bdba01
visor no longer rewrites its config
0pcom Mar 22, 2022
d1cac60
merge develop into
mrpalide Mar 22, 2022
67602ec
fix linter errors and warns
mrpalide Mar 22, 2022
2e0f91f
refactor config update & add fallback to hardcoded values if server e…
0pcom Mar 24, 2022
74f2d60
continued refactoring.
0pcom Mar 25, 2022
a4bca27
continued refactoring.
0pcom Mar 25, 2022
a7d1b56
visor no longer writes to the config file. Fixed accidental recursion.
0pcom Mar 25, 2022
e2e1410
determine config parameters (hypervisor,dmsghttp) via map[string]inte…
0pcom Mar 25, 2022
97791ea
fix read config from stdin for visor
0pcom Mar 25, 2022
17295fa
refactor
0pcom Mar 25, 2022
45ae4c0
fix make check errors
0pcom Mar 25, 2022
8075e5e
color cobra & other asthetic improvements
0pcom Mar 26, 2022
d86e4b5
move completion from subcommand to -z flag
0pcom Mar 26, 2022
d58d02e
further tweaks
0pcom Mar 26, 2022
f15b566
fix service discovery and uptime tracker URLs accidentally switched
0pcom Mar 26, 2022
f0cac85
colorize setup-node help text
0pcom Mar 26, 2022
bc5319f
fix some make check errors
0pcom Mar 26, 2022
8337455
remove closing cliL in cli shutdown. It will close in dmsgpty shuttin…
mrpalide Mar 28, 2022
1b2b240
address requested changes, hide excess flags, logic cleanup for visor…
0pcom Mar 28, 2022
4cfd2c5
Merge branch 'refine-skywire-cli' of ssh://github.com/the-skycoin-pro…
0pcom Mar 28, 2022
fd3869b
fix appveyor tests & test deployment services
0pcom Mar 28, 2022
e098a9f
minor tweak to help menus; hide --all flag when showing all flags
0pcom Mar 28, 2022
e27aa3e
fix config update & other tweaks
0pcom Mar 29, 2022
4e66e57
rever cliL.Close()
mrpalide Mar 29, 2022
07293f2
check error for cliL.Close (fix appveyor error)
0pcom Mar 30, 2022
25ce5bf
Merge branch 'develop' into refine-skywire-cli
0pcom Mar 30, 2022
eb68bc9
nil error before returning for cliL.Close
0pcom Mar 30, 2022
c5067c1
change netErr.Temporary to netErr.Timeout ; fix golangci-lint error: …
0pcom Mar 30, 2022
d4a1d40
remove check config version from visorconfig.Parse
0pcom Mar 30, 2022
da0b293
fix appveyor errors for mac and windows
0pcom Mar 30, 2022
14f6201
change pushCloseStack on initCLI
mrpalide Mar 30, 2022
e9a9bc0
go get skywire-utilities@develop | fix new issues
mrpalide Mar 30, 2022
13e2eb3
cleanup removing unnecessary files. Drop unnecessary prefixes from va…
0pcom Mar 30, 2022
825f765
add viper to visor for handling config; change envs to match skywire-…
0pcom Mar 31, 2022
79289f2
fix visor wont start & other issues
0pcom Apr 2, 2022
31123d2
fix make check errors and add local folder (ignoring contents)
0pcom Apr 2, 2022
0f697df
fix appveyor errors
0pcom Apr 2, 2022
3e7c57f
fix appveyor errors
0pcom Apr 2, 2022
460d5f1
update documenttion and fix package path for config gen
0pcom Apr 2, 2022
aa01157
make format check
0pcom Apr 3, 2022
108b72f
update documentation / try to fix appveyor errors
0pcom Apr 3, 2022
8fd9bcc
update documentation
0pcom Apr 3, 2022
69b51ea
go get dmsg@develop | go get skywire-utilities@develop | go mod vendor
mrpalide Apr 4, 2022
09109d5
update golangci-lint to 1.44.2 in appveyor
mrpalide Apr 4, 2022
5c5e294
add not permitted error to whitelist
mrpalide Apr 4, 2022
767484f
fix nil pointer on tp.transport issue #1134
mrpalide Apr 4, 2022
c1b817c
add autostart flag on update config
mrpalide Apr 4, 2022
d855e23
add --dmsghttp flag to update dmsghttp-config file from github
mrpalide Apr 4, 2022
72bdb4b
update CHANGELOG | fix linter
mrpalide Apr 4, 2022
a76791b
check config version against visor version & error on mismatch. Impro…
0pcom Apr 5, 2022
9077689
remove dmsghttp-config update logic
mrpalide Apr 5, 2022
fb7f41c
fix logging & update logic for printing config gen instructions on in…
0pcom Apr 5, 2022
d4ab914
fix logging & update logic for printing config gen instructions on in…
0pcom Apr 5, 2022
c8a6250
make format check
0pcom Apr 5, 2022
dbe524d
Merge branch 'develop' into refine-skywire-cli
mrpalide Apr 6, 2022
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
79 changes: 50 additions & 29 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
disableApps string
bestProtocol bool
serviceConfURL string
fallback bool
)

func init() {
Expand Down Expand Up @@ -86,34 +87,39 @@ var genConfigCmd = &cobra.Command{
Run: func(cmd *cobra.Command, _ []string) {
mLog := logging.NewMasterLogger()
mLog.SetLevel(logrus.InfoLevel)
var services visorconfig.Services

urlstr := []string{"http://", serviceConfURL, "/config"}
ersonp marked this conversation as resolved.
Show resolved Hide resolved
0pcom marked this conversation as resolved.
Show resolved Hide resolved
serviceConfURL = strings.Join(urlstr, "")
serviceConfURL1 := strings.Join(urlstr, "")
client := http.Client{
Timeout: time.Second * 2, // Timeout after 2 seconds
}
req, err := http.NewRequest(http.MethodGet, serviceConfURL, nil)
req, err := http.NewRequest(http.MethodGet, serviceConfURL1, nil)
if err != nil {
mLog.Fatal(err)
}

res, err := client.Do(req)
if err != nil {
mLog.Fatal(err)
}

if res.Body != nil {
defer res.Body.Close() //nolint
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
mLog.Fatal(err)
}
var services visorconfig.Services
err = json.Unmarshal(body, &services)
if err != nil {
mLog.Fatal(err)
if serviceConfURL != "skywire.skycoin.com" { // unhardcode this later
mLog.WithError(err).Fatal("Failed to fetch servers\n")
} else {
mLog.WithError(err).Error("Failed to fetch servers\n")
mLog.Info("Falling back on hardcoded servers")
fallback = true
}
} else {
if res.Body != nil {
defer res.Body.Close() //nolint
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
mLog.Fatal(err)
}
err = json.Unmarshal(body, &services)
if err != nil {
mLog.Fatal(err)
}
}

//fmt.Println(services)
Expand Down Expand Up @@ -154,6 +160,18 @@ var genConfigCmd = &cobra.Command{
genConf = visorconfig.MakeDefaultConfig
}

// fall back on server values from skywire-utilities/pkg/skyenv
if fallback {
jdknives marked this conversation as resolved.
Show resolved Hide resolved
services.DmsgDiscovery = skyenv.DefaultDmsgDiscAddr
services.TransportDiscovery = skyenv.DefaultTpDiscAddr
services.AddressResolver = skyenv.DefaultAddressResolverAddr
services.RouteFinder = skyenv.DefaultRouteFinderAddr
services.SetupNodes = append(services.SetupNodes, skyenv.MustPK(skyenv.DefaultSetupPK))
services.UptimeTracker = skyenv.DefaultUptimeTrackerAddr
services.ServiceDiscovery = skyenv.DefaultServiceDiscAddr
services.StunServers = skyenv.GetStunServers()
}

// Generate config.
conf, err := genConf(mLog, output, &sk, hypervisor, services)
if err != nil {
Expand Down Expand Up @@ -216,20 +234,23 @@ var genConfigCmd = &cobra.Command{
conf.UptimeTracker.Addr = dmsgHTTPServersList.Prod.UptimeTracker
conf.Routing.RouteFinder = dmsgHTTPServersList.Prod.RouteFinder
conf.Launcher.ServiceDisc = dmsgHTTPServersList.Prod.ServiceDiscovery
/*
conf.Dmsg.Servers = dmsgHTTPServersList.Prod.DMSGServers
conf.Dmsg.Discovery = services.DmsgDiscovery
conf.Transport.AddressResolver = services.AddressResolver
conf.Transport.Discovery = services.TransportDiscovery
conf.UptimeTracker.Addr = services.UptimeTracker
conf.Routing.RouteFinder = services.RouteFinder
conf.Routing.SetupNodes = services.SetupNodes
conf.Launcher.ServiceDisc = services.ServiceDiscovery
conf.StunServers = services.StunServers
*/
}
}

/*
if fallback {
conf.Dmsg.Servers = dmsgHTTPServersList.Prod.DMSGServers
conf.Dmsg.Discovery = skyenv.DefaultDmsgDiscAddr
conf.Transport.AddressResolver = skyenv.DefaultAddressResolverAddr
conf.Transport.Discovery = skyenv.DefaultTpDiscAddr
conf.UptimeTracker.Addr = skyenv.DefaultUptimeTrackerAddr
conf.Routing.RouteFinder = skyenv.DefaultRouteFinderAddr
conf.Routing.SetupNodes = skyenv.DefaultSetupPK
conf.Launcher.ServiceDisc = skyenv.DefaultServiceDiscAddr
conf.StunServers = skyenv.GetStunServers()
}
*/

// Read in old config (if any) and obtain old hypervisors.
if replaceHypervisors {
if oldConf, ok := readOldConfig(mLog, output, true, hypervisor, services); ok {
Expand Down Expand Up @@ -318,7 +339,7 @@ func readOldConfig(log *logging.MasterLogger, confPath string, replace bool, hyp
}

if !replace {
logger.Fatal("Config file already exists. Specify the 'replace, r' flag to replace this.")
logger.Fatal("Config file already exists. Specify the 'replace, r' flag to replace.")
}

conf, err := visorconfig.Parse(log, confPath, raw, hypervisor, services)
Expand Down
6 changes: 6 additions & 0 deletions cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package config
import (
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/cmd/skywire-cli/commands/config/update"
)

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

func init() {
RootCmd.AddCommand(update.RootCmd)
}

// RootCmd contains commands that interact with the config of local skywire-visor
var RootCmd = &cobra.Command{
Use: "config",
Expand Down
173 changes: 173 additions & 0 deletions cmd/skywire-cli/commands/config/update/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package update

import (
"encoding/json"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
"time"

"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/pkg/visor/visorconfig"
)

var (
addOutput string
addInput string
environment string
updateEndpoints bool
addHypervisorPKs string
resetHypervisor bool
setVPNClientKillswitch string
addVPNClientSrv string
addVPNClientPasscode string
resetVPNclient bool
addVPNServerPasscode string
setVPNServerSecure string
resetVPNServer bool
addSkysocksClientSrv string
resetSkysocksClient bool
skysocksPasscode string
resetSkysocks bool
setPublicAutoconnect string
serviceConfURL string
minHops int
output string
)

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

func init() {
RootCmd.Flags().SortFlags = false
RootCmd.Flags().BoolVarP(&updateEndpoints, "endpoints", "a", false, "update server endpoints")
RootCmd.Flags().StringVarP(&serviceConfURL, "url", "b", "skywire.skycoin.com", "service configuration URL")
RootCmd.Flags().StringVarP(&environment, "environment", "c", "production", "desired environment (values production or testing)")
RootCmd.Flags().StringVar(&setPublicAutoconnect, "public-autoconn", "", "change public autoconnect configuration")
RootCmd.Flags().IntVar(&minHops, "set-minhop", -1, "change min hops value")
RootCmd.PersistentFlags().StringVarP(&addInput, "input", "i", "skywire-config.json", "path of input config file.")
RootCmd.PersistentFlags().StringVarP(&addOutput, "output", "o", "skywire-config.json", "path of output config file.")
RootCmd.PersistentFlags().BoolVarP(&pkg, "pkg", "p", false, "read from /opt/skywire/skywire.json")
}

// RootCmd contains commands that update the config
var RootCmd = &cobra.Command{
Use: "update",
Short: "update a config file",
PreRun: func(_ *cobra.Command, _ []string) {
var err error
if output, err = filepath.Abs(addOutput); err != nil {
logger.WithError(err).Fatal("Invalid config output.")
}
},
Run: func(cmd *cobra.Command, _ []string) {
mLog := logging.NewMasterLogger()
mLog.SetLevel(logrus.InfoLevel)
if cmd.Flags().Changed("serviceConfURL") {
updateEndpoints = true
}
var services visorconfig.Services
if updateEndpoints {
urlstr := []string{"http://", serviceConfURL, "/config"}
serviceConfURL = strings.Join(urlstr, "")
client := http.Client{
Timeout: time.Second * 2, // Timeout after 2 seconds
}
req, err := http.NewRequest(http.MethodGet, serviceConfURL, nil)
if err != nil {
mLog.Fatal(err)
}
res, err := client.Do(req)
if err != nil {
mLog.Fatal(err)
}
if res.Body != nil {
defer res.Body.Close() //nolint
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
mLog.Fatal(err)
}
err = json.Unmarshal(body, &services)
if err != nil {
mLog.Fatal(err)
}
}

conf, ok := visorconfig.ReadConfig(addInput)
if ok != nil {
mLog.WithError(ok).Fatal("Failed to parse config.")
}

switch environment {
case "production":
visorconfig.SetDefaultProductionValues(conf)
case "testing":
visorconfig.SetDefaultTestingValues(conf)
default:
logger.Fatal("Unrecognized environment value: ", environment)
}

switch setPublicAutoconnect {
case "true":
conf.Transport.PublicAutoconnect = true
case "false":
conf.Transport.PublicAutoconnect = false
case "":
break
default:
logger.Fatal("Unrecognized public autoconnect value: ", setPublicAutoconnect)
}

if minHops >= 0 {
conf.Routing.MinHops = uint16(minHops)
}

saveConfig(conf)
},
}

func changeAppsConfig(conf *visorconfig.V1, appName string, argName string, argValue string) {
apps := conf.Launcher.Apps
for index := range apps {
if apps[index].Name != appName {
continue
}
updated := false
for ind, arg := range apps[index].Args {
if arg == argName {
apps[index].Args[ind+1] = argValue
updated = true
}
}
if !updated {
apps[index].Args = append(apps[index].Args, argName, argValue)
}
}
}

func resetAppsConfig(conf *visorconfig.V1, appName string) {
apps := conf.Launcher.Apps
for index := range apps {
if apps[index].Name == appName {
apps[index].Args = []string{}
}
}
}

func saveConfig(conf *visorconfig.V1) {
// Save config to file.
if err := conf.Flush(); err != nil {
logger.WithError(err).Fatal("Failed to flush config to file.")
}

// Print results.
j, err := json.MarshalIndent(conf, "", "\t")
if err != nil {
logger.WithError(err).Fatal("An unexpected error occurred. Please contact a developer.")
0pcom marked this conversation as resolved.
Show resolved Hide resolved
}
logger.Infof("Updated file '%s' to: %s", output, j)
0pcom marked this conversation as resolved.
Show resolved Hide resolved
}
Loading