Skip to content

Commit

Permalink
Chore(docs): Update configuration docs and gitlab/github templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
onegreyonewhite committed Oct 1, 2024
1 parent dd3ebf6 commit 9c450a9
Show file tree
Hide file tree
Showing 8 changed files with 764 additions and 329 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: "ubuntu-22.04"
strategy:
matrix:
node: [ 18 ]
node: [ 20 ]

steps:
- name: Checkout the source code
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Set the node version
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: 'yarn'

- name: Set the python version
Expand Down
2 changes: 0 additions & 2 deletions .gitlab/merge_request_templates/Chore.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
### Changelog:
* What was done?

Parsed bundle size: 0.00 MB. (not changed)

Closes: group/project#issue
WIP: group/project#issue

Expand Down
2 changes: 0 additions & 2 deletions .gitlab/merge_request_templates/Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
### Changelog:
* What was done?

Parsed bundle size: 0.00 MB. (not changed)

Closes: group/project#issue
WIP: group/project#issue

Expand Down
2 changes: 0 additions & 2 deletions .gitlab/merge_request_templates/Feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
### Changelog:
* What was done?

Parsed bundle size: 0.00 MB. (not changed)

Closes: group/project#issue
WIP: group/project#issue

Expand Down
2 changes: 0 additions & 2 deletions .gitlab/merge_request_templates/Fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
### Changelog:
* What was done?

Parsed bundle size: 0.00 MB. (not changed)

Closes: group/project#issue
WIP: group/project#issue

Expand Down
185 changes: 168 additions & 17 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ In the example above authorization logic will be the following:
* **log_level** - Logging level. The verbosity level, configurable in Django and Celery, dictates the extent of log information,
with higher levels providing detailed debugging insights for development and lower levels streamlining
logs for production environments. Default: WARNING.
* **enable_django_logs** - Enable or disable Django logger to output.
Useful for debugging. Default: false.
* **enable_django_logs** - Enable or disable Django logger output.
Useful for debugging. When set to ``true``, logs generated by Django's internal operations will be included in the application logs.
This can be helpful during development or troubleshooting to get more detailed information about Django's internal processes.
Default: ``false``.
* **enable_admin_panel** - Enable or disable Django Admin panel. Default: false.
* **enable_registration** - Enable or disable user self-registration. Default: false.
* **enable_user_self_remove** - Enable or disable user self-removing. Default: false.
Expand All @@ -77,6 +79,23 @@ In the example above authorization logic will be the following:
The instance is serialized to a string using the :mod:`standard python module pickle <pickle>`
and then encrypted with :wiki:`Vigenère cipher <Vigenère cipher>`.
Read more in the :class:`vstutils.utils.SecurePickling` documentation. Default: false.
* **enable_user_self_remove** - Enable or disable the ability for users to delete their own accounts.
When set to ``true``, users will have the option to remove their own accounts from the system.
This feature should be enabled with caution, as it allows users to permanently delete their data. Default: ``false``.
* **auth-plugins** - Comma-separated list of Django authentication backends.
The authentication attempt is made until the first successful one in the order specified in the list.
Predefined options are:

- `DJANGO` - Uses `django.contrib.auth.backends.ModelBackend`, which authenticates users against the default Django user model.

- `LDAP` - Uses the LDAP authentication backend with parameters specified in `ldap-*` settings. This allows authentication against an LDAP directory.

You can also specify custom authentication backends by providing their import paths.
For example, if you have a custom backend at `myapp.auth.MyCustomBackend`, you can include it in the list like so:

.. sourcecode:: bash

auth-plugins = DJANGO,LDAP,myapp.auth.MyCustomBackend


.. _database:
Expand Down Expand Up @@ -165,6 +184,43 @@ Finally, add some options to MySQL/MariaDB configuration:
collation-server=utf8_unicode_ci


To simplify the configuration of database connections, you can use the ``DATABASE_URL`` environment variable in conjunction with the ``django-environ`` package.
This approach allows you to define your database connection in a single environment variable,
which is especially useful for managing different environments (development, testing, production) without changing the code.

**DATABASE_URL** - An environment variable that contains the database connection URL.
This variable is parsed by ``django-environ`` to configure the database settings. The format of the URL is:

.. sourcecode:: bash

backend://user:password@host:port/database_name


**Examples:**

- **PostgreSQL:**

.. sourcecode:: bash

DATABASE_URL=postgres://user:password@localhost:5432/mydatabase


- **MySQL:**

.. sourcecode:: bash

DATABASE_URL=mysql://user:password@localhost:3306/mydatabase


- **SQLite (file-based database):**

.. sourcecode:: bash

DATABASE_URL=sqlite:///path/to/mydatabase.sqlite3


Note the three slashes after ``sqlite:`` indicating an absolute file path.

.. _cache:

Cache settings
Expand All @@ -181,6 +237,62 @@ additional plugins. You can find details about cache configs supported
using client-server cache realizations.
We recommend to use Redis in production environments.

To simplify the configuration of cache backends, you can use the ``CACHE_URL`` environment variable in conjunction with the ``django-environ`` package.
This approach allows you to define your cache configuration in a single environment variable,
making it easy to switch between different cache backends without changing the code.

**CACHE_URL** - An environment variable that contains the cache backend connection URL.
This variable is parsed by django-environ to configure the cache settings in Django.
The format of the URL is:

.. sourcecode:: bash

backend://username:password@host:port


**Examples:**

- Memcached using MemcacheCache backend

.. sourcecode:: bash

CACHE_URL=memcache://127.0.0.1:11211

- Memcached using PyLibMCCache backend

.. sourcecode:: bash

CACHE_URL=pymemcache://127.0.0.1:11211

- Redis cache

.. sourcecode:: bash

CACHE_URL=redis://127.0.0.1:6379/1

- Database cache

.. sourcecode:: bash

CACHE_URL=dbcache://my_cache_table

- File-based cache

.. sourcecode:: bash

CACHE_URL=filecache:///var/tmp/django_cache

- Dummy cache (for development)

.. sourcecode:: bash

CACHE_URL=dummycache://


**LOCKS_CACHE_URL**, **SESSIONS_CACHE_URL**, **ETAG_CACHE_URL** - Environment variables for configuring specific cache backends for locks, session data, and ETag caching respectively.
These allow you to use different cache configurations for different purposes within your application.


Tarantool Cache Backend for Django
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -289,6 +401,16 @@ This section require vstutils with `rpc` extra dependency.
* **concurrency** - Count of celery worker threads. Default: 4.
* **heartbeat** - Interval between sending heartbeat packages, which says that connection still alive. Default: 10.
* **enable_worker** - Enable or disable worker with webserver. Default: true.
* **default_delivery_mode** - Sets the default delivery mode for Celery tasks.
This parameter determines whether messages are persisted to disk or kept in memory when sent to the broker.
Possible values are:

- ``persistent`` - Messages are stored on disk by the broker, ensuring they survive broker restarts. This is suitable for tasks that must not be lost.

- ``transient`` - Messages are kept in memory by the broker, which can improve performance but may result in message loss if the broker restarts.

Use this setting to balance between performance and reliability based on your application's needs. Default: ``persistent``.


The following variables from :celery_docs:`Django settings <userguide/configuration.html#new-lowercase-settings>`
are also supported (with the corresponding types):
Expand Down Expand Up @@ -365,6 +487,11 @@ Developers often switch between these backends based on the context of their wor
* **password** - Auth password for smtp-server connection. Default: ``""``.
* **tls** - Enable/disable tls for smtp-server connection. Default: ``False``.
* **send_confirmation** - Enable/disable confirmation message after registration. Default: ``False``.
* **ssl** - Enable or disable SSL for the SMTP server connection.
When set to ``True``, the connection to the SMTP server will be secured using SSL, typically on port 465.
Use this setting if your SMTP server requires an SSL connection for sending emails.
If both ``tls`` and ``ssl`` are set to ``True``, ``ssl`` will take precedence.
Default: ``False``.


.. _web:
Expand All @@ -374,13 +501,27 @@ Web settings

Section ``[web]``.

These settings are related to web-server. Those settings includes:
session_timeout, static_files_url and pagination limit.

* **allow_cors** - enable cross-origin resource sharing. Default: ``False``.
* **cors_allowed_origins**, **cors_allowed_origins_regexes**, **cors_expose_headers**, **cors_allow_methods**,
**cors_allow_headers**, **cors_preflight_max_age** - `Settings <https://github.com/adamchainz/django-cors-headers#configuration>`_
from ``django-cors-headers`` lib with their defaults.
These settings are related to the web server. They include configurations for session management, security headers, CORS (Cross-Origin Resource Sharing), and API behavior.

* **allow_cors** - Enable Cross-Origin Resource Sharing (CORS).
When set to ``true``, the application will accept requests from origins other than its own domain, which is necessary when the API is accessed from different domains.
This setting corresponds to enabling ``CORSMiddleware`` in FastAPI. Default: ``false``.
* **cors_allowed_origins** - A list of origins that are allowed to make cross-origin requests.
This corresponds to the ``allow_origins`` parameter in ``fastapi.middleware.cors.CORSMiddleware``.
Each origin should be a string representing a domain, e.g., ``https://example.com``.
Wildcards like ``*`` are accepted to allow all origins. Default: ``*`` if ``allow_cors`` is set or empty list set.
* **cors_allow_methods** - A list of HTTP methods that are allowed when making cross-origin requests.
This corresponds to the ``allow_methods`` parameter in ``CORSMiddleware``.
By specifying this, you control which HTTP methods are permitted for CORS requests to your application.
Common methods include ``GET``, ``POST``, ``PUT``, ``PATCH``, ``DELETE``, and ``OPTIONS``.
Default: ``GET`` if ``allow_cors`` is not set. Else - ``GET``.
* **cors_allow_headers** - A list of HTTP headers that are allowed when making cross-origin requests.
This corresponds to the ``allow_headers`` parameter in ``CORSMiddleware``.
Use this setting to specify which HTTP headers are allowed in CORS requests.
Common headers include ``Content-Type``, ``Authorization``, etc.
Default: ``*`` if ``allow_cors`` is set or empty list set.
* **cors_allowed_credentials** - Indicate that cookies and authorization headers should be supported for cross-origin requests.
Default: ``true`` if allow_cors else ``false``.
* **enable_gravatar** - Enable/disable gravatar service using for users. Default: ``True``.
* **rest_swagger_description** - Help string in Swagger schema. Useful for dev-integrations.
* **openapi_cache_timeout** - Cache timeout for storing schema data. Default: ``120``.
Expand All @@ -390,11 +531,19 @@ session_timeout, static_files_url and pagination limit.
* **etag_default_timeout** - Cache timeout for Etag headers to control models caching. Default: ``1d`` (one day).
* **rest_page_limit** and **page_limit** - Default limit of objects in API list. Default: ``1000``.
* **session_cookie_domain** - The domain to use for session cookies.
This setting defines the domain attribute of the session cookie, which determines which domains the cookie is sent to.
By setting this, you can allow the session cookie to be shared across subdomains.
Read :django_docs:`more <settings/#std:setting-SESSION_COOKIE_DOMAIN>`. Default: ``None``.
* **csrf_trusted_origins** - A list of hosts which are trusted origins for unsafe requests.
* **csrf_trusted_origins** - A list of trusted origins for Cross-Site Request Forgery (CSRF) protection.
This setting specifies a list of hosts that are trusted when performing cross-origin POST/PUT/PATCH requests that require CSRF protection.
This is necessary when your application needs to accept POST/PUT/PATCH requests from other domains.
Read :django_docs:`more <settings/#csrf-trusted-origins>`. Default: from **session_cookie_domain**.
* **case_sensitive_api_filter** - Enables/disables case sensitive search for name filtering.
Default: ``True``.
* **case_sensitive_api_filter** - Enable or disable case-sensitive search for name filtering in the API.
When set to ``true``, filters applied to fields such as ``name`` will be case-sensitive,
meaning that the search will distinguish between uppercase and lowercase letters.
When set to ``false``, the search will be case-insensitive.
Adjust this setting based on whether you want users to have case-sensitive searches.
Default: ``true``.
* **secure_proxy_ssl_header_name** - Header name which activates SSL urls in responses.
Read :django_docs:`more <settings/#secure-proxy-ssl-header>`. Default: ``HTTP_X_FORWARDED_PROTOCOL``.
* **secure_proxy_ssl_header_value** - Header value which activates SSL urls in responses.
Expand All @@ -416,10 +565,12 @@ The following variables from Django settings are also supported (with the corres

The following settings affects prometheus metrics endpoint (which can be used for monitoring application):

* **metrics_throttle_rate** - Count of requests to ``/api/metrics/`` endpoint. Default: ``120``.
* **metrics_throttle_rate** - Count of requests to ``/api/metrics/`` endpoint per minute. Default: ``120``.
* **enable_metrics** - Enable/disable ``/api/metrics/`` endpoint for app. Default: ``true``
* **metrics_backend** - Python class path with metrics collector backend. Default: ``vstutils.api.metrics.DefaultBackend``
Default backend collects metrics from uwsgi workers and python version info.
* **metrics_backend** - The Python class path of the metrics collector backend.
This class is responsible for collecting and providing metrics data for your application.
By default, it uses ``vstutils.api.metrics.DefaultBackend``, which collects basic metrics like worker status and Python version information.
You can specify a custom backend by providing the import path to your own class. Default: ``vstutils.api.metrics.DefaultBackend``.


Section ``[uvicorn]``.
Expand Down Expand Up @@ -854,7 +1005,7 @@ This section contains additional information for configure additional elements.
#. If you need set ``https`` for your web settings, you can do it using HAProxy, Nginx, Traefik
or configure it in ``settings.ini``.

.. sourcecode:: ini
.. sourcecode:: ini

[uwsgi]
addrport = 0.0.0.0:8443
Expand All @@ -865,7 +1016,7 @@ This section contains additional information for configure additional elements.

#. We strictly do not recommend running the web server from root. Use HTTP proxy to run on privileged ports.

#. You can use `{ENV[HOME:-value]}` (where `HOME` is environment variable, `value` is default value)
#. You can use ``{ENV[HOME:-value]}`` (where ``HOME`` is environment variable, ``value`` is default value)
in configuration values.

#. You can use environment variables for setup important settings. But config variables has more priority then env.
Expand Down
Loading

0 comments on commit 9c450a9

Please sign in to comment.