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.4.0.tar.gz (13.9 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.4.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ngits_drf_iot_client-0.4.0.tar.gz
  • Upload date:
  • Size: 13.9 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.4.0.tar.gz
Algorithm Hash digest
SHA256 5414ff180e2ed305e7ca7a9b79c542aae0233dbdbdf59acb6aa13047041fb3be
MD5 57d6a219cdd0b9d93fe2be30c2587d87
BLAKE2b-256 c9e99e5e77571444f3d49f60dc925e1b87f6eec626acb2edac11ce1b53a2920a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ngits_drf_iot_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4fbcb30e528a4ae81cacc8f318b7dac7fdcdb9f5287b7c679e8685581ef59c0
MD5 975dece5ce25bb8c0f5c42d276ec5b92
BLAKE2b-256 67648715aafcf6dece4304de5ed1a0b36328f304fe0f3fa310a0e7f420911ed2

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