diff --git a/Makefile b/Makefile index fa8d92707..4ce0cb181 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ check-cg: ## Cursory check of the main help menu, offline dmsghttp config gen an check-windows: lint-windows test-windows ## Run linters and tests on windows image -build: build-merged ## Install dependencies, build apps and binaries. `go build` with ${OPTS} +build: clean build-merged ## Install dependencies, build apps and binaries. `go build` with ${OPTS} build-merged: ## Install dependencies, build apps and binaries. `go build` with ${OPTS} ${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)skywire ./cmd/skywire @@ -130,13 +130,13 @@ install-system-linux: build ## Install apps and binaries over those provided by sudo echo "sudo cache" sudo install -Dm755 $(BUILD_PATH)skywire /opt/skywire/bin/ -install-system-linux-merged: build-merged ## Install apps and binaries over those provided by the linux package - linux package must be installed first! - sudo echo "sudo cache" - sudo install -Dm755 $(BUILD_PATH)skywire /opt/skywire/bin/ install-generate: ## Installs required execs for go generate. ${OPTS} go install github.com/mjibson/esc github.com/vektra/mockery/v2@latest + ## TO DO: it may be unnecessary to install required execs for go generate into the path. An alternative method may exist which does not require this + ## https://eli.thegreenplace.net/2021/a-comprehensive-guide-to-go-generate + generate: ## Generate mocks and config README's go generate ./... diff --git a/cmd/skywire-cli/commands/config/gen.go b/cmd/skywire-cli/commands/config/gen.go index 21e097458..4eeb8436b 100644 --- a/cmd/skywire-cli/commands/config/gen.go +++ b/cmd/skywire-cli/commands/config/gen.go @@ -208,6 +208,8 @@ func init() { gHiddenFlags = append(gHiddenFlags, "svcconf") genConfigCmd.Flags().BoolVar(&noDefaults, "nodefaults", false, "do not use hardcoded defaults for production / test services") gHiddenFlags = append(gHiddenFlags, "nodefaults") + genConfigCmd.Flags().BoolVar(&snConfig, "sn", false, "generate config for route setup-node") + gHiddenFlags = append(gHiddenFlags, "sn") genConfigCmd.Flags().StringVar(&ver, "version", scriptExecString("${VERSION}"), "custom version testing override\033[0m") gHiddenFlags = append(gHiddenFlags, "version") genConfigCmd.Flags().BoolVar(&isAll, "all", false, "show all flags") @@ -1021,7 +1023,13 @@ var genConfigCmd = &cobra.Command{ // Marshal the modified config to JSON with indentation jsonData, err := json.MarshalIndent(conf, "", " ") if err != nil { - log.Fatalf("Failed to marshal config to JSON: %v", err) + log.WithError(err).Fatal("Failed to marshal config to indented JSON") + } + if snConfig { + jsonData, err = script.Echo(string(jsonData)).JQ("{public_key: .pk, secret_key: .sk, dmsg: {discovery: .dmsg.discovery, sessions_count: .dmsg.sessions_count, servers: .dmsg.servers}, transport_discovery: .transport.discovery, log_level: .log_level}").Bytes() + if err != nil { + log.Fatalf("Failed to convert config to setup-node config format: %v", err) + } } // Write the JSON data back to the file err = os.WriteFile(confPath, jsonData, 0644) //nolint @@ -1032,7 +1040,21 @@ var genConfigCmd = &cobra.Command{ // Print results. j, err := json.MarshalIndent(conf, "", "\t") if err != nil { - log.WithError(err).Fatal("Could not unmarshal json.") + log.WithError(err).Fatal("Failed to marshal config to indented JSON") + } + if snConfig { + j, err = script.Echo(string(j)).JQ("{public_key: .pk, secret_key: .sk, dmsg: {discovery: .dmsg.discovery, sessions_count: .dmsg.sessions_count, servers: .dmsg.servers}, transport_discovery: .transport.discovery, log_level: .log_level}").Bytes() + if err != nil { + log.Fatalf("Failed to convert config to setup-node config format: %v", err) + } + var data any + if err = json.Unmarshal(j, &data); err != nil { + log.Fatalf("Failed to convert config to setup-node config format: %v", err) + } + j, err = json.MarshalIndent(data, "", " ") + if err != nil { + log.WithError(err).Fatal("Failed to marshal config to indented JSON") + } } //print config to stdout, omit logging messages, exit if isStdout { diff --git a/cmd/skywire-cli/commands/config/root.go b/cmd/skywire-cli/commands/config/root.go index 1eaffc99a..d08fc195e 100644 --- a/cmd/skywire-cli/commands/config/root.go +++ b/cmd/skywire-cli/commands/config/root.go @@ -101,6 +101,7 @@ var ( proxyClientPass string configServicePath string dmsgHTTPPath string + snConfig bool ) // RootCmd contains commands that interact with the config of local skywire-visor