Skip to content

Commit

Permalink
add --sn flag to config gen ; generate config for setup-node
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Mar 21, 2024
1 parent 51093e2 commit d03f1c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ./...

Expand Down
26 changes: 24 additions & 2 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d03f1c3

Please sign in to comment.