Skip to main content

Django GCP IoT Device Manager

https://img.shields.io/pypi/v/dj_gcp_iotdevice.svg Gitlab pipeline status Documentation Status

Provides a CRDL (Create, Retrieve, Destroy, List) interface to GCP IoT Core

Getting Started

If you are not familiar with GCP IoT Core then please first read the following:

First create an IoT device registry and then make sure that the service account assigned to your service (VM, Cloud Run, App Engine) has enough GCP permissions to create/read/delete/list from GCP IoT Core.

Installation

Install dj_gcp_iotdevice from pip

$ pip install dj_gcp_iotdevice

Add to your top level apps.py

from dj_gcp_iotdevice.apps import GCPIoTDeviceConfig

class MyProjectDeviceConfig(GCPIoTDeviceConfig):
    registry = 'my-iot-registry'
    location = 'us-central1'
    project = 'my-project-id'

Add the new app config to your installed apps

INSTALLED_APPS = [
    ...
    'apps.MyProjectDeviceConfig',
]

Add the provided urls to your list of urls

urlpatterns = [
    ...
    path('', include('dj_gcp_iotdevice.urls')),
]

Run the migrate command to create the new permissions that you can protect the API with

python manage.py migrate

API

The following endpoints will be accessible

POST /devices/
GET /devices/{id}
DELETE /devices/{id}
GET /devices/

To create a new device you will need to generate a private/public keypair using the following commands

openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem

Take the contents of the rsa_public.pem and use that for the public_key in the API. Make sure to use \n characters for the line feeds.

The following snippet is the openapi spec for the new devices api

/devices/:
    get:
        operationId: devices_list
        summary: Used to list all the devices in the registry.
        description: |-
            :raises PermissionDenied: Likely bad coordinates to registry or not enough permissions
                                    to list devices from registry.
        parameters: []
        responses:
            '200':
            description: ''
            schema:
                type: array
                items:
                $ref: '#/definitions/Device'
        tags:
            - devices
    post:
        operationId: devices_create
        summary: Used to add a new IoT device to the registry.
        description: |-
            :raises ParseError: Bad data provided.  Likely a bad public key.
            :raises NotAcceptable: Could not add device.  Probably device Id already exists.
            :raises PermissionDenied: Likely wrong GCP coordinates or insufficient permissions
                                    on GCP to add devices to the registry.
        parameters:
            - name: data
            in: body
            required: true
            schema:
                $ref: '#/definitions/Device'
        responses:
            '201':
            description: ''
            schema:
                $ref: '#/definitions/Device'
        tags:
            - devices
        parameters: []
/devices/{id}/:
    get:
        operationId: devices_read
        summary: Used to get one device from the registry.
        description: |-
            :raises PermissionDenied: Likely bad coordinates to registry or not enough
                                    permissions to read devices from registry.
            :raises NotFound: Device does not exist.
        parameters: []
        responses:
            '200':
            description: ''
            schema:
                $ref: '#/definitions/Device'
        tags:
            - devices
    delete:
        operationId: devices_delete
        summary: Used to remove a device from the registry.
        description: |-
            :raises PermissionDenied: Likely bad coordinates to registry or not enough
                                    permissions to remove devices from the registry.
            :raises NotFound: Device does not exist.
        parameters: []
        responses:
            '204':
            description: ''
        tags:
            - devices
        parameters:
        - name: id
            in: path
            required: true
            type: string

Permissions

Modifying the IoT device registry is not something you want everyone to be able to do so this app also adds model permissions you can assign to groups or to individual users that can limit what the user is able to do.

In the Admin page under dj_gcp_iotdevice there are 4 permissions: can add, can change, can delete, and can view. Use these to control what parts of the CRDL a user or group can access.

Metadata

Release files for dj-gcp-iotdevice 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-gcp-iotdevice 0.3.1
File Size Uploaded Provenance Actions
dj_gcp_iotdevice-0.3.1.tar.gz 7.1 kB Without provenance Details for dj_gcp_iotdevice-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dj-gcp-iotdevice 0.3.1
File Interpreter ABI Platform Actions
dj_gcp_iotdevice-0.3.1-py3-none-any.whl Python 3 none any Details for dj_gcp_iotdevice-0.3.1-py3-none-any.whl

Total release size: 15.0 kB

Release files / dj_gcp_iotdevice-0.3.1.tar.gz

Download URL dj_gcp_iotdevice-0.3.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
83629dd9df0e22f4f037718234342e115641efbe78bb27ed7fde7d3ffe22ab92
BLAKE2b-256 checksum
How to use checksums
2a89eb4689bafebaf1ba197fd4dd11920c4f27c1b010c83f93fc0c9a91aacfdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

Release files / dj_gcp_iotdevice-0.3.1-py3-none-any.whl

Download URL dj_gcp_iotdevice-0.3.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f55d5104d9f8d432a951ec42570b115cc6295f93093a5aea96d3408b1bb1683
BLAKE2b-256 checksum
How to use checksums
5be5166b5c5bdc45a3913603bcd339f7097816ac539dd52e2d4f7f643fad57d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

Security for dj-gcp-iotdevice 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page