Run functions on a remote hub via an http server through a simple API
Project description
Run functions on a remote hub via an http server through a simple API. This greatly facilitates communication and sharing workloads across nodes in a JSON application.
INSTALLATION
pip install pop-gate
Get Capabilities
Gate extends pop-tree, which can be used to get details of all available resources
gate --refs "gate.init.tree"
curl http://localhost:5000 -H "Content-Type: application/json" -d '{"ref": "gate.init.tree"}'
USAGE
Run the gate server from the command line and expose specific patterns of hub references. The ‘–refs’ represent patters on the hub that are allowlisted. The ‘–prefix’ tells gate to assume that all refs are under a specific dynamic namespace.
In this example we will use a prefix of “gate” and allow all refs under ‘hub.gate.init’
gate --prefix gate --refs "init.*"
Use curl to run hub.gate.init.test() on the remote server like so:
curl http://localhost:8080 -H "Content-Type: application/json" -d '{"ref": "init.test"}'
Keyword arguments can be passed by adding extra keys to the call:
curl http://localhost:8080 -H "Content-Type: application/json" -d '{"ref": "init.test", "args": ["arg1", "arg2"], "kwargs": {"kwarg1": "value1"}}'
TESTING
Install gate locally with testing libraries:
git clone git@gitlab.com:saltstack/pop/gate.git
pip install -e gate -r requirements-test.txt
Run the tests with pytest
pytest gate/tests
INTEGRATION
In order to use gate in your own project add the gate config to your conf.py like so:
my_project/conf.py
CLI_CONFIG = {
# Gate options
"host": {"source": "gate"},
"port": {"source": "gate"},
"server": {"source": "gate"},
"matcher": {"source": "gate"},
"prefix": {"source": "gate"},
"refs": {"source": "gate", "default": ["gate.init.test"]},
}
Add gate startup code to your project’s initializer like so:
my_project/my_project/init.py
def __init__(hub):
# Horizontally merge the gate dynamic namespace into your project
hub.pop.sub.add(dyne_name="gate")
def cli(hub):
# Load the config from gate onto hub.OPT
hub.pop.config.load(["my_project", "gate"], cli="my_project")
# Create the asyncio loop
hub.pop.loop.create()
# Get the default gate server, and other options from hub.OPT.gate
gate_server = hub.OPT.gate.server
# Create the server coroutine
coro = hub.gate.init.start(gate_server=gate_server)
# Start the gate server
hub.pop.Loop.run_until_complete(coro)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pop-gate-5.tar.gz
.
File metadata
- Download URL: pop-gate-5.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/3.7.2 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11b8fecfdc82e4b2b48dff74100128f38b0e8a37f6643d493fe8d8c8f9a1f220 |
|
MD5 | e999e145049d6cd254015842572bd62a |
|
BLAKE2b-256 | cc153c2a353f83551a2cc4d2c892b7cc6470339fa982940b1c65a7604e0e63c7 |
File details
Details for the file pop_gate-5-py3-none-any.whl
.
File metadata
- Download URL: pop_gate-5-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/3.7.2 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a1328b599b3b4166765f75045cada8fc356d07bbc4e29858d32b1bec35e11b |
|
MD5 | 29f9f3053e4664e6988daf7ebf9aac06 |
|
BLAKE2b-256 | a6b3b17d27f3dcebae30c014fd3dc73c93da0bf269b3d897ffe45395cf5344d4 |