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.1.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.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ngits_drf_iot_client-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 5d3c5044694aeb620e163c904ca8e4bab267e4fd98e838226c021dee631f74d7
MD5 8f94da6c643b1bebecc240352df2df9a
BLAKE2b-256 7d38ca80c0a6bca454e801abfe75a16858df931ce0ef0482d5ab2cec092aed06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ngits_drf_iot_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3af7c6f70c9a13b65708177b6f93cd5f983212758325e0b1866968ed53681f3a
MD5 b25d5c62ecf1acb0a3754ae7d4ce9b84
BLAKE2b-256 03e6a2b46b2f7a33e99b47f5f8a4f88fed4ac13a164ddb3ee074cceb0ec192db

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