# Django Nats NKEYS
[![image](https://img.shields.io/pypi/v/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/pyversions/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/djversions/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/wheel/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/discord/773452324692688956)](https://discord.gg/Y848Hq9xKh) [![image](https://img.shields.io/github/workflow/status/bitsy-ai/django-nats-nkeys/Test)](https://github.com/bitsy-ai/django-nats-nkeys) [![image](https://img.shields.io/codecov/c/github/bitsy-ai/django-nats-nkeys)](https://github.com/bitsy-ai/django-nats-nkeys) [![image](https://img.shields.io/github/release-date-pre/bitsy-ai/django-nats-nkeys)](https://github.com/bitsy-ai/django-nats-nkeys)
[NATS](https://docs.nats.io/nats-concepts/what-is-nats) is an
infrastructure platform for building message-based services.
This Django app integrates [NAT's multi-tenant account paradigm](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts) with [Django Organizations](https://github.com/bennylope/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
* Based on [Django organizations](https://github.com/bennylope/django-organizations)
* An `Organization` represents an `account` in [NATS multi-tenant account model](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts)
* An `App` represents a `user` in [NATS multi-tenant account model](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts)
`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" ]`)
Raw data
{
"_id": null,
"home_page": "http://github.com/bitsy-ai/django-nats-nkey",
"name": "django-nats-nkeys",
"maintainer": "",
"docs_url": null,
"requires_python": ">3.6.9",
"maintainer_email": "",
"keywords": "django NATS",
"author": "Leigh Johnson",
"author_email": "leigh@bitsy.ai",
"download_url": "https://files.pythonhosted.org/packages/19/27/c21e25564020fdfc1efd69b02c372d2fbabdb5de589e465fca3dde075a0e/django_nats_nkeys-0.10.1.tar.gz",
"platform": null,
"description": "# Django Nats NKEYS\n\n[![image](https://img.shields.io/pypi/v/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/pyversions/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/djversions/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/pypi/wheel/django-nats-nkeys)](https://pypi.org/project/django-nats-nkeys/) [![image](https://img.shields.io/discord/773452324692688956)](https://discord.gg/Y848Hq9xKh) [![image](https://img.shields.io/github/workflow/status/bitsy-ai/django-nats-nkeys/Test)](https://github.com/bitsy-ai/django-nats-nkeys) [![image](https://img.shields.io/codecov/c/github/bitsy-ai/django-nats-nkeys)](https://github.com/bitsy-ai/django-nats-nkeys) [![image](https://img.shields.io/github/release-date-pre/bitsy-ai/django-nats-nkeys)](https://github.com/bitsy-ai/django-nats-nkeys)\n\n[NATS](https://docs.nats.io/nats-concepts/what-is-nats) is an\ninfrastructure platform for building message-based services.\n\nThis Django app integrates [NAT's multi-tenant account paradigm](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts) with [Django Organizations](https://github.com/bennylope/django-organizations).\n\nThe NATS `nsc` tool is used to manage operator, account, and user JWTs.\n\n\nQuick start\n===========\n\n\n1. `pip install django-nats-nkeys[drf]` \n\n2. Add to your INSTALLED\\_APPS settings:\n\n INSTALLED_APPS = [\n ...\n \"organizations\",\n \"django_extensions\",\n \"django_nats_nkey\",\n ]\n\n3. Run `python manage.py migrate` to create the NATS organizationals\n models\n\n4. Run `python manage.py nsc-init` (optional) Initialize a new NATS\n operator. You are responsible for copying the generated\n `.conf` file to your NATS server. If you choose to use\n an existing operator, you are responsible for running `nsc pull` as a pre-deployment step.\n\nContributor's Guide\n====================\n\n1. Create a development environment (requires docker & docker-compose):\n\n make docker-up\n make nsc-init\n\n2. Run tests and generate a coverage report:\n\n make pytest\n\n3. Run `black` linter:\n\n make lint\n\n\nSettings\n===========\n\n### Basic Settings\n`NATS_NSC_DATA_DIR` (default: `\"/var/lib/nats/nsc/stores\"` or `$NSC_STORE` environment var)\n`NATS_NSC_CONFIG_DIR`(default: `\"/var/lib/nats/nsc/config\"` or `$NSC_HOME` environment var)\n`NATS_NSC_KEYSTORE_DIR` (default: `\"/var/lib/nats/nsc/keys\"` or `$NKEYS_PATH` environment var)\n`NATS_SERVER_URI` (default: `\"nats://nats:4222\"`)\n`NATS_NKEYS_IMPORT_DIR` (default: `\".nats/\"`, )\n`NATS_NKEYS_EXPORT_DIR` (default: `\".nats/\"`)\n`NATS_NKEYS_OPERATOR_NAME` (default: `\"DjangoOperator\"`)\n\n### Retry Mode\n\n`NATS_NSC_RETRY_MODE` (default \"STRICT\", allowed values: \"STRICT\" or \"IDEMPOTENT\")\n\nIn `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.\n\nIn `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.\n\n\n### Organization Models\n* Based on [Django organizations](https://github.com/bennylope/django-organizations)\n* An `Organization` represents an `account` in [NATS multi-tenant account model](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts)\n* An `App` represents a `user` in [NATS multi-tenant account model](https://docs.nats.io/running-a-nats-service/configuration/securing_nats/accounts)\n \n\n`NATS_ORGANIZATION_MODEL` (default: `\"django_nats_nkeys.NatsOrganization\"`)\n* Must subclass `django_nats_nkeys.models.NatsOrganization`\n\n`NATS_ORGANIZATION_OWNER_MODEL` (default: `\"django_nats_nkeys.NatsOrganizationOwner\"`)\n* Must subclass `django_nats_nkey.models.NatsOrganizationOwner`\n\n`NATS_ORGANIZATION_APP_MODEL` (default: `\"django_nats_nkey.NatsOrganizationApp\"`)\n* Must subclass `django_nats_nkey.models.AbstractNatsApp`\n\n`NATS_ORGANIZATION_USER_MODEL` (default: `\"django_nats_nkeys.models.NatsOrganizationUser\"`)\n* Must subclass `django_nats_nkeys.models.NatsOrganizationUser`\n\n\n### Robot/Automation Models\n\n`NATS_ROBOT_APP_MODEL` (default: `\"django_nats_nkeys.NatsRobotApp\"`)\n\n`NATS_ROBOT_ACCOUNT_MODEL` (default: `\"django_nats_nkeys.NatsRobotAccount\"`)\n\n\n### App Models\n\n`NATS_APP_MODELS` (default: `[ \"django_nats_nkey.NatsOrganizationApp\" , \"django_nats_nkeys.NatsRobotApp\" ]`)\n\n",
"bugtrack_url": null,
"license": "GNU AGPLv3",
"summary": "Django NATS Nkey is a Django app to synchronize Django superusers, accounts, and users with NATS nkey-based authentization/authorization scheme",
"version": "0.10.1",
"split_keywords": [
"django",
"nats"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1aefee72720ec35747ae3301b6dff0831e71f6b45f43cca6359cfe7bddf26d88",
"md5": "48df370a3f45a0f75d26712c171a26f5",
"sha256": "3be83a6d6afed91685d338c1a1e6abb57d3ec681d8c7b7c4ada288f78ec9bf89"
},
"downloads": -1,
"filename": "django_nats_nkeys-0.10.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "48df370a3f45a0f75d26712c171a26f5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">3.6.9",
"size": 822588,
"upload_time": "2023-03-28T00:36:33",
"upload_time_iso_8601": "2023-03-28T00:36:33.500441Z",
"url": "https://files.pythonhosted.org/packages/1a/ef/ee72720ec35747ae3301b6dff0831e71f6b45f43cca6359cfe7bddf26d88/django_nats_nkeys-0.10.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1927c21e25564020fdfc1efd69b02c372d2fbabdb5de589e465fca3dde075a0e",
"md5": "829617a753c15ed022c8fffd2dcc0b2a",
"sha256": "7b4185b883556c71657b35fb718a4c12278aa308620188f4778743d3bdcfef75"
},
"downloads": -1,
"filename": "django_nats_nkeys-0.10.1.tar.gz",
"has_sig": false,
"md5_digest": "829617a753c15ed022c8fffd2dcc0b2a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.6.9",
"size": 28026,
"upload_time": "2023-03-28T00:36:36",
"upload_time_iso_8601": "2023-03-28T00:36:36.525822Z",
"url": "https://files.pythonhosted.org/packages/19/27/c21e25564020fdfc1efd69b02c372d2fbabdb5de589e465fca3dde075a0e/django_nats_nkeys-0.10.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-28 00:36:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "bitsy-ai",
"github_project": "django-nats-nkey",
"lcname": "django-nats-nkeys"
}