mediachain / aleph

א: The mediachain universe manipulation engine
MIT License
38 stars 16 forks source link

Automatic SSH tunneling with Deploy credentials file #99

Closed yusefnapora closed 7 years ago

yusefnapora commented 7 years ago

This adds a --deployCredentialsFile option that you can point at the file downloaded at the end of the Deploy process. If given, it will create an SSH tunnel for you to the remote machine, using the ip address, username and password from the file. It uses a javascript SSH implementation, so it should work on Windows.

To get this to work, I made a subcommand helper function that wraps each subcommand handler. If an SSH config is given, it creates the tunnel, runs the handler, then closes the tunnel afterwards. The subcommand handler functions had to be tweaked slightly to return a Promise, which the wrapper waits on before closing the tunnel.

I also made the subcommand helper create the RestClient instance, so subcommands can just pull the client member out of their options object, instead of grabbing apiUrl and creating a RestClient. That may come in handy if we ever add more options to the RestClient constructor, since we can just update it in one place.

example:

mcclient --deployCredentialsFile ~/Downloads/mediachain_node_138.68.24.97.yaml id
Peer ID: QmcrFvafCC64F44vhzv2JsYLYdLf3N2FHHiVjajDXrLhFh
Publisher ID: 4XTTMGc59GywZVY3gipX9nJNeWeW9bFN4h8ui61Q9vKvBM97m
Info: hello world

For this to be truly great, I'd like to add persistent configuration to mcclient, so we can store the credentials in e.g. ~/.mediachain/mcclient/config.json. Then we wouldn't need to require the --deployCredentialsFile option for every command. That seems like it belongs in its own PR though.

Closes #92

denisnazarov commented 7 years ago

Awesome, working for me 👍

vyzo commented 7 years ago

yusef, let's use ssh keys -- using passwords is a very bad idea.