From 3e89d233840dae6a50ebb680f7a2d1ad6c3598ab Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Thu, 7 Oct 2021 19:26:57 +0700 Subject: [PATCH 1/3] adds config subcommand, remove config subcommand from visor subcommand --- README.md | 8 +- cmd/skywire-cli/README.md | 831 +++++++++--------- .../{visor/gen-config.go => config/gen.go} | 4 +- cmd/skywire-cli/commands/config/root.go | 14 + .../update-config.go => config/update.go} | 4 +- cmd/skywire-cli/commands/root.go | 2 + cmd/skywire-visor/README.md | 6 +- docker/images/visor/entrypoint.sh | 2 +- 8 files changed, 455 insertions(+), 416 deletions(-) rename cmd/skywire-cli/commands/{visor/gen-config.go => config/gen.go} (99%) create mode 100644 cmd/skywire-cli/commands/config/root.go rename cmd/skywire-cli/commands/{visor/update-config.go => config/update.go} (98%) diff --git a/README.md b/README.md index 7f06d6b0d3..f22df37915 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,14 @@ Skywire can be statically built. For instructions check [the docs](docs/static-b In order to expose the hypervisor UI, generate a config file with `--is-hypervisor` or `-i` flag: ```bash -$ skywire-cli visor gen-config -i +$ skywire-cli config gen -i ``` Docker container will create config automatically for you, should you want to run it manually, you can do: ```bash $ docker run --rm -v :/opt/skywire \ - skycoin/skywire:test skywire-cli gen-config -i + skycoin/skywire:test skywire-cli config gen -i ``` After starting up the visor, the UI will be exposed by default on `localhost:8000`. @@ -55,14 +55,14 @@ Every visor can be controlled by one or more hypervisors. To allow a hypervisor hypervisor needs to be specified in the configuration file. You can add a remote hypervisor to the config with: ```bash -$ skywire-cli visor update-config --hypervisor-pks +$ skywire-cli config update --hypervisor-pks ``` Or from docker image: ```bash $ docker run --rm -v :/opt/skywire \ - skycoin/skywire:test skywire-cli update-config hypervisor-pks + skycoin/skywire:test skywire-cli config update hypervisor-pks ``` ## Run `skywire-visor` diff --git a/cmd/skywire-cli/README.md b/cmd/skywire-cli/README.md index c72601c1fc..27b739c367 100644 --- a/cmd/skywire-cli/README.md +++ b/cmd/skywire-cli/README.md @@ -6,31 +6,33 @@ skywire command line interface - [Install](#install) - [skywire-cli usage](#skywire-cli-usage) - - [mdisc usage](#mdisc-usage) + - [mdisc usage](#mdisc-usage) - [available servers](#available-servers) - - [entry](#entry) - - [visor usage](#visor-usage) - - [add rule](#add-rule) - - [add tp](#add-tp) - - [app logs since](#app-logs-since) - - [disc tp](#disc-tp) - - [exec](#exec) - - [gen config](#gen-config) - - [ls apps](#ls-apps) - - [ls rules](#ls-rules) - - [ls tp](#ls-tp) - - [ls types](#ls-types) - - [pk](#pk) - - [rm rule](#rm-rule) - - [rm tp](#rm-tp) - - [rule](#rule) - - [set app autostart](#set-app-autostart) - - [start app](#start-app) - - [stop app](#stop-app) - - [tp](#tp) - - [update config](#update-config) - - [version](#version) - - [rtfind usage](#rtfind-usage) + - [entry](#entry) + - [visor usage](#visor-usage) + - [add rule](#add-rule) + - [add tp](#add-tp) + - [app logs since](#app-logs-since) + - [disc tp](#disc-tp) + - [exec](#exec) + - [ls apps](#ls-apps) + - [ls rules](#ls-rules) + - [ls tp](#ls-tp) + - [ls types](#ls-types) + - [pk](#pk) + - [rm rule](#rm-rule) + - [rm tp](#rm-tp) + - [rule](#rule) + - [set app autostart](#set-app-autostart) + - [start app](#start-app) + - [stop app](#stop-app) + - [tp](#tp) + - [version](#version) + - [rtfind usage](#rtfind-usage) + - [config usage](#config-usage) + - [gen](#gen) + - [update](#update) + ## Install @@ -52,6 +54,7 @@ Usage: skywire-cli [command] Available Commands: + config Contains sub-commands that interact with the config of local skywire-visor help Help about any command mdisc Contains sub-commands that interact with a remote DMSG Discovery rtfind Queries the Route Finder for available routes between two visors @@ -152,7 +155,6 @@ Available Commands: app-logs-since Gets logs from given app since RFC3339Nano-formated timestamp. "beginning" is a special timestamp to fetch all the logs disc-tp Queries the Transport Discovery to find transport(s) of given transport ID or edge public key exec Executes the given command - gen-config Generates a config file ls-apps Lists apps running on the local visor ls-rules Lists the local visor's routing rules ls-tp Lists the available transports with optional filter flags @@ -165,7 +167,6 @@ Available Commands: start-app Starts an app of given name stop-app Stops an app of given name tp Returns summary of given transport by id - update-config Updates a config file version Obtains version and build info of the node Flags: @@ -198,7 +199,6 @@ Flags: ``` - #### add tp add transport @@ -282,6 +282,7 @@ $ skywire-cli visor exec ##### Example ls + ``` $ skywire-cli visor exec ls bin @@ -321,529 +322,592 @@ $skywire-cli visor exec echo -- "-a" -a ``` +#### ls apps -#### gen config +list apps ``` -$ skywire-cli visor gen-config --help -Generates a config file +$ skywire-cli visor ls-apps +``` -Usage: - skywire-cli visor gen-config [flags] +##### Example -Flags: - -h, --help help for gen-config - --hypervisor-pks string public keys of hypervisors that should be added to this visor - -i, --is-hypervisor generate a hypervisor configuration. - -o, --output string path of output config file. (default "skywire-config.json") - -p, --package use defaults for package-based installations in /opt/skywire - -r, --replace rewrite existing config (retains keys). - --sk cipher.SecKey if unspecified, a random key pair will be generated. - (default 0000000000000000000000000000000000000000000000000000000000000000) - -s, --skybian use defaults paths found in skybian - writes config to /etc/skywire-config.json - -t, --testenv use test deployment service. +``` +$ skywire-cli visor ls-apps +app ports auto_start status +skychat 1 true running +skysocks 3 true running +skysocks-client 13 false stopped +vpn-server 44 false stopped +vpn-client 43 false stopped +``` + +#### ls rules + +Lists the local visor's routing rules -Global Flags: - --rpc string RPC server address (default "localhost:3435") +``` +$ skywire-cli visor ls-rules ``` -##### Example defaults +##### Example -The default visor config generation assumes the command is run from the root of the cloned repository +``` +$ skywire-cli visor ls-rules +id type local-port remote-port remote-pk resp-id next-route-id next-transport-id expire-at +``` + +#### ls tp + +list transports ``` -$ cd $GOPATH/src/github.com/skycoin/skywire -$ skywire-cli visor gen-config -[2021-06-24T08:58:56-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/home/user/go/src/github.com/skycoin/skywire/skywire-config.json" -[2021-06-24T08:58:56-05:00] INFO [skywire-cli]: Updated file '/home/user/go/src/github.com/skycoin/skywire/skywire-config.json' to: { - "version": "v1.0.0", - "sk": "b65d256d4a2af23e330179d95c9526a6e053479d8b5ca077ecf97dd8ec189876", - "pk": "0336d57c96b706b8560223b0fa71e55331ab3dabe34dd464002ab10bf199ada2b3", - "dmsg": { - "discovery": "http://dmsg.discovery.skywire.skycoin.com", - "sessions_count": 1 - }, - "dmsgpty": { - "port": 22, - "authorization_file": "./dmsgpty/whitelist.json", - "cli_network": "unix", - "cli_address": "/tmp/dmsgpty.sock" - }, - "stcp": { - "pk_table": null, - "local_address": ":7777" - }, - "transport": { - "discovery": "http://transport.discovery.skywire.skycoin.com", - "address_resolver": "http://address.resolver.skywire.skycoin.com", - "log_store": { - "type": "file", - "location": "./transport_logs" - }, - "trusted_visors": null - }, - "routing": { - "setup_nodes": [ - "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" - ], - "route_finder": "http://routefinder.skywire.skycoin.com", - "route_finder_timeout": "10s" - }, - "uptime_tracker": { - "addr": "http://uptime-tracker.skywire.skycoin.com" - }, - "launcher": { - "discovery": { - "update_interval": "30s", - "service_discovery": "http://service.discovery.skycoin.com" - }, - "apps": [ - { - "name": "skychat", - "args": [ - "-addr", - ":8001" - ], - "auto_start": true, - "port": 1 - }, - { - "name": "skysocks", - "auto_start": true, - "port": 3 - }, - { - "name": "skysocks-client", - "auto_start": false, - "port": 13 - }, - { - "name": "vpn-server", - "auto_start": false, - "port": 44 - }, - { - "name": "vpn-client", - "auto_start": false, - "port": 43 - } - ], - "server_addr": "localhost:5505", - "bin_path": "./apps", - "local_path": "./local" - }, - "hypervisors": [], - "cli_addr": "localhost:3435", - "log_level": "info", - "shutdown_timeout": "10s", - "restart_check_delay": "1s" -} +$ skywire-cli visor ls-tp ``` -The default configuration is for a visor only. To generate a configuration which provides the hypervisor web interface, the `-i` or `--is-hypervisor` flag should be specified. +##### Example + ``` -$ skywire-cli visor gen-config -i +$ skywire-cli visor ls-tp +type id remote mode is_up ``` -##### Example hypervisor configuration for skybian +#### ls types + +Lists transport types used by the local visor + ``` -$ skywire-cli visor gen-config -irs +$ skywire-cli visor ls-types ``` -##### Example visor configuration for skybian -It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. +##### Example -Determine the hypervisor public key by running the following command on the machine running the hypervisor +``` +$ skywire-cli visor ls-types +dmsg +stcp +stcpr +sudph +``` + +#### pk + +Obtains the public key of the visor ``` $ skywire-cli visor pk ``` -substitute the hypervisor public key in the following command: + +##### Example + ``` -$ skywire-cli visor gen-config --hypervisor-pks -rs +$ skywire-cli visor pk +0359f02198933550ad5b41a21470a0bbe0f73c0eb6e93d7d279133a0d5bffc645c ``` -##### Example hypervisor configuration for package based installation +#### rm rule -This assumes the skywire installation is at `/opt/skywire` with binaries and apps in their own subdirectories. +Removes a routing rule ``` -$ skywire-cli visor gen-config -ip -[2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" -[2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" -[2021-06-24T09:09:39-05:00] INFO [skywire-cli]: Updated file '/opt/skywire/skywire.json' to: { - "version": "v1.0.0", - "sk": "b65d256d4a2af23e330179d95c9526a6e053479d8b5ca077ecf97dd8ec189876", - "pk": "0336d57c96b706b8560223b0fa71e55331ab3dabe34dd464002ab10bf199ada2b3", - "dmsg": { - "discovery": "http://dmsg.discovery.skywire.skycoin.com", - "sessions_count": 1 - }, - "dmsgpty": { - "port": 22, - "authorization_file": "/opt/skywire/dmsgpty/whitelist.json", - "cli_network": "unix", - "cli_address": "/tmp/dmsgpty.sock" - }, - "stcp": { - "pk_table": null, - "local_address": ":7777" - }, - "transport": { - "discovery": "http://transport.discovery.skywire.skycoin.com", - "address_resolver": "http://address.resolver.skywire.skycoin.com", - "log_store": { - "type": "file", - "location": "/opt/skywire/transport_logs" - }, - "trusted_visors": null - }, - "routing": { - "setup_nodes": [ - "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" - ], - "route_finder": "http://routefinder.skywire.skycoin.com", - "route_finder_timeout": "10s" - }, - "uptime_tracker": { - "addr": "http://uptime-tracker.skywire.skycoin.com" - }, - "launcher": { - "discovery": { - "update_interval": "30s", - "service_discovery": "http://service.discovery.skycoin.com" - }, - "apps": [ - { - "name": "skychat", - "args": [ - "-addr", - ":8001" - ], - "auto_start": true, - "port": 1 - }, - { - "name": "skysocks", - "auto_start": true, - "port": 3 - }, - { - "name": "skysocks-client", - "auto_start": false, - "port": 13 - }, - { - "name": "vpn-server", - "auto_start": false, - "port": 44 - }, - { - "name": "vpn-client", - "auto_start": false, - "port": 43 - } - ], - "server_addr": "localhost:5505", - "bin_path": "/opt/skywire/apps", - "local_path": "/opt/skywire/local" - }, - "hypervisors": [], - "cli_addr": "localhost:3435", - "log_level": "info", - "shutdown_timeout": "10s", - "restart_check_delay": "1s", - "hypervisor": { - "db_path": "/opt/skywire/users.db", - "enable_auth": true, - "cookies": { - "hash_key": "fa985b3bb729fb4feedf3c7f6329cc31dcdca4457ac27d11cdeb14b39f248f01c5b784853074be3b95b02a9edeb2a6c721e0ee5675d1d55705cbd670082a107a", - "block_key": "7d2f37467789f9bbd9f053b26a2580e03d2e36ecae0ca966ab6ae10a34b1bfbc", - "expires_duration": 43200000000000, - "path": "/", - "domain": "" - }, - "dmsg_port": 46, - "http_addr": ":8000", - "enable_tls": true, - "tls_cert_file": "/opt/skywire/ssl/cert.pem", - "tls_key_file": "/opt/skywire/ssl/key.pem" - } -} - +$ skywire-cli visor rm-rule ``` -The configuration is written (or rewritten) +##### Example -##### Example - visor configuration for package based installation +``` +$ skywire-cli visor rm-rule -h +Removes a routing rule via route ID key -It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. +Usage: + skywire-cli visor rm-rule [flags] +``` -Determine the hypervisor public key by running the following command on the machine running the hypervisor +#### rm tp + +removes a transport ``` -$ skywire-cli visor pk +$ skywire-cli visor rm-tp ``` -When running a visor with or without a hypervisor on the same machine, it's wise to keep the same keys for the other config file. - -Copy the `skywire.json` config file from the previous example to `skywire-visor.json`; then paste the public key from the above command output into the following command +##### Example ``` -$ skywire-cli visor gen-config --hypervisor-pks -pr -``` +$ skywire-cli visor rm-tp -h +Removes transport with given id -The configuration is written (or rewritten) +Usage: + skywire-cli visor rm-tp [flags] -The configuration files should be specified in corresponding systemd service files or init / startup scripts to start either a visor or hypervisor instance +``` + +#### rule -starting the hypervisor intance ``` -skywire-visor -c /opt/skywire/skywire.json +$ skywire-cli visor rule ``` -starting visor-only or with remote hypervisor +##### Example + ``` -skywire-visor -c /opt/skywire/skywire-visor.json +$ skywire-cli visor rule -h +Returns a routing rule via route ID key + +Usage: + skywire-cli visor rule [flags] + ``` -#### ls apps +#### set-app-autostart -list apps +set application autostart ``` -$ skywire-cli visor ls-apps +$ skywire-cli visor set-app-autostart (on|off) ``` ##### Example ``` -$ skywire-cli visor ls-apps -app ports auto_start status -skychat 1 true running -skysocks 3 true running -skysocks-client 13 false stopped -vpn-server 44 false stopped -vpn-client 43 false stopped +$ skywire-cli visor set-app-autostart -h +Sets the autostart flag for an app of given name + +Usage: + skywire-cli visor set-app-autostart (on|off) [flags] ``` -#### ls rules +#### start-app -Lists the local visor's routing rules +start application ``` -$ skywire-cli visor ls-rules +$ skywire-cli visor set-app-autostart (on|off) ``` ##### Example ``` -$ skywire-cli visor ls-rules -id type local-port remote-port remote-pk resp-id next-route-id next-transport-id expire-at +$ skywire-cli visor set-app-autostart -h +Sets the autostart flag for an app of given name + +Usage: + skywire-cli visor set-app-autostart (on|off) [flags] + ``` +#### stop-app -#### ls tp +stop application -list transports ``` -$ skywire-cli visor ls-tp +$ skywire-cli visor stop app ``` ##### Example ``` -$ skywire-cli visor ls-tp -type id remote mode is_up +$ skywire-cli visor stop-app skychat +OK ``` -#### ls types +#### tp -Lists transport types used by the local visor +Returns summary of given transport by id ``` -$ skywire-cli visor ls-types +$ skywire-cli visor tp ``` ##### Example ``` -$ skywire-cli visor ls-types -dmsg -stcp -stcpr -sudph +$ skywire-cli visor tp -h +Returns summary of given transport by id + +Usage: + skywire-cli visor tp [flags] ``` -#### pk +#### version -Obtains the public key of the visor +version ``` -$ skywire-cli visor pk +$ skywire-cli visor version ``` ##### Example ``` -$ skywire-cli visor pk -0359f02198933550ad5b41a21470a0bbe0f73c0eb6e93d7d279133a0d5bffc645c +$ skywire-cli visor version +Version "0.4.1" built on "2021-03-19T23:26:21Z" against commit "d804a8ce" ``` -#### rm rule - -Removes a routing rule +### rtfind usage ``` -$ skywire-cli visor rm-rule +skywire-cli rtfind ``` ##### Example ``` -$ skywire-cli visor rm-rule -h -Removes a routing rule via route ID key +$ skywire-cli rtfind -h + +Queries the Route Finder for available routes between two visors Usage: - skywire-cli visor rm-rule [flags] +skywire-cli rtfind [flags] +Flags: +--addr string address in which to contact route finder service (default "http://routefinder.skywire.skycoin.com") +-h, --help help for rtfind +--max-hops uint16 max hops for the returning routeFinderRoutesCmd (default 1000) +--min-hops uint16 min hops for the returning routeFinderRoutesCmd (default 1) +--timeout duration timeout for remote server requests (default 10s) ``` -#### rm tp +### config usage -removes a transport ``` -$ skywire-cli visor rm-tp +skywire-cli config -h + +Contains sub-commands that interact with the config of local skywire-visor + +Usage: + skywire-cli config [command] + +Available Commands: + gen Generates a config file + update Updates a config file + +Flags: + -h, --help help for config + +Use "skywire-cli config [command] --help" for more information about a command. ``` -##### Example +#### gen ``` -$ skywire-cli visor rm-tp -h -Removes transport with given id +$ skywire-cli config gen --help +Generates a config file Usage: - skywire-cli visor rm-tp [flags] + skywire-cli config gen [flags] +Flags: + -h, --help help for gen + --hypervisor-pks string public keys of hypervisors that should be added to this visor + -i, --is-hypervisor generate a hypervisor configuration. + -o, --output string path of output config file. (default "skywire-config.json") + -p, --package use defaults for package-based installations in /opt/skywire + -r, --replace rewrite existing config (retains keys). + --sk cipher.SecKey if unspecified, a random key pair will be generated. + (default 0000000000000000000000000000000000000000000000000000000000000000) + -s, --skybian use defaults paths found in skybian + writes config to /etc/skywire-config.json + -t, --testenv use test deployment service. + +Global Flags: + --rpc string RPC server address (default "localhost:3435") ``` +##### Example defaults -#### rule +The default visor config generation assumes the command is run from the root of the cloned repository ``` -$ skywire-cli visor rule +$ cd $GOPATH/src/github.com/skycoin/skywire +$ skywire-cli config gen +[2021-06-24T08:58:56-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/home/user/go/src/github.com/skycoin/skywire/skywire-config.json" +[2021-06-24T08:58:56-05:00] INFO [skywire-cli]: Updated file '/home/user/go/src/github.com/skycoin/skywire/skywire-config.json' to: { + "version": "v1.0.0", + "sk": "b65d256d4a2af23e330179d95c9526a6e053479d8b5ca077ecf97dd8ec189876", + "pk": "0336d57c96b706b8560223b0fa71e55331ab3dabe34dd464002ab10bf199ada2b3", + "dmsg": { + "discovery": "http://dmsg.discovery.skywire.skycoin.com", + "sessions_count": 1 + }, + "dmsgpty": { + "port": 22, + "authorization_file": "./dmsgpty/whitelist.json", + "cli_network": "unix", + "cli_address": "/tmp/dmsgpty.sock" + }, + "stcp": { + "pk_table": null, + "local_address": ":7777" + }, + "transport": { + "discovery": "http://transport.discovery.skywire.skycoin.com", + "address_resolver": "http://address.resolver.skywire.skycoin.com", + "log_store": { + "type": "file", + "location": "./transport_logs" + }, + "trusted_visors": null + }, + "routing": { + "setup_nodes": [ + "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" + ], + "route_finder": "http://routefinder.skywire.skycoin.com", + "route_finder_timeout": "10s" + }, + "uptime_tracker": { + "addr": "http://uptime-tracker.skywire.skycoin.com" + }, + "launcher": { + "discovery": { + "update_interval": "30s", + "service_discovery": "http://service.discovery.skycoin.com" + }, + "apps": [ + { + "name": "skychat", + "args": [ + "-addr", + ":8001" + ], + "auto_start": true, + "port": 1 + }, + { + "name": "skysocks", + "auto_start": true, + "port": 3 + }, + { + "name": "skysocks-client", + "auto_start": false, + "port": 13 + }, + { + "name": "vpn-server", + "auto_start": false, + "port": 44 + }, + { + "name": "vpn-client", + "auto_start": false, + "port": 43 + } + ], + "server_addr": "localhost:5505", + "bin_path": "./apps", + "local_path": "./local" + }, + "hypervisors": [], + "cli_addr": "localhost:3435", + "log_level": "info", + "shutdown_timeout": "10s", + "restart_check_delay": "1s" +} ``` -##### Example +The default configuration is for a visor only. To generate a configuration which provides the hypervisor web interface, +the `-i` or `--is-hypervisor` flag should be specified. ``` -$ skywire-cli visor rule -h -Returns a routing rule via route ID key +$ skywire-cli config gen -i +``` -Usage: - skywire-cli visor rule [flags] +##### Example hypervisor configuration for skybian +``` +$ skywire-cli config gen -irs ``` -#### set-app-autostart +##### Example visor configuration for skybian -set application autostart +It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. + +Determine the hypervisor public key by running the following command on the machine running the hypervisor ``` -$ skywire-cli visor set-app-autostart (on|off) +$ skywire-cli visor pk ``` -##### Example +substitute the hypervisor public key in the following command: ``` -$ skywire-cli visor set-app-autostart -h -Sets the autostart flag for an app of given name - -Usage: - skywire-cli visor set-app-autostart (on|off) [flags] +$ skywire-cli config gen --hypervisor-pks -rs ``` -#### start-app +##### Example hypervisor configuration for package based installation -start application -``` -$ skywire-cli visor set-app-autostart (on|off) -``` +This assumes the skywire installation is at `/opt/skywire` with binaries and apps in their own subdirectories. -##### Example +``` +$ skywire-cli config gen -ip +[2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" +[2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" +[2021-06-24T09:09:39-05:00] INFO [skywire-cli]: Updated file '/opt/skywire/skywire.json' to: { + "version": "v1.0.0", + "sk": "b65d256d4a2af23e330179d95c9526a6e053479d8b5ca077ecf97dd8ec189876", + "pk": "0336d57c96b706b8560223b0fa71e55331ab3dabe34dd464002ab10bf199ada2b3", + "dmsg": { + "discovery": "http://dmsg.discovery.skywire.skycoin.com", + "sessions_count": 1 + }, + "dmsgpty": { + "port": 22, + "authorization_file": "/opt/skywire/dmsgpty/whitelist.json", + "cli_network": "unix", + "cli_address": "/tmp/dmsgpty.sock" + }, + "stcp": { + "pk_table": null, + "local_address": ":7777" + }, + "transport": { + "discovery": "http://transport.discovery.skywire.skycoin.com", + "address_resolver": "http://address.resolver.skywire.skycoin.com", + "log_store": { + "type": "file", + "location": "/opt/skywire/transport_logs" + }, + "trusted_visors": null + }, + "routing": { + "setup_nodes": [ + "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" + ], + "route_finder": "http://routefinder.skywire.skycoin.com", + "route_finder_timeout": "10s" + }, + "uptime_tracker": { + "addr": "http://uptime-tracker.skywire.skycoin.com" + }, + "launcher": { + "discovery": { + "update_interval": "30s", + "service_discovery": "http://service.discovery.skycoin.com" + }, + "apps": [ + { + "name": "skychat", + "args": [ + "-addr", + ":8001" + ], + "auto_start": true, + "port": 1 + }, + { + "name": "skysocks", + "auto_start": true, + "port": 3 + }, + { + "name": "skysocks-client", + "auto_start": false, + "port": 13 + }, + { + "name": "vpn-server", + "auto_start": false, + "port": 44 + }, + { + "name": "vpn-client", + "auto_start": false, + "port": 43 + } + ], + "server_addr": "localhost:5505", + "bin_path": "/opt/skywire/apps", + "local_path": "/opt/skywire/local" + }, + "hypervisors": [], + "cli_addr": "localhost:3435", + "log_level": "info", + "shutdown_timeout": "10s", + "restart_check_delay": "1s", + "hypervisor": { + "db_path": "/opt/skywire/users.db", + "enable_auth": true, + "cookies": { + "hash_key": "fa985b3bb729fb4feedf3c7f6329cc31dcdca4457ac27d11cdeb14b39f248f01c5b784853074be3b95b02a9edeb2a6c721e0ee5675d1d55705cbd670082a107a", + "block_key": "7d2f37467789f9bbd9f053b26a2580e03d2e36ecae0ca966ab6ae10a34b1bfbc", + "expires_duration": 43200000000000, + "path": "/", + "domain": "" + }, + "dmsg_port": 46, + "http_addr": ":8000", + "enable_tls": true, + "tls_cert_file": "/opt/skywire/ssl/cert.pem", + "tls_key_file": "/opt/skywire/ssl/key.pem" + } +} ``` -$ skywire-cli visor set-app-autostart -h -Sets the autostart flag for an app of given name -Usage: - skywire-cli visor set-app-autostart (on|off) [flags] +The configuration is written (or rewritten) -``` +##### Example - visor configuration for package based installation -#### stop-app +It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. -stop application +Determine the hypervisor public key by running the following command on the machine running the hypervisor ``` -$ skywire-cli visor stop app +$ skywire-cli visor pk ``` -##### Example +When running a visor with or without a hypervisor on the same machine, it's wise to keep the same keys for the other +config file. + +Copy the `skywire.json` config file from the previous example to `skywire-visor.json`; then paste the public key from +the above command output into the following command ``` -$ skywire-cli visor stop-app skychat -OK +$ skywire-cli config gen --hypervisor-pks -pr ``` +The configuration is written (or rewritten) -#### tp +The configuration files should be specified in corresponding systemd service files or init / startup scripts to start +either a visor or hypervisor instance -Returns summary of given transport by id +starting the hypervisor intance ``` -$ skywire-cli visor tp +skywire-visor -c /opt/skywire/skywire.json ``` -##### Example +starting visor-only or with remote hypervisor ``` -$ skywire-cli visor tp -h -Returns summary of given transport by id - -Usage: - skywire-cli visor tp [flags] +skywire-visor -c /opt/skywire/skywire-visor.json ``` - -#### update config +#### update ``` -$ skywire-cli visor update-config -h +$ ./skywire-cli config update --help Updates a config file Usage: - skywire-cli visor update-config [flags] + skywire-cli config update [flags] Flags: --add-hypervisor-pks string public keys of hypervisors that should be added to this visor -e, --environment string desired environment (values production or testing) (default "production") - -h, --help help for update-config + -h, --help help for update -i, --input string path of input config file. (default "skywire-config.json") -o, --output string path of output config file. (default "skywire-config.json") --reset-hypervisor-pks resets hypervisor`s configuration - -Global Flags: - --rpc string RPC server address (default "localhost:3435") - ``` ##### Example ``` -skywire-cli visor update-config +skywire-cli config update [2021-06-24T10:42:33-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="skywire-config.json" [2021-06-24T10:42:33-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="skywire-config.json" [2021-06-24T10:42:33-05:00] INFO [skywire-cli]: Updated file '/home/d0mo/go/src/github.com/skycoin/skywire/skywire-config.json' to: { @@ -930,44 +994,3 @@ skywire-cli visor update-config "restart_check_delay": "1s" } ``` - - -#### version - -version - -``` -$ skywire-cli visor version -``` - -##### Example - -``` -$ skywire-cli visor version -Version "0.4.1" built on "2021-03-19T23:26:21Z" against commit "d804a8ce" -``` - - -### rtfind usage - -``` -skywire-cli rtfind -``` - -##### Example - -``` -$ skywire-cli rtfind -h - -Queries the Route Finder for available routes between two visors - -Usage: -skywire-cli rtfind [flags] - -Flags: ---addr string address in which to contact route finder service (default "http://routefinder.skywire.skycoin.com") --h, --help help for rtfind ---max-hops uint16 max hops for the returning routeFinderRoutesCmd (default 1000) ---min-hops uint16 min hops for the returning routeFinderRoutesCmd (default 1) ---timeout duration timeout for remote server requests (default 10s) -``` diff --git a/cmd/skywire-cli/commands/visor/gen-config.go b/cmd/skywire-cli/commands/config/gen.go similarity index 99% rename from cmd/skywire-cli/commands/visor/gen-config.go rename to cmd/skywire-cli/commands/config/gen.go index 5f58e2042b..4bf52f5778 100644 --- a/cmd/skywire-cli/commands/visor/gen-config.go +++ b/cmd/skywire-cli/commands/config/gen.go @@ -1,4 +1,4 @@ -package visor +package config import ( "encoding/json" @@ -43,7 +43,7 @@ func init() { } var genConfigCmd = &cobra.Command{ - Use: "gen-config", + Use: "gen", Short: "Generates a config file", PreRun: func(_ *cobra.Command, _ []string) { var err error diff --git a/cmd/skywire-cli/commands/config/root.go b/cmd/skywire-cli/commands/config/root.go new file mode 100644 index 0000000000..123c811947 --- /dev/null +++ b/cmd/skywire-cli/commands/config/root.go @@ -0,0 +1,14 @@ +package config + +import ( + "github.com/skycoin/skycoin/src/util/logging" + "github.com/spf13/cobra" +) + +var logger = logging.MustGetLogger("skywire-cli") + +// RootCmd contains commands that interact with the config of local skywire-visor +var RootCmd = &cobra.Command{ + Use: "config", + Short: "Contains sub-commands that interact with the config of local skywire-visor", +} diff --git a/cmd/skywire-cli/commands/visor/update-config.go b/cmd/skywire-cli/commands/config/update.go similarity index 98% rename from cmd/skywire-cli/commands/visor/update-config.go rename to cmd/skywire-cli/commands/config/update.go index 14678776f8..70bba612dc 100644 --- a/cmd/skywire-cli/commands/visor/update-config.go +++ b/cmd/skywire-cli/commands/config/update.go @@ -1,4 +1,4 @@ -package visor +package config import ( "encoding/json" @@ -37,7 +37,7 @@ func init() { } var updateConfigCmd = &cobra.Command{ - Use: "update-config", + Use: "update", Short: "Updates a config file", PreRun: func(_ *cobra.Command, _ []string) { var err error diff --git a/cmd/skywire-cli/commands/root.go b/cmd/skywire-cli/commands/root.go index 4367812b5a..0828a44c76 100644 --- a/cmd/skywire-cli/commands/root.go +++ b/cmd/skywire-cli/commands/root.go @@ -1,6 +1,7 @@ package commands import ( + "github.com/skycoin/skywire/cmd/skywire-cli/commands/config" "log" "github.com/spf13/cobra" @@ -20,6 +21,7 @@ func init() { visor.RootCmd, mdisc.RootCmd, rtfind.RootCmd, + config.RootCmd, ) } diff --git a/cmd/skywire-visor/README.md b/cmd/skywire-visor/README.md index be4af355c9..4a1341d3d0 100644 --- a/cmd/skywire-visor/README.md +++ b/cmd/skywire-visor/README.md @@ -44,7 +44,7 @@ Flags: Refer to the skywire-cli documentation for more detailed information regarding additional flags and argument that may be passed to the following command: ``` -skywire-cli visor gen-config +skywire-cli config gen ``` With no additional flags or arguments, the configuration is written to skywire-config.json and stdout. @@ -94,14 +94,14 @@ The configuration file is generated in the following way for a visor with local hypervisor: ``` -$ skywire-cli visor gen-config -ip +$ skywire-cli config gen -ip ``` for visor with remote hypervisor; first copy the existing configuration file to keep the same keys. ``` # cp /opt/skywire/skywire.json /opt/skywire/skywire-visor.json -# skywire-cli visor gen-config --hypervisor-pks -p +# skywire-cli config gen --hypervisor-pks -p ``` These two configuration files can be referenced in systemd service files or init scripts to start skywire with either a local or remote hypervisor. diff --git a/docker/images/visor/entrypoint.sh b/docker/images/visor/entrypoint.sh index 8d011a929b..9e95c71f7f 100755 --- a/docker/images/visor/entrypoint.sh +++ b/docker/images/visor/entrypoint.sh @@ -9,7 +9,7 @@ default_config_path=/opt/skywire/config.json gen_default_config() { echo "no config found, generating one...." - /release/skywire-cli visor gen-config -o "$default_config_path" -r --is-hypervisor + /release/skywire-cli config gen -o "$default_config_path" -r --is-hypervisor sed -i 's/localhost//g' "$default_config_path" echo "config generated" } From c8c6b4051c8e4649afc7bb86b2026f07f877fb52 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Thu, 7 Oct 2021 21:56:21 +0700 Subject: [PATCH 2/3] formatting --- cmd/skywire-cli/commands/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/skywire-cli/commands/root.go b/cmd/skywire-cli/commands/root.go index 0828a44c76..c89bdc2d80 100644 --- a/cmd/skywire-cli/commands/root.go +++ b/cmd/skywire-cli/commands/root.go @@ -1,11 +1,11 @@ package commands import ( - "github.com/skycoin/skywire/cmd/skywire-cli/commands/config" "log" "github.com/spf13/cobra" + "github.com/skycoin/skywire/cmd/skywire-cli/commands/config" "github.com/skycoin/skywire/cmd/skywire-cli/commands/mdisc" "github.com/skycoin/skywire/cmd/skywire-cli/commands/rtfind" "github.com/skycoin/skywire/cmd/skywire-cli/commands/visor" From 508a12d5cc9edb8cbee3e018ebf0ef68fafb36d5 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Fri, 8 Oct 2021 22:38:01 +0700 Subject: [PATCH 3/3] added checks for environment value, and edited CHANGELOG.md --- CHANGELOG.md | 2 ++ cmd/skywire-cli/commands/config/update.go | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aecde19630..9d273c9b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - changed proxy_discovery_addr field to service_discovery - updated UI - removed `--public` flag from `skywire-cli visor add-tp` command +- removed `skywire-cli visor gen-config` and `skywire-cli visor update-config` subcommands. ### Added @@ -25,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - added public_autoconnect field to transport section - added transport_setup_nodes field to transport section - added MinHops field to V1Routing section of config +- added `skywire-cli config` subcommand ## 0.2.1 - 2020.04.07 diff --git a/cmd/skywire-cli/commands/config/update.go b/cmd/skywire-cli/commands/config/update.go index 70bba612dc..94b5e33af5 100644 --- a/cmd/skywire-cli/commands/config/update.go +++ b/cmd/skywire-cli/commands/config/update.go @@ -42,7 +42,7 @@ var updateConfigCmd = &cobra.Command{ PreRun: func(_ *cobra.Command, _ []string) { var err error if output, err = filepath.Abs(addOutput); err != nil { - logger.WithError(err).Fatal("Invalid output provided.") + logger.WithError(err).Fatal("Invalid config output.") } }, Run: func(_ *cobra.Command, _ []string) { @@ -76,12 +76,13 @@ var updateConfigCmd = &cobra.Command{ } } - if environment == "production" { + switch environment { + case "production": visorconfig.SetDefaultProductionValues(conf) - } - - if environment == "testing" { + case "testing": visorconfig.SetDefaultTestingValues(conf) + default: + logger.Fatal("Unrecognized environment value: ", environment) } if resetHypervisor {