Skip to content

Commit

Permalink
Include more of the deployment config in the survey (#1834)
Browse files Browse the repository at this point in the history
* update system survey to include more of the deployment configuration

* update dmsg dependency

* fix CI errors

* fix logging

* update skycoin-service-discovery dependency

* update skywire-services dependency
  • Loading branch information
0pcom authored Jun 23, 2024
1 parent e32f8f1 commit abeef67
Show file tree
Hide file tree
Showing 11 changed files with 961 additions and 583 deletions.
94 changes: 70 additions & 24 deletions cmd/skywire-cli/commands/survey/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@
package clisurvey

import (
"crypto/sha256"
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
)

var (
// pk cipher.PubKey
// pkString string
isCksum bool
logger = logging.MustGetLogger("skywire-visor") //nolint:unused
mLog = logging.NewMasterLogger()
log = mLog.PackageLogger("survey")
confPath string
// stdin bool
// confArg string
pkg bool
usr bool
pkgconfigexists bool
userconfigexists bool
conf *visorconfig.V1
)

func init() {
surveyCmd.Flags().SortFlags = false
surveyCmd.Flags().BoolVarP(&isCksum, "sha", "s", false, "generate checksum of system survey")
surveyCmd.Flags().StringVarP(&confPath, "config", "c", "", "optionl config file to use (i.e.: "+visorconfig.ConfigName+")")
// surveyCmd.Flags().StringVarP(&confArg, "confarg", "C", "", "supply config as argument")
// surveyCmd.Flags().BoolVarP(&stdin, "stdin", "n", false, "read config from stdin")
if _, err := os.Stat(visorconfig.SkywirePath + "/" + visorconfig.ConfigJSON); err == nil {
pkgconfigexists = true
}
if _, err := os.Stat(visorconfig.HomePath() + "/" + visorconfig.ConfigName); err == nil {
userconfigexists = true
}
if pkgconfigexists {
surveyCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "use package config "+visorconfig.SkywirePath+"/"+visorconfig.ConfigJSON)
}
if userconfigexists {
surveyCmd.Flags().BoolVarP(&usr, "user", "u", false, "use config at: "+visorconfig.HomePath()+"/"+visorconfig.ConfigName)
}
}

// RootCmd is surveyCmd
Expand All @@ -33,36 +55,60 @@ var surveyCmd = &cobra.Command{
Short: "system survey",
Long: "print the system survey",
Run: func(cmd *cobra.Command, args []string) {
if pkg {
confPath = visorconfig.SkywirePath + "/" + visorconfig.ConfigJSON
}
if usr {
confPath = visorconfig.HomePath() + "/" + visorconfig.ConfigName
}
// if confPath != "" && confArg != "" {
// log.Fatal("cannot specify both --config, -c and --confarg, -C")
// }
// if confPath != "" && stdin {
// log.Fatal("cannot specify both --config, -c and --stdin, -n")
// }
// if stdin && confArg != "" {
// log.Fatal("cannot specify both --confarg, -C and --stdin, -n")
// }
// if stdin || confArg != "" || confPath != "" {

if confPath != "" {
// conf = initConfig()
confJSON, err := os.ReadFile(confPath) //nolint
if err != nil {
log.WithError(err).Fatal("Failed to read config file")
}
err = json.Unmarshal(confJSON, &conf)
if err != nil {
log.WithError(err).Fatal("Failed to unmarshal old config json")
}
}
survey, err := visorconfig.SystemSurvey()
if err != nil {
internal.Catch(cmd.Flags(), fmt.Errorf("Failed to generate system survey: %v", err))
}
// //non-critical logic implemented with bitfield/script
// pkString, err = script.Exec(`skywire-cli visor pk -p`).String()
// //fail silently or proceed on nil error
// if err != nil {
// internal.Catch(cmd.Flags(), fmt.Errorf("failed to fetch visor public key: %v", err))
// } else {
// err = pk.Set(pkString)
// if err != nil {
// internal.Catch(cmd.Flags(), fmt.Errorf("failed to validate visor public key: %v", err))
// } else {
// survey.PubKey = pk
// }
// }
skyaddr, err := os.ReadFile(visorconfig.PackageConfig().LocalPath + "/" + visorconfig.RewardFile) //nolint
if err == nil {
survey.SkycoinAddress = string(skyaddr)
}

if conf != nil {
survey.PubKey = conf.PK
survey.ServicesURLs.DmsgDiscovery = conf.Dmsg.Discovery
survey.ServicesURLs.TransportDiscovery = conf.Transport.Discovery
survey.ServicesURLs.AddressResolver = conf.Transport.AddressResolver
survey.ServicesURLs.RouteFinder = conf.Routing.RouteFinder
survey.ServicesURLs.RouteSetupNodes = conf.Routing.RouteSetupNodes
survey.ServicesURLs.TransportSetupPKs = conf.Transport.TransportSetupPKs
survey.ServicesURLs.UptimeTracker = conf.UptimeTracker.Addr
survey.ServicesURLs.ServiceDiscovery = conf.Launcher.ServiceDisc
survey.ServicesURLs.SurveyWhitelist = conf.SurveyWhitelist
survey.ServicesURLs.StunServers = conf.StunServers
//survey.DmsgServers = v.dmsgC.ConnectedServersPK()
}
s, err := json.MarshalIndent(survey, "", "\t")
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Could not marshal json: %v", err))
}
if isCksum {
fmt.Printf("%x/n", sha256.Sum256([]byte(s)))
} else {
fmt.Printf("%s", s)
}
fmt.Printf("%s", s)
},
}
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ require (
github.com/robert-nix/ansihtml v1.0.1
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
github.com/sirupsen/logrus v1.9.3
github.com/skycoin/dmsg v1.3.22-0.20240520184015-5d7616ee506a
github.com/skycoin/dmsg v1.3.22-0.20240622174622-39e439d5679d
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/skycoin-service-discovery v0.0.0-20240306165129-2af10aca698e
github.com/skycoin/skywire-services v0.0.0-20240403004908-50ccbbf07004
github.com/skycoin/skycoin-service-discovery v0.0.0-20240623180153-a8ad1c33ec6b
github.com/skycoin/skywire-services v0.0.0-20240623180621-d0bc8fd4da3d
github.com/skycoin/skywire-utilities v1.3.18-0.20240208220612-9f31eda72f33
github.com/skycoin/systray v1.10.0
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
Expand Down Expand Up @@ -191,3 +191,12 @@ replace github.com/xxxserxxx/gotop/v4 => github.com/ersonp/gotop/v4 v4.2.1
// replace github.com/skycoin/skywire-services => ../skywire-services
// replace github.com/skycoin/skycoin-service-discovery => ../skycoin-service-discovery
// replace github.com/skycoin/skywire-utilities => ../skywire-utilities

// Uncomment to update other skywire deps to specific commit hash.
// run `go mod tidy ; go mod vendor`
// copy the changed line to the correct place in the above
// then, re-comment the line before saving.
// replace github.com/skycoin/dmsg => github.com/skycoin/dmsg <commit-hash>
// replace github.com/skycoin/skywire-services => github.com/skycoin/skywire-services <commit-hash>
// replace github.com/skycoin/skycoin-service-discovery => github.com/skycoin/skycoin-service-discovery <commit-hash>
// replace github.com/skycoin/skywire-utilities => github.com/skycoin/skywire-utilities <commit-hash>
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skycoin/dmsg v1.3.22-0.20240520184015-5d7616ee506a h1:GNEzS7oWScmzp4LBHTcSpRpo4ABbO6lblE4jnwlXgWw=
github.com/skycoin/dmsg v1.3.22-0.20240520184015-5d7616ee506a/go.mod h1:QMd7NXzarhpTJrdmJLCnqBqI0hMj0RIou9DI9s1e5mo=
github.com/skycoin/dmsg v1.3.22-0.20240622174622-39e439d5679d h1:nop/q3XL7GDMP9QpyuBV1fi5Y0rnI7iZeRdHtLfMNt4=
github.com/skycoin/dmsg v1.3.22-0.20240622174622-39e439d5679d/go.mod h1:QMd7NXzarhpTJrdmJLCnqBqI0hMj0RIou9DI9s1e5mo=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I=
github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
github.com/skycoin/skycoin-service-discovery v0.0.0-20240306165129-2af10aca698e h1:y9C5pGHQp/iJFj0QJqr5SboE+Q2RmeYav/AncHOAmWg=
github.com/skycoin/skycoin-service-discovery v0.0.0-20240306165129-2af10aca698e/go.mod h1:h2Yq97wrppNdVgtAhEhY/9w568wS3T6CkK2pWhfUQm0=
github.com/skycoin/skywire-services v0.0.0-20240403004908-50ccbbf07004 h1:VTcuwPkcRkPP4QojtKv4OvsNua30xuY5c/SdpefU+ys=
github.com/skycoin/skywire-services v0.0.0-20240403004908-50ccbbf07004/go.mod h1:HGvza0o1t9KI/wGcklvoKIgfxfbI7M2PEtc+HsPz1nc=
github.com/skycoin/skycoin-service-discovery v0.0.0-20240623180153-a8ad1c33ec6b h1:5HUw+Uckv5mZORdcSC1TLmAu2ICRYjouoqATa8mTp74=
github.com/skycoin/skycoin-service-discovery v0.0.0-20240623180153-a8ad1c33ec6b/go.mod h1:FeOj6UmWl3fHf09yndIljAznZeAFiu95eUjNW/nIIHs=
github.com/skycoin/skywire-services v0.0.0-20240623180621-d0bc8fd4da3d h1:KZT7CjyFy465RLjEZyPU0NzEa2pQY6wH38EOkWH7HL8=
github.com/skycoin/skywire-services v0.0.0-20240623180621-d0bc8fd4da3d/go.mod h1:61gfVmHyIAZexpeGKqaYrwelKW4VUIgjmtg5QpG2sf0=
github.com/skycoin/skywire-utilities v1.3.18-0.20240208220612-9f31eda72f33 h1:BzhyKolEWT8cnXZJMxC0TYGCvu3wMYdI6NOpvToN+uQ=
github.com/skycoin/skywire-utilities v1.3.18-0.20240208220612-9f31eda72f33/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw=
github.com/skycoin/systray v1.10.0 h1:fQZJHMylpVvfmOOTLvUssfyHVDoC8Idx6Ba2BlLEuGg=
Expand Down
29 changes: 16 additions & 13 deletions pkg/visor/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,32 @@ func GenerateSurvey(v *Visor, log *logging.Logger, routine bool) {
log.Info("Skycoin reward address: ", cAddr.String())
//generate the system survey
pathutil.EnsureDir(v.conf.LocalPath) //nolint
generatedSurvey, err := visconf.SystemSurvey()
survey, err := visconf.SystemSurvey()
if err != nil {
log.WithError(err).Error("Could not read system info.")
return
}
generatedSurvey.PubKey = v.conf.PK
generatedSurvey.SkycoinAddress = cAddr.String()

generatedSurvey.ServicesURLs.TransportDiscovery = v.conf.Transport.Discovery
generatedSurvey.ServicesURLs.AddressResolver = v.conf.Transport.AddressResolver
generatedSurvey.ServicesURLs.RouteFinder = v.conf.Routing.RouteFinder
generatedSurvey.ServicesURLs.RouteSetupNodes = v.conf.Routing.RouteSetupNodes
generatedSurvey.ServicesURLs.UptimeTracker = v.conf.UptimeTracker.Addr
generatedSurvey.ServicesURLs.ServiceDiscovery = v.conf.Launcher.ServiceDisc
generatedSurvey.DmsgServers = v.dmsgC.ConnectedServersPK()
survey.PubKey = v.conf.PK
survey.SkycoinAddress = cAddr.String()
survey.ServicesURLs.DmsgDiscovery = v.conf.Dmsg.Discovery
survey.ServicesURLs.TransportDiscovery = v.conf.Transport.Discovery
survey.ServicesURLs.AddressResolver = v.conf.Transport.AddressResolver
survey.ServicesURLs.RouteFinder = v.conf.Routing.RouteFinder
survey.ServicesURLs.RouteSetupNodes = v.conf.Routing.RouteSetupNodes
survey.ServicesURLs.TransportSetupPKs = v.conf.Transport.TransportSetupPKs
survey.ServicesURLs.UptimeTracker = v.conf.UptimeTracker.Addr
survey.ServicesURLs.ServiceDiscovery = v.conf.Launcher.ServiceDisc
survey.ServicesURLs.SurveyWhitelist = v.conf.SurveyWhitelist
survey.ServicesURLs.StunServers = v.conf.StunServers
survey.DmsgServers = v.dmsgC.ConnectedServersPK()

log.Info("Generating system survey")
v.surveyLock.Lock()
v.survey = generatedSurvey
v.survey = survey
v.surveyLock.Unlock()

// Save survey as file
s, err := json.MarshalIndent(generatedSurvey, "", "\t")
s, err := json.MarshalIndent(survey, "", "\t")
if err != nil {
log.WithError(err).Error("Could not marshal json.")
return
Expand Down
Loading

0 comments on commit abeef67

Please sign in to comment.