Metadata-Version: 2.4
Name: ngits-drf-iot-client
Version: 0.1.0
Summary: Identity-agnostic Django/DRF client for the NGITS IoT ESB automation & command APIs
Author-email: "NG IT Services Sp. z o.o." <biuro@ngits.pl>
License: BSD-3-Clause
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: Django>=4.2
Requires-Dist: djangorestframework>=3.14
Requires-Dist: requests>=2.31
Provides-Extra: schemas
Requires-Dist: drf-spectacular>=0.27; extra == "schemas"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=24.0.0; extra == "dev"
Requires-Dist: isort>=5.13.0; extra == "dev"
Requires-Dist: drf-spectacular>=0.27; extra == "dev"

# 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

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

## Configure (host `settings.py`)

```python
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:

```python
# 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

```python
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=...)`.
