Clone
14
Environment Variables
Corban-Lee Jones edited this page 2024-09-29 19:30:19 +00:00

Environment Variables

This wiki covers the environment variables used in this application, their purposes and what values you should use.

There are two ways you can pass parameters into the app using environment variables:

  1. Using a .env file (best for development)
  2. Setting them manually, usually via Docker (best for production)

Security

DEBUG

Optional / Default False

This flag is intended to be enabled for development purposes, and should always be disabled in a production environment.
Unless you intend to make use of debugging for development purposes, you should leave this alone.

Example value: True or False

SECRET_KEY

Optional / Default unsecure-default-secret-key

Your secret key should be secure, unique and unpredictable, it is advised that you create one using the following steps:

  1. launch the Django Shell using django-admin shell, which can be executed from the same environment where Django is installed.
  2. paste the following code, and hit 'enter' from django.core.management.utils import get_random_secret_key; get_random_secret_key(); exit();
  3. your new secret key will be output, surrounded by single quotes ', discard the surrounding quotes and you have your secret key!

Learn more here.

Example value: qc!dypv=k(wau%$-c943bk2!=7wbx!%5_4-ncssjyu((bwzs59

SUPERUSER_IDS

Optional / No Default

A comma separated list of Discord User IDs. Authenticated users with a matching Discord ID will be automatically made into superusers.
Superusers can access the Django administrator panel, so be careful!

Example value: 000000000000000001 or 000000000000000001,000000000000000002 (no spaces) for multiple users.

Discord App

This application works by communicating with the Discord API, to do this you will need a Discord Application.
You can follow this guide to create one fit for purpose.

Note

PYRSS is a two-part project, meaning you will also have to setup the PYRSS Bot to use it.
The same Discord Application should be used for both projects when deployed and/or during development.

Once created, you can gather the values for all of the following fields:

DISCORD_KEY

Required / No Default

The ID of your Discord Application, sometimes referred to as 'Client ID' or 'Application ID', it can be found under the 'General Information' tab when viewing your Discord Application.

Example value: 1129375994058336030

DISCORD_SECRET

Required / No Default

A secret key used by your Discord Application, you can find it under the 'OAuth2' tab when viewing your Discord Application. If you lose it, you can create a new one from the same place you found it, using the 'Reset Secret' button.

Example value: DFHjQNR5Rwd9tTmNNSvUrdBqAy34liL5 (This example is a randomly generated string, your value is sensitive so keep it secure)

DISCORD_SCOPES

Optional / Default identity,guilds

The scopes that the Discord Application holds over users who authenticate through it.
There is no real reason for you to change this value, and it is recommended that you leave it as is.

Example value identity,guilds (comma separated)

DISCORD_REDIRECT_URL

Required / No Default

Obtainable through the OAuth2 tab > Redirects, when viewing your Discord Application. You will need to create one if you haven't already.
It should match your HOST environment variable, but include the necessary protocol (http:// or https://), and include the path specified in the example.

Example value: https://pyrss.example.com/oauth2/login/redirect

DISCORD_OAUTH2_URL

Required / No Default

The URL used to authenticate a user with your Discord Application, you can construct this yourself with the following components:

  • Client ID (a previously covered environment variable)
  • Discord Scopes (a previously covered environment variable)
  • Redirect URI (a previously covered environment variable)

Important

For the purposes of this example value, you should replace the commas in the scopes with plus symbols (identity,guilds to identity+guilds).

Example value: https://discord.com/oauth2/authorize?client_id=<CLIENT ID>&response_type=code&redirect_uri=<REDIRECT URI>&scope=<SCOPES>

DISCORD_INVITE_URL

Required / No Default

The URL used to invite the Bot side of PYRSS to any given Discord server, it has a similar, yet different structure to the DISCORD_OAUTH2_URL environment variable. It requires:

  • Client ID (a previously covered environment variable)
  • Permissions Integer (A value that determines the bot's permissions within the server joined using this URL)

Note

The scope in this example URL should not be changed, as it is the only scope required for the function of this URL.
The permissions integer should need to change from the example, but there is a calculated for it on the Discord Developer Portal should you need to change it.

Example value: https://discord.com/oauth2/authorize?client_id=<CLIENT ID>&permissions=139586750528&scope=applications.commands+bot

DISCORD_API_URL

Required / Default https://discord.com/api/v10

The API endpoint for Discord.
This value shouldn't be changed unless you know what you are doing, as different API versions could handle/respond to requests differently.

Example value: https://discord.com/api/v9

BOT_TOKEN

Required / No Default

The authentication token for your Discord Bot.
This project requires access so that it can know what servers it's in, and what channels to list for subscriptions.

Example value: QfjXdruDsFVw.EuqV9jCZZgK9fo6vpGK.7MrTmk2xQuQqqKFupotri.Mu8nBHDtv9lvxVV (This example is a randomly generated string, your value is sensitive so keep it secure)

Database

https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DB_ENGINE

Optional / Default None

The database engine used by the application, view the list of supported engines to learn more.

Warning

Leaving this value as the default value (None) will cause other database related environment variables to be ignored, due to the default sqlite database being used instead.

Example value: django.db.backends.postgresql

DB_NAME

Optional / No Default

The name of your database

Example value: pyrss

DB_USER

Optional / No Default

Username for authenticating with your database

Example value pyrss

DB_PASS

Optional / No Default

Password for authenticating with your database, use a secure and unique value.

Example value: You should create one yourself

DB_HOST

Optional / No Default

The host endpoint for your database.

Example value: 192.168.0.50 or use docker container names if applicable.

DB_PORT

Optional / No Default

Port of the endpoint for the database.

Example value: 5432

Data Logic

These variables dictate important logic in the data side of the PYRSS application.

MAX_SUBSCRIPTIONS_PER_SERVER

Optional / Default 15

The maximum amount of subscriptions that can be created against any given server. This is not a database constraint, but rather is checked in the validation of API requests, meaning it can be bypassed with administrator access.

Example value: 10

MAX_FILTERS_PER_SERVER

Optional / Default 15

The maximum amount of content filters that can be created against any given server. This is not a database constraint, but rather is checked in the validation of API requests, meaning it can be bypassed with administrator access.

Example value: 10

MAX_MESSAGE_STYLES_PER_SERVER

Optional / Default 15

The maximum amount of message styles that can be created against any given server. This is not a database constraint, but rather is checked in the validation of API requests, meaning it can be bypassed with administrator access.

Example value: 10