Skip to main content

SDK for interacting with Puppet Relay

Project description

This is the Python SDK for use with the internal Relay service APIs. The SDK requires Python 3.8.

It is intended for use by integration authors who are building containers to run inside the service. For running workflows and interacting with the user-facing service APIs, use the Relay CLI.

The API documentation is auto-generated from the source code. Here are some higher-level examples that show the main SDK classes that integration authors will interact with.

Installation

The SDK is available to install via pip:

pip install relay-sdk

If you use the relaysh/core:latest-python container image as your base image, it’ll be pre-installed.

Usage

The main purpose of the SDK is to provide helpers for interacting with Relay’s metadata service. Each container that runs in Relay has access to this service, which allows the container to read and write key-value data, emit events, and generate logs.

Accessing Data from the step spec

The Interface class is the primary way to interact with the service. Import it and instantiate an object, then call methods on that object to access metadata, which comes from the spec section of the step and global Connection information. The Dynamic class provides syntactic sugar for getting data like connection credentials, workflow-specific parameters, and secrets. It represents nested data structures as dot-separated method accessors.

from relay_sdk import Interface, Dynamic as D

relay = Interface()
azuresecret = relay.get(D.azure.connection.secret) # using Dynamic
azureclient = relay.get('azure["connection"]["clientID"]') # same as above
secret = relay.get(D.mysecret)
relay.outputs.set("outputkey","This will be the value of outputkey")

Webhook Triggers

The WebhookServer class provides a helper that sets up a webserver to handle incoming requests for Trigger actions.

This example, from the Docker Hub integration, makes use of the Interface class to access the events.emit method, which will cause the workflow associated with this trigger to be run with the inline mapping of workflow parameters to values extracted from the webhook payload.

The WebhookServer class can run any WSGI or ASGI application passed to it. The integrations the Relay team develops internally use the Quart web app framework.

from relay_sdk import Interface, WebhookServer
from quart import Quart, request, jsonify, make_response

relay = Interface()
app = Quart('image-pushed')

@app.route('/', methods=['POST'])
async def handler():
    event_payload = await request.get_json()

    if event_payload is None:
        return await make_response(jsonify(message='not a valid Docker Hub event'), 400)

    pd = event_payload['push_data']
    rd = event_payload['repository']

    relay.events.emit({
        'pushedAt': pd['pushed_at'],
        'pusher': pd['pusher'],
        'tag': pd['tag'],
        'name': rd['repo_name']
    })

    return await make_response(jsonify(message='success'), 200)


if __name__ == '__main__':
    WebhookServer(app).serve_forever()

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

relay-sdk-0.1.4.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relay_sdk-0.1.4-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file relay-sdk-0.1.4.tar.gz.

File metadata

  • Download URL: relay-sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.0

File hashes

Hashes for relay-sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ab39cb06b1ec44e5f57cd725ac17604161226b4ba8111b4fc15b630cacb621da
MD5 62e5c94e5ea33cfbb9566f8299b9ce3a
BLAKE2b-256 d51f53f5e2baf98cbd14fa7a362387ccee0ea94d8fc93f69f3ed547142c11f7a

See more details on using hashes here.

File details

Details for the file relay_sdk-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: relay_sdk-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.0

File hashes

Hashes for relay_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 964d199897c923aff1a7610748d37fd7572f5a60acac84f3250bfe4a27853e2f
MD5 93314fcb2189c5a0fb5cbb8d3334d10f
BLAKE2b-256 5689a69cb8a5554ac2dd856d35c993eed7b4134b7766413c4b32a0c4b83756db

See more details on using hashes here.

Supported by

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