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

skywire-cli config priv subcommand #1369

Merged
merged 19 commits into from
Oct 5, 2022
Merged

skywire-cli config priv subcommand #1369

merged 19 commits into from
Oct 5, 2022

Conversation

0pcom
Copy link
Collaborator

@0pcom 0pcom commented Sep 20, 2022

Did you run make format && make check?
yes

Fixes
#1361
#1362

Adds:

  • skywire-cli config priv subcommands to set and get rewards address and privacy with privacy.json
  • skywire-cli visor priv subcommands for setting privacy over rpc
  • SetPrivacy and GetPrivacy rpc endpoints
  • system hardware survey generation (system.json)

How to test this PR:

skywire-cli config priv --help
skywire-cli config priv set -- help
skywire-cli config priv get -- help
skywire-cli config priv set
skywire-cli config priv get
skywire-cli config priv set <skycoin-address>
skywire-cli config priv set -a <skycoin-address> -i -o $(pwd)
skywire-cli visor priv set
skywire-cli visor priv get

@0pcom 0pcom changed the title add priv subcommand to skywire-cli config for generating privacy.json… skywire-cli config priv subcommand Sep 20, 2022
cmd/skywire-cli/commands/visor/logserver.go Outdated Show resolved Hide resolved
cmd/skywire-cli/commands/visor/logserver.go Outdated Show resolved Hide resolved
cmd/skywire-cli/commands/visor/logserver.go Outdated Show resolved Hide resolved
cmd/skywire-cli/commands/visor/logserver.go Outdated Show resolved Hide resolved
cmd/skywire-cli/commands/visor/logserver.go Outdated Show resolved Hide resolved
cmd/skywire-cli/commands/visor/privacy.go Outdated Show resolved Hide resolved
cmd/skywire-visor/commands/root.go Show resolved Hide resolved
pkg/skyenv/values.go Outdated Show resolved Hide resolved
pkg/skyenv/values.go Show resolved Hide resolved
pkg/visor/api.go Outdated
*/

// SetPrivacy implements API.
func (v *Visor) SetPrivacy(p skyenv.Privacy) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if its a wise move to make the visor binary dependent on the existence of the skywire-cli command being existent and in $PATH. Why not write to the config yourself here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it appears to me like we are calling SetPrivacy function inside the skywire-cli config priv set call via RPC. And then inside this function we are calling the cli function again. Are we sure this works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is my strong conviction that the visor should be writing its own configs. The cli is tasked with config generation and updating.

the issue we have had previously is with having multiple implementations of the same thing, and a certain bifurcation or lack of feature parity existed in that.

with this, the config is only written by the cli, and everything else calls upon that existing functionality.

the visor is, in a practical sense, dependant on skywire-cli. We don't explicitly support omitting skywire-cli from the installation. I don't know how you could practically or reliably run skywire without updating the config on version changes, that sort of thing. You would need skywire-cli at some point and there is no reason to separate the binaries.

lets please assume it's in the path and not go down such rabbit holes. If the cli cannot be assumed to be present with the visor i will begin to question my sanity.

it's not like it breaks the visor if there is a command not found error there.

Copy link
Contributor

@ersonp ersonp Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the code is written right now is overly complicated and the API part of it won't even work because it simply calls itself. I think there is a way to fix it by simply moving the code that writes to the privacy.json to internal or to it's own pkg and that way both the instances will be using the exact same code.

Also, there is no need to use the cli in this way since we are in the same codebase and can access the code programmatically. Because of the drawbacks of not having cli in the PATH using the current way may not cause any issues when installed by packages but will most certainly cause unnecessary headaches and issues while development and testing and also on a manual install/build.

@0pcom
Copy link
Collaborator Author

0pcom commented Oct 1, 2022

$ skywire-cli config priv --help
rewards & privacy setting

Sets the skycoin rewards address and ip public for the visor.
The config is written to the root of the default local directory
Run this command with root permissions for visors running as root via systemd
this config is served via dmsghttp along with transport logs
and the system hardware survey for automating rewards distribution

Usage:
  skywire-cli config priv [command]

Available Commands:
  set          set reward address & node privacy
  get          read reward address & privacy setting from file

Global Flags:
      --json   print output in json

Use "skywire-cli config priv [command] --help" for more information about a command.

The "default" (for testing) is the genesis address

$ skywire-cli config priv set --help
set reward address & node privacy

Usage:
  skywire-cli config priv set <address> [flags]

Flags:
  -a, --address string   reward address (default "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6")
  -o, --out string       output config: /opt/skywire/local/privacy.json
  -i, --publicip         display node ip

Global Flags:
      --json   print output in json
$ skywire-cli config priv get --help
read reward address & privacy setting from file

Usage:
  skywire-cli config priv get [flags]

Flags:
  -o, --out string   read config from: /opt/skywire/local/privacy.json

Global Flags:
      --json   print output in json
$ sudo skywire-cli config priv set
[2022-10-01T17:56:48-05:00] INFO [skywire-cli]: Updated file '/opt/skywire/local/privacy.json' to:
{
	"display_node_ip": false,
	"reward_address": "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6"
}
$ skywire-cli config priv get
{
	"display_node_ip": false,
	"reward_address": "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6"
}

demonstrating using skycoin-cli to get an address from a wallet to set reward address

$ sudo skywire-cli config priv set $(skycoin-cli listAddresses $HOME/.skycoin/wallets/*.wlt | head -n3 | tail -n1 | tr -d '"')
[2022-10-01T17:56:48-05:00] INFO [skywire-cli]: Updated file '/opt/skywire/local/privacy.json' to:
{
	"display_node_ip": false,
	"reward_address": "nLpzxwcH78ytc6k3ff1SfBrVCQHKaZ59SD"
}

demonstrating setting a custom path and setting display_node_ip true

$skywire-cli config priv set -a $(skycoin-cli listAddresses $HOME/.skycoin/wallets/*.wlt | head -n3 | tail -n1 | tr -d '"') -i -o $(pwd)/privacy.json
[2022-10-01T17:56:48-05:00] INFO [skywire-cli]: Updated file '/home/user/go/src/github.com/skycoin/skywire/privacy.json' to:
{
	"display_node_ip": true,
	"reward_address": "nLpzxwcH78ytc6k3ff1SfBrVCQHKaZ59SD"
}

the user will either set the privacy.json file via skywire-cli config priv set or from the hypervisor UI. To make the configuration possible, rpc functions were added. skywire-cli visor priv set & get are more or less a test of the rpc.

the underlying command executed is skywire-cli config priv set or get

config generation is intentionally done exclusively via skywire-cli, as it is not appropriate for the visor to generate or update configs except for very limited circumstances such as updating app autostart via the hypervisor UI

$ skywire-cli visor priv set --help
configure privacy settings

test of the api endpoint SetPrivacy

Usage:
  skywire-cli visor priv set [flags]

Flags:
  -a, --address string   reward address (default "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6")
  -o, --out string       output config: /home/user/.skywire/local/privacy.json
  -i, --publicip         display node ip

Global Flags:
      --json         print output in json
      --rpc string   RPC server address (default "localhost:3435")

skywire-cli visor priv get will show the contents of privacy.json if it exists in the visor's local path. By contrast skywire-cli config priv get reads the config from the default local path the visor uses when run as root / default for package installation.

$ skywire-cli visor priv get --help
configure privacy settings

test of the api endpoints GetPrivacy

Usage:
  skywire-cli visor priv get [flags]

Global Flags:
      --json         print output in json
      --rpc string   RPC server address (default "localhost:3435")

This seems like it should create the config with the wrong permissions for the path but in fact it does not

$ skywire-cli visor priv set -a $(skycoin-cli listAddresses $HOME/.skycoin/wallets/*.wlt | head -n3 | tail -n1 | tr -d '"') -i -o $(pwd)/privacy.json
[2022-10-01T17:56:48-05:00] INFO [skywire-cli visor priv set]: Privacy settings updated to:
{"display_node_ip":true,"reward_address":"nLpzxwcH78ytc6k3ff1SfBrVCQHKaZ59SD"}
$ skywire-cli visor priv get
{
	"display_node_ip": true,
	"reward_address": "nLpzxwcH78ytc6k3ff1SfBrVCQHKaZ59SD"
}

the config was removed here without permissions errors

$ cat privacy.json
{
	"display_node_ip": true,
	"reward_address": "nLpzxwcH78ytc6k3ff1SfBrVCQHKaZ59SD"
}
$ rm privacy.json

@ersonp ersonp merged commit 9824aba into develop Oct 5, 2022
@0pcom 0pcom deleted the feat/privacyjson branch March 10, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants