-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/ Support for telemetry, loguru, refactored settings (#296)
* support for telemetry and logging * fixed incorrect middleware name * added docstrings and setup otel for loguru * sending logs to otel * init * django settings module variable set in post_fork * trace export error fixed * refactor: base settings * add: OTEL_RESOURCE_ATTRIBUTES env var * zango release workflow added (#301) * zango release workflow added * branch updated, workflow name corrected * version and changelog checks added * image link updated * feat: added frontend build generation workflow (#316) * autoincrement filter added * filter renamed * filter renamed * feat: added frontend build generation workflow * fix: api token added, LICENSE file removed --------- Co-authored-by: deepakdinesh1123 <[email protected]> Co-authored-by: Harsh Shah <[email protected]> * Deploy frontend build * add: contribution doc and fix use_latest template tag (#293) * add: contribution doc and fix use_latest template tag fix * chore: add doc_string for use_latest filter --------- Co-authored-by: Harsh Shah <[email protected]> * added version for dependencies (#320) * added version for dependencies * Update base.txt django-rest-knox version fixed * auditlogs now gets default timezone of host if timezone is not specified (#322) * auditlogs now gets default timezone of host if timezone is not specified * tzlocal removed * remove unused import --------- Co-authored-by: Harsh Shah <[email protected]> * support for telemetry and logging * otel resource attributes variable removed * python-dotenv removed * fix: shift handler and logger inside setup_setting for avoiding error on existing project --------- Co-authored-by: kc-diabeat <[email protected]> Co-authored-by: deepakdinesh1123 <[email protected]> Co-authored-by: Harsh Shah <[email protected]> Co-authored-by: deepakdinesh1123 <[email protected]> Co-authored-by: Ravi Patel <[email protected]> Co-authored-by: Harsh Shah <[email protected]>
- Loading branch information
1 parent
046b5b9
commit ad3428a
Showing
16 changed files
with
715 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 19 additions & 125 deletions
144
backend/src/zango/cli/project_template/project_name/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,45 @@ | ||
import os | ||
import environ | ||
from pathlib import Path | ||
from datetime import timedelta | ||
|
||
from zango.config.settings.base import * | ||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
env = environ.Env( | ||
DEBUG=(bool, True), | ||
REDIS_HOST=(str, "127.0.0.1"), | ||
REDIS_PORT=(str, "6379"), | ||
SESSION_SECURITY_WARN_AFTER=(int, 1700), | ||
SESSION_SECURITY_EXPIRE_AFTER=(int, 1800), | ||
INTERNAL_IPS=(list, []), | ||
ALLOWED_HOSTS=(list, ["*"]), | ||
CORS_ORIGIN_WHITELIST=(list, ["http://localhost:1443", "http://localhost:8000"]), | ||
CSRF_TRUSTED_ORIGINS=(list, ["http://localhost:1443", "http://localhost:8000"]), | ||
AXES_BEHIND_REVERSE_PROXY = (bool, False), | ||
AXES_FAILURE_LIMIT = (int, 6), | ||
AXES_LOCK_OUT_AT_FAILURE = (bool, True), | ||
AXES_COOLOFF_TIME = (int, 900), | ||
) | ||
environ.Env.read_env(os.path.join(BASE_DIR.parent, ".env")) | ||
|
||
SECRET_KEY = "{{secret_key}}" | ||
class AttrDict(dict): | ||
""" | ||
A dictionary subclass for managing global settings with attribute-style access. | ||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
This class allows getting and setting items in the global namespace | ||
using both attribute and item notation. | ||
""" | ||
|
||
ALLOWED_HOSTS = env("ALLOWED_HOSTS") | ||
def __getattr__(self, item): | ||
return globals()[item] | ||
|
||
PROJECT_NAME = env("PROJECT_NAME") | ||
def __setattr__(self, item, value): | ||
globals()[item] = value | ||
|
||
WSGI_APPLICATION = f"{PROJECT_NAME}.wsgi.application" | ||
def __setitem__(self, key, value): | ||
globals()[key] = value | ||
|
||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django_tenants.postgresql_backend", | ||
"NAME": env("POSTGRES_DB"), | ||
"USER": env("POSTGRES_USER"), | ||
"PASSWORD": env("POSTGRES_PASSWORD"), | ||
"HOST": env("POSTGRES_HOST"), | ||
"PORT": env("POSTGRES_PORT"), | ||
"ATOMIC_REQUESTS": True, | ||
} | ||
} | ||
# Call setup_settings to initialize the settings | ||
settings_result = setup_settings(AttrDict(vars()), BASE_DIR) | ||
|
||
REDIS_HOST = env("REDIS_HOST") | ||
REDIS_PORT = env("REDIS_PORT") | ||
REDIS_PROTOCOL = "redis" | ||
# Setting Overrides | ||
# Any settings that need to be overridden or added should be done below this line | ||
# to ensure they take effect after the initial setup | ||
|
||
REDIS_URL = f"{REDIS_PROTOCOL}://{REDIS_HOST}:{REDIS_PORT}/1" | ||
CELERY_BROKER_URL = REDIS_URL | ||
SECRET_KEY = "{{secret_key}}" # Shift this to .env | ||
|
||
CACHES = { | ||
"default": { | ||
"BACKEND": "django_redis.cache.RedisCache", | ||
"LOCATION": REDIS_URL, # Using DB 1 for cache | ||
"OPTIONS": { | ||
"CLIENT_CLASS": "django_redis.client.DefaultClient", | ||
}, | ||
"TIMEOUT": 300, # Default timeout is 5 minutes, but adjust as needed | ||
} | ||
} | ||
|
||
CORS_ORIGIN_ALLOW_ALL = True | ||
CORS_ALLOW_ALL_ORIGINS = True | ||
CORS_ALLOW_CREDENTIALS = True | ||
CORS_ORIGIN_WHITELIST = env( | ||
"CORS_ORIGIN_WHITELIST" | ||
) # Change according to domain configured | ||
CSRF_TRUSTED_ORIGINS = env( | ||
"CSRF_TRUSTED_ORIGINS" | ||
) # Change according to domain configured | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/4.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = "en-us" | ||
|
||
TIME_ZONE = "UTC" | ||
|
||
USE_I18N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# ROOT_URLCONF = '{{project_name}}.urls' | ||
|
||
import os | ||
|
||
TEMPLATES[0]["DIRS"] = [os.path.join(BASE_DIR, "templates")] | ||
|
||
SHOW_PUBLIC_IF_NO_TENANT_FOUND = False | ||
PUBLIC_SCHEMA_URLCONF = "zango.config.urls_public" | ||
ROOT_URLCONF = f"{PROJECT_NAME}.urls_tenants" | ||
|
||
ENV = "dev" | ||
|
||
PHONENUMBER_DEFAULT_REGION = "IN" | ||
|
||
MEDIA_URL = "/media/" | ||
MEDIA_ROOT = os.path.join(BASE_DIR, "media") | ||
|
||
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID" | ||
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY" | ||
AWS_S3_REGION_NAME = "AWS_S3_REGION_NAME" | ||
|
||
STORAGES = { | ||
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}, | ||
"staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}, | ||
} | ||
|
||
# To change the media storage to S3 you can use the BACKEND class provided by the default storage | ||
# To change the static storage to S3 you can use the BACKEND class provided by the staticfiles storage | ||
# STORAGES = { | ||
# "default": {"BACKEND": "zango.core.storage_utils.S3MediaStorage"}, | ||
# "staticfiles": {"BACKEND": "zango.core.storage_utils.S3StaticStorage"}, | ||
# } | ||
# | ||
AWS_MEDIA_STORAGE_BUCKET_NAME = "media" # S3 Bucket Name | ||
AWS_MEDIA_STORAGE_LOCATION = "media" # Prefix added to all the files uploaded | ||
AWS_STATIC_STORAGE_BUCKET_NAME = "static" # S3 Bucket Name | ||
AWS_STATIC_STORAGE_LOCATION = "static" # Prefix added to all the files uploaded | ||
|
||
STATIC_ROOT = os.path.join(BASE_DIR, "static") | ||
STATIC_URL = "static/" | ||
STATICFILES_DIRS += [os.path.join(BASE_DIR, "assets")] | ||
|
||
# Session Security | ||
SESSION_SECURITY_WARN_AFTER = env("SESSION_SECURITY_WARN_AFTER") | ||
SESSION_SECURITY_EXPIRE_AFTER = env("SESSION_SECURITY_EXPIRE_AFTER") | ||
|
||
if DEBUG or ENV == "dev": | ||
# Disable secure cookies in development or debugging environments | ||
# to simplify troubleshooting and testing. | ||
SESSION_COOKIE_SECURE = False | ||
CSRF_COOKIE_SECURE = False | ||
|
||
|
||
# INTERNAL_IPS can contain a list of IP addresses or CIDR blocks that are considered internal. | ||
# Both individual IP addresses and CIDR notation (e.g., '192.168.1.1' or '192.168.1.0/24') can be provided. | ||
INTERNAL_IPS = env("INTERNAL_IPS") | ||
|
||
|
||
AXES_BEHIND_REVERSE_PROXY = env("AXES_BEHIND_REVERSE_PROXY") | ||
AXES_FAILURE_LIMIT = env("AXES_FAILURE_LIMIT") | ||
AXES_LOCK_OUT_AT_FAILURE = env("AXES_LOCK_OUT_AT_FAILURE") | ||
AXES_COOLOFF_TIME = timedelta(seconds=env("AXES_COOLOFF_TIME")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.