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.3.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.3.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ngits_drf_iot_client-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 63efad60c2794e410b087bfac8e0768c407082b9eb32475c984646104f2eb7c1
MD5 d9692853af924a8856524476e011c7dd
BLAKE2b-256 18b63bd81febb11b7cae72c126ff92d67193c37bb8886d31946e99262dd71f10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ngits_drf_iot_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27d266fd9c7f909b13d6617f75f9a19cd30318e8794dc9bc8889b44e9794fd2a
MD5 3a5f143537940ee4f13aa9ae989ec447
BLAKE2b-256 0b374f2dcecb646bee364c320f535a678f35a57c0eee2527ff241da02fe056d2

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