A minimalist REST API wrapper for python's subprocess API.
Project description
Flask-Shell2HTTP
A minimalist REST API wrapper for python's subprocess API.
Execute shell commands asynchronously and safely from flask's endpoints.
Inspired by the work of awesome folks over at msoap/shell2http.
You can use this for
- Set a script that runs on a succesful POST request to an endpoint of your choice. See Example code
- Map a base command to an endpoint and passing dynamic arguments to it. See Example code
- Can also process uploaded files. See Example code
- Choose to run a command asynchronously or not. (upcoming feature)
Quick Start
Dependencies
- Python:
>=v3.6
- Flask
- Flask-Executor
Install
$ pip install flask_shell2http flask_executor
Example
from flask import Flask
from flask_executor import Executor
from flask_shell2http import Shell2HTTP
# Flask application instance
app = Flask(__name__)
executor = Executor(app)
shell2http = Shell2HTTP(app=app, executor=executor, base_url_prefix="/commands/")
shell2http.register_command(endpoint="saythis", command_name="echo")
Run the application server with, $ flask run -p 4000
.
Make HTTP calls
$ curl -X POST -d '{"args": ["Hello", "World!"]}' http://localhost:4000/commands/saythis
or using python's requests module,
data = {"args": ["Hello", "World!"]}
resp = requests.post("http://localhost:4000/commands/saythis", json=data)
print("Result:", resp.json())
returns JSON,
{
"key": "ddbe0a94847c65f9b8198424ffd07c50",
"status": "running"
}
Then using this key
you can query for the result,
$ curl http://localhost:4000/commands/saythis?key=ddbe0a94847c65f9b8198424ffd07c50
Returns result in JSON,
{
"end_time": 1593019807.782958,
"error": "",
"md5": "ddbe0a94847c65f9b8198424ffd07c50",
"process_time": 0.00748753547668457,
"report": {
"result": "Hello World!\n"
},
"start_time": 1593019807.7754705,
"status": "success"
}
Why?
This was made to integrate various command-line tools easily with IntelOwl.
Various examples
You can find various examples under examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Shell2HTTP-1.0.1.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for Flask_Shell2HTTP-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96e2f0710fe16ed5a015342c5eb64fa1e301b05d04e04c4697dc3ca2a7cc994f |
|
MD5 | 26d3f6c060c3f7f5b47b8b522d7c0878 |
|
BLAKE2b-256 | 1a95dfa6071be847403574fb2ad433037eda9726893c3b3e3c48cb5bf93dc516 |