From 85aef7a9275c1c04b0f2c366e32587d4b9e013cd Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Sun, 24 Mar 2024 09:31:45 -0500 Subject: [PATCH] add transport setup-node config gen --- cmd/skywire-cli/commands/config/gen.go | 33 +++++++++++++++++++------ cmd/skywire-cli/commands/config/root.go | 3 ++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/skywire-cli/commands/config/gen.go b/cmd/skywire-cli/commands/config/gen.go index 4eeb8436ba..1907bb4065 100644 --- a/cmd/skywire-cli/commands/config/gen.go +++ b/cmd/skywire-cli/commands/config/gen.go @@ -208,8 +208,10 @@ 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().BoolVar(&rsnConfig, "rsn", false, "generate config for route setup-node") + gHiddenFlags = append(gHiddenFlags, "rsn") + genConfigCmd.Flags().BoolVar(&tpsnConfig, "tpsn", false, "generate config for transport setup-node") + gHiddenFlags = append(gHiddenFlags, "tpsn") 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") @@ -379,6 +381,9 @@ var genConfigCmd = &cobra.Command{ } } } + if rsnConfig && tpsnConfig { + log.Fatal("use of mutually exclusive flags --rsn and --tpsn") + } }, Run: func(cmd *cobra.Command, args []string) { @@ -1025,12 +1030,18 @@ var genConfigCmd = &cobra.Command{ if err != nil { log.WithError(err).Fatal("Failed to marshal config to indented JSON") } - if snConfig { + if rsnConfig { 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) } } + if tpsnConfig { + 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}, 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 if err != nil { @@ -1042,10 +1053,18 @@ var genConfigCmd = &cobra.Command{ if err != nil { 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) + if rsnConfig || tpsnConfig { + if rsnConfig { + 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) + } + } + if tpsnConfig { + 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}, 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 { diff --git a/cmd/skywire-cli/commands/config/root.go b/cmd/skywire-cli/commands/config/root.go index d08fc195e9..be4eddddbc 100644 --- a/cmd/skywire-cli/commands/config/root.go +++ b/cmd/skywire-cli/commands/config/root.go @@ -101,7 +101,8 @@ var ( proxyClientPass string configServicePath string dmsgHTTPPath string - snConfig bool + rsnConfig bool + tpsnConfig bool ) // RootCmd contains commands that interact with the config of local skywire-visor