Skip to main content

Utilities for DBCA Django apps

Project description

Overview

DBCA Django utility classes and functions.

Requirements

  • Python 3.12 or later
  • Django 5.2 or later

Development

Dependencies for this project are managed using uv. With uv installed, change into the project directory and run:

uv sync

Activate the virtualenv like so:

source .venv/bin/activate

Run unit tests using pytest (or tox, to test against multiple Python versions):

pytest -sv
tox -v

Releases

Tagged releases are built and pushed to PyPI automatically using a GitHub workflow in the project. Update the project version in pyproject.toml and tag the required commit with the same value to trigger a release. Packages can also be built and uploaded manually to PyPI using uv, if required:

uv build
uv publish

Installation

  1. Install via uv/pip/etc.: pip install dbca-utils

SSO Login Middleware

This will automatically login and create users using headers from an upstream proxy (REMOTE_USER and some others). The logout view will redirect to a separate logout page which clears the SSO session.

Usage

Add dbca_utils.middleware.SSOLoginMiddleware to settings.MIDDLEWARE (after both of django.contrib.sessions.middleware.SessionMiddleware and django.contrib.auth.middleware.AuthenticationMiddleware. Ensure that AUTHENTICATION_BACKENDS contains django.contrib.auth.backends.ModelBackend, as this middleware depends on it for retrieving the logged in user for a session. Note that the middleware will still work without it, but will reauthenticate the session on every request, and request.user.is_authenticated won't work properly/will be false.

Example:

MIDDLEWARE = [
    ...,
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'dbca_utils.middleware.SSOLoginMiddleware'
    ...,
]

Audit model mixin

AuditMixin is an extension of Django.db.model.Model that adds a number of additional fields:

  • creator - FK to AUTH_USER_MODEL, used to record the object creator
  • modifier - FK to AUTH_USER_MODEL, used to record who the object was last modified by
  • created - a timestamp that is set on initial object save
  • modified - an auto-updating timestamp (on each object save)

Healthcheck feature

Requirements

  • Django 5.2 or later
  • Declared the default cache and also the cache is shared by all pod instances
  • The image has the command 'ps' which is used to collect the cpu and memory data

Usage

  • Install the app 'dbca_utils' in INSTALLED_APPS
  • Service Configuration
    • HEALTHCHECK_ENABLED: Optional. enable/disable the healthcheck service. default is 'true'
    • PROCESS_FILTER: Optional. find the web app related processes from command 'ps aux'. default is '| grep python'
    • CACHE_PREFIX: Optional. used as the prefix of the cache key. default is ''
    • PORT: Optional. The listening port of the web application. default is '8080'
    • WORKLOADS: Optional. Used if the web app has a fixed replicas.
    • WORKLOAD_DEPLOYMENT: Optional. the workload is deployment if it is true; otherwise it is statefulset. default is 'true'
    • WORKLOAD_FAILED_THRESHOLD: Optional. The number of continuous failed times to treat a pod is offline.
  • Nginx Configuration.
    • Add a location 'location /healthcheck/' and configure it to use basic auth in nginx.
  • Access the url : https://xxx.dbca.wa.gov.au/healthcheck/healthdata to get the health json data

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

dbca_utils-3.0.4.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbca_utils-3.0.4-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file dbca_utils-3.0.4.tar.gz.

File metadata

  • Download URL: dbca_utils-3.0.4.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dbca_utils-3.0.4.tar.gz
Algorithm Hash digest
SHA256 087d6f9dd50e5d30fd052edd51d5df475944f0c106f4f3993b86fd999fdaff76
MD5 8c5318f21ecb034882018e892be6f205
BLAKE2b-256 f3565c798a75494f2aca94b7255ec531ed9706992d88c4009d94cb55aab89c21

See more details on using hashes here.

File details

Details for the file dbca_utils-3.0.4-py3-none-any.whl.

File metadata

  • Download URL: dbca_utils-3.0.4-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dbca_utils-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 36388e48494afa0442f4ece6c1b9b1d1a2b7d972030b53da0cb6d529772edeff
MD5 2be0ce88587d7bad618c4312b34b92ea
BLAKE2b-256 99c5127f7b71be569e2b572a700a21905be4272f146a1e16ba36cf6cd68ca843

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