Skip to main content

Identity-agnostic Django/DRF client for the NGITS IoT ESB automation & command APIs

Project description

ngits-drf-iot-client

Identity-agnostic Django/DRF client for the IoT ESB automation and command APIs. It lets any application (a single-tenant app, a multi-tenant panel, ...) act as a thin BFF over the shared IoT platform without duplicating domain logic — the same way ngits-drf-cube-proxy sits in front of analytics.

The automation domain (models, evaluation, command dispatch) lives in the IoT platform services. This package is only the transport + tenant-scoping glue used by the presentation layer.

Install

pip install ngits-drf-iot-client
# during local development, before it is published:
pip install -e ../ngits-drf-iot-client

Configure (host settings.py)

IOT_ESB_BASE_URL = "https://iot-esb.example.com"  # client appends /api/v1
IOT_ESB_TOKEN = env("IOT_ESB_TOKEN")              # sent as X-Token
IOT_CLIENT_IDENTITY_RESOLVER = "myapp.iot.resolve_scope"
# optional:
IOT_CLIENT_TIMEOUT = 10

The resolver maps an authenticated user to the tenant(s) they may access:

# myapp/iot.py  (single-tenant app)
def resolve_scope(user):
    tenant = get_tenant_for(user)                    # your own lookup
    return None if tenant is None else tenant.uuid   # None -> 403

# multi-tenant panel
def resolve_scope(user):
    return list(get_tenants_for(user))               # iterable of tenant UUIDs

Use in a DRF view

from rest_framework import viewsets
from rest_framework.response import Response
from iot_client import IotClientMixin

class AutomationViewSet(IotClientMixin, viewsets.ViewSet):
    def list(self, request):
        client = self.get_iot_client()
        return Response(client.list_automations(tenants=self.get_tenant_scope()))

    def create(self, request):
        client = self.get_iot_client()
        return Response(client.create_automation(request.data), status=201)

Client surface

IotEsbClient: list_automations, get_automation, create_automation, update_automation, delete_automation, activate_automation, deactivate_automation, list_rule_types, list_actions, create_command, get_command. All read methods accept a tenants scope; errors raise IotClientError(status_code=...).

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

ngits_drf_iot_client-0.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

ngits_drf_iot_client-0.2.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file ngits_drf_iot_client-0.2.0.tar.gz.

File metadata

  • Download URL: ngits_drf_iot_client-0.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ngits_drf_iot_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7bf3d4ca4ffe445c206e37b011cf104b1c2395b621675c09d4c801ff7180bdf1
MD5 2c2e72bc4a31c3faac568d6419601535
BLAKE2b-256 11e809003d4f725c92e7c0d29827587570a0a695155e9509eab233f1e65be54b

See more details on using hashes here.

File details

Details for the file ngits_drf_iot_client-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ngits_drf_iot_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0810745a1cf6f819dcbc61fb83d8ade91ef9330a87956a85a3ccd819f43135f4
MD5 21a597efd04066eb4ebca61b9ada1614
BLAKE2b-256 711b1c10f92e519dd87cc057c7fc7afa284b38975697ca5ebbbc672a570e893a

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