The purpose of this tool is to help with the following three use cases:
-
You want to run a piece of code in a remote environment, but the code is too large or it is otherwise impractical to paste it into the console (sometimes pasting many lines of code breaks the session).
-
You want to pull information from a remote environment's console, but this information is too large to easily copy it from the console.
-
You want to do both 1 and 2 at the same time.
This is not meant to be used in a production environment!
You only need Python 3.6+
and ngrok
. As a reminder, ngrok
can be installed via brew install ngrok
, and you need to configure it. Here's a sample configuration for ngrok
. It only takes one file:
# In mac: ~/Library/Application Support/ngrok/ngrok.yml
authtoken: "*****" # from https://dashboard.ngrok.com/get-started/your-authtoken
version: "2"
region: us
-
Put the code that you want to run in a file. Name the file something that starts with
code
(e.g.code.rb
,code_pull_assignments.rb
), and place it in this directory. For example:# code.rb class RemoteExecution def self.run # ... logic to run end end
-
Open a terminal session and start the
remote-execution
server with:python server.py
-
Open another terminal session and run
ngrok
:ngrok http 8000
Take note of the
https
url as it is going to be used in the next step. This url looks something likehttps://c7fd6475f29d.ngrok.io
. You could also specify the--hostname
flag if you have one here, but beaware that this could pose a security risk if others know this url, as they can easily see all files in this directory.You need to specify
8000
becauseserver.py
runs on that port by default. -
Open another terminal session to console into the desired environment, and
eval
the code from step 1 by pulling it via thengrok
url from step 2 and using the file name for the path. For example, if you're usingruby
:eval(open('https://c7fd6475f29d.ngrok.io/code.rb').read); RemoteExecution.run eval(open('https://c7fd6475f29d.ngrok.io/code_pull_assignments.rb').read); RemoteExecution.run
That's it. If you want to test this locally, you can skip the ngrok
step and just use http://127.0.0.1:8000
in step 4.
-
Open a terminal session and start the
remote-execution
server. See step from Use case 1 for details. -
Open another terminal session and run
ngrok
. See step from Use case 1 for details. -
Open another terminal session to console into the desired environment. Perform an
HTTP POST
request to the url from step 2 with the json-formatted information that you want to pull as the body of the request. For example, if you're on ruby:payload = {'data': 5} # information that you would like to pull HTTParty.post('https://c7fd6475f29d.ngrok.io', :body => payload.to_json)
You can also test this directly from curl:
curl -X POST https://c7fd6475f29d.ngrok.io -d '{"data": 6}'
-
Put the code that you want to run in a file. Name the file something that starts with
code
(e.g.code.rb
,code_pull_assignments.rb
), and place it in this directory. Include a request at the end of the code to send the information back. If you're running ruby code, this would look something like this:# code.rb class RemoteExecution def self.run payload = {} # information that you would like to pull # ... run code to populate `payload` HTTParty.post('https://c7fd6475f29d.ngrok.io', :body => payload.to_json) end end
-
Open a terminal session and start the
remote-execution
server. See step from Use case 1 for details. -
Open another terminal session and run
ngrok
. See step from Use case 1 for details. -
Open another terminal session to console into the desired environment, and
eval
the code from step 1 by pulling it via thengrok
url from step 2 and using the file name for the path. For example, if you're usingruby
:eval(open('https://c7fd6475f29d.ngrok.io/code.rb').read); RemoteExecution.run