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.
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 aPromise
, which the wrapper waits on before closing the tunnel.I also made the
subcommand
helper create theRestClient
instance, so subcommands can just pull theclient
member out of their options object, instead of grabbingapiUrl
and creating aRestClient
. That may come in handy if we ever add more options to theRestClient
constructor, since we can just update it in one place.example:
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