Skip to main content

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

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", "kwarg1": "value1", "kwarg2": "value2"}'

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 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

pop-gate-1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

pop_gate-1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pop-gate-1.1.tar.gz.

File metadata

  • Download URL: pop-gate-1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for pop-gate-1.1.tar.gz
Algorithm Hash digest
SHA256 890378b38dad14c8920d3167c89f43704c4aaf338183222ad7b5b0042d4e9ddd
MD5 4b44335c452ae243c71bcf8ad3622edb
BLAKE2b-256 c315746b29f6577be1943cab1d41e32755879ebb3d26f7a31d7e3c2d11c2f653

See more details on using hashes here.

File details

Details for the file pop_gate-1.1-py3-none-any.whl.

File metadata

  • Download URL: pop_gate-1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for pop_gate-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3bde1e0e48e68ba54643d804243572d243766fc767ed3c9ac0ea85229952161
MD5 6bb8794fc34e73cf70c3ba49299cd1b0
BLAKE2b-256 002bffe95e0194eadbba0a4fe344229deabc3d641eeafb05cf4dfbebb9a1ba9a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page