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

Transport setup-node config gen #1790

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 26 additions & 7 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading