Skip to main content

Django NATS Nkey is a Django app to synchronize Django superusers, accounts, and users with NATS nkey-based authentization/authorization scheme

Project description

Django Nats NKEYS

image image image image image image image image

NATS is an infrastructure platform for building message-based services.

This Django app integrates NAT's multi-tenant account paradigm with Django Organizations.

The NATS nsc tool is used to manage operator, account, and user JWTs.

Quick start

  1. pip install django-nats-nkeys[drf]

  2. Add to your INSTALLED_APPS settings:

    INSTALLED_APPS = [
        ...
        "organizations",
        "django_extensions",
        "django_nats_nkey",
    ]
    
  3. Run python manage.py migrate to create the NATS organizationals models

  4. Run python manage.py nsc-init (optional) Initialize a new NATS operator. You are responsible for copying the generated .conf file to your NATS server. If you choose to use an existing operator, you are responsible for running nsc pull as a pre-deployment step.

Contributor's Guide

  1. Create a development environment (requires docker & docker-compose):

    make docker-up
    make nsc-init
    
  2. Run tests and generate a coverage report:

    make pytest
    
  3. Run black linter:

    make lint
    

Settings

Basic Settings

NATS_NSC_DATA_DIR (default: "/var/lib/nats/nsc/stores" or $NSC_STORE environment var) NATS_NSC_CONFIG_DIR(default: "/var/lib/nats/nsc/config" or $NSC_HOME environment var) NATS_NSC_KEYSTORE_DIR (default: "/var/lib/nats/nsc/keys" or $NKEYS_PATH environment var) NATS_SERVER_URI (default: "nats://nats:4222") NATS_NKEYS_IMPORT_DIR (default: ".nats/", ) NATS_NKEYS_EXPORT_DIR (default: ".nats/") NATS_NKEYS_OPERATOR_NAME (default: "DjangoOperator")

Retry Mode

NATS_NSC_RETRY_MODE (default "STRICT", allowed values: "STRICT" or "IDEMPOTENT")

In STRICT mode, django_nats_nkey.errors.NscConflict will be raised if nsc add ... command returns an "already exists" error. You are responsible for implementing a separate process to handle eventual consistency between Django models and nsc environment.

In IDEMPOTENT mode, conflict is logged at the WARNING level but no Exception is raised. In this mode, nsc add command may be retried many times and will be a no-op if resource already exists.

Organization Models

NATS_ORGANIZATION_MODEL (default: "django_nats_nkeys.NatsOrganization")

  • Must subclass django_nats_nkeys.models.NatsOrganization

NATS_ORGANIZATION_OWNER_MODEL (default: "django_nats_nkeys.NatsOrganizationOwner")

  • Must subclass django_nats_nkey.models.NatsOrganizationOwner

NATS_ORGANIZATION_APP_MODEL (default: "django_nats_nkey.NatsOrganizationApp")

  • Must subclass django_nats_nkey.models.AbstractNatsApp

NATS_ORGANIZATION_USER_MODEL (default: "django_nats_nkeys.models.NatsOrganizationUser")

  • Must subclass django_nats_nkeys.models.NatsOrganizationUser

Robot/Automation Models

NATS_ROBOT_APP_MODEL (default: "django_nats_nkeys.NatsRobotApp")

NATS_ROBOT_ACCOUNT_MODEL (default: "django_nats_nkeys.NatsRobotAccount")

App Models

NATS_APP_MODELS (default: [ "django_nats_nkey.NatsOrganizationApp" , "django_nats_nkeys.NatsRobotApp" ])

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

django_nats_nkeys-0.9.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

django_nats_nkeys-0.9.0-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file django_nats_nkeys-0.9.0.tar.gz.

File metadata

  • Download URL: django_nats_nkeys-0.9.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.10.6

File hashes

Hashes for django_nats_nkeys-0.9.0.tar.gz
Algorithm Hash digest
SHA256 a0bc75a4e6f104e52c1ea52cf343f02c2541cccb083c47fba3fa345731876ff1
MD5 a2d9afe16d2ce1da5f852f871e847ca5
BLAKE2b-256 d4a9658323886c05357ff0755fc1f60d1119099fece4a6553ee108d45381854c

See more details on using hashes here.

File details

Details for the file django_nats_nkeys-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: django_nats_nkeys-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.10.6

File hashes

Hashes for django_nats_nkeys-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf11cb8cb4f5cfe087450436b613c358a4f0302ed6419e0561f1f6a4fb37006
MD5 640de36d13b2d7bd7621320d01e22af8
BLAKE2b-256 cff1494c2744622b89ffd9635d06f0242cf708d2ab5fe6766bc1fd0e7aacb098

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page