pulumi-django-azure 1.0.28__py3-none-any.whl → 1.0.59__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pulumi_django_azure/__init__.py +0 -2
- pulumi_django_azure/azure_helper.py +34 -40
- pulumi_django_azure/context_processors.py +42 -0
- pulumi_django_azure/django_deployment.py +153 -244
- pulumi_django_azure/management/commands/fix_cache_control.py +119 -0
- pulumi_django_azure/management/commands/purge_cache.py +10 -2
- pulumi_django_azure/management/commands/purge_cdn.py +10 -4
- pulumi_django_azure/management/commands/test_redis.py +248 -0
- pulumi_django_azure/middleware.py +26 -41
- pulumi_django_azure/settings.py +62 -34
- {pulumi_django_azure-1.0.28.dist-info → pulumi_django_azure-1.0.59.dist-info}/METADATA +251 -278
- pulumi_django_azure-1.0.59.dist-info/RECORD +14 -0
- {pulumi_django_azure-1.0.28.dist-info → pulumi_django_azure-1.0.59.dist-info}/WHEEL +1 -2
- pulumi_django_azure-1.0.28.dist-info/RECORD +0 -12
- pulumi_django_azure-1.0.28.dist-info/top_level.txt +0 -1
pulumi_django_azure/settings.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import environ
|
|
2
2
|
from azure.keyvault.secrets import SecretClient
|
|
3
3
|
|
|
4
|
-
from .azure_helper import AZURE_CREDENTIAL, LOCAL_IP_ADDRESSES, get_db_password,
|
|
4
|
+
from .azure_helper import AZURE_CREDENTIAL, LOCAL_IP_ADDRESSES, get_db_password, get_subscription
|
|
5
5
|
|
|
6
6
|
env = environ.Env()
|
|
7
7
|
|
|
@@ -45,11 +45,10 @@ if azure_storage_account_name := env("AZURE_STORAGE_ACCOUNT_NAME", default=None)
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
# CDN domain - shared for all storages
|
|
48
|
-
|
|
49
|
-
AZURE_CUSTOM_DOMAIN = cdn_host
|
|
48
|
+
AZURE_CUSTOM_DOMAIN = env("CDN_HOST", default=None)
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
# Cache-Control configuration for Azure Storage uploads
|
|
51
|
+
AZURE_CACHE_CONTROL = env("AZURE_CACHE_CONTROL", default="public,max-age=31536000,immutable")
|
|
53
52
|
|
|
54
53
|
# Storage configuration
|
|
55
54
|
STORAGES = {}
|
|
@@ -62,6 +61,9 @@ if container_media := env("AZURE_STORAGE_CONTAINER_MEDIA", default=None):
|
|
|
62
61
|
},
|
|
63
62
|
}
|
|
64
63
|
|
|
64
|
+
if AZURE_CUSTOM_DOMAIN:
|
|
65
|
+
MEDIA_URL = f"https://{AZURE_CUSTOM_DOMAIN}/{container_media}/"
|
|
66
|
+
|
|
65
67
|
if container_staticfiles := env("AZURE_STORAGE_CONTAINER_STATICFILES", default=None):
|
|
66
68
|
STORAGES["staticfiles"] = {
|
|
67
69
|
"BACKEND": "storages.backends.azure_storage.AzureStorage",
|
|
@@ -69,6 +71,11 @@ if container_staticfiles := env("AZURE_STORAGE_CONTAINER_STATICFILES", default=N
|
|
|
69
71
|
"azure_container": container_staticfiles,
|
|
70
72
|
},
|
|
71
73
|
}
|
|
74
|
+
COLLECTFASTA_STRATEGY = "collectfasta.strategies.azure.AzureBlobStrategy"
|
|
75
|
+
|
|
76
|
+
if AZURE_CUSTOM_DOMAIN:
|
|
77
|
+
STATIC_URL = f"https://{AZURE_CUSTOM_DOMAIN}/{container_staticfiles}/"
|
|
78
|
+
|
|
72
79
|
|
|
73
80
|
# This setting enables password rotation in the health check middleware
|
|
74
81
|
if IS_AZURE_ENVIRONMENT:
|
|
@@ -104,65 +111,86 @@ if IS_AZURE_ENVIRONMENT:
|
|
|
104
111
|
"disable_existing_loggers": False,
|
|
105
112
|
"formatters": {
|
|
106
113
|
"timestamped": {
|
|
107
|
-
"format": "{asctime} {levelname} {message}",
|
|
114
|
+
"format": "{asctime} {levelname} [p:{process:d}] [t:{thread:d}] {message}",
|
|
108
115
|
"style": "{",
|
|
109
116
|
},
|
|
110
117
|
},
|
|
111
118
|
"handlers": {
|
|
112
|
-
"
|
|
119
|
+
"console": {
|
|
113
120
|
"level": "INFO",
|
|
114
|
-
"class": "logging.
|
|
115
|
-
"filename": "/home/LogFiles/django.log",
|
|
116
|
-
# 50 MB
|
|
117
|
-
"maxBytes": 52428800,
|
|
118
|
-
"backupCount": 5,
|
|
121
|
+
"class": "logging.StreamHandler",
|
|
119
122
|
"formatter": "timestamped",
|
|
120
123
|
},
|
|
121
124
|
},
|
|
122
125
|
"loggers": {
|
|
123
126
|
"django": {
|
|
124
|
-
"handlers": ["
|
|
127
|
+
"handlers": ["console"],
|
|
125
128
|
"level": "INFO",
|
|
126
129
|
"propagate": True,
|
|
127
130
|
},
|
|
128
131
|
"pulumi_django_azure": {
|
|
129
|
-
"handlers": ["
|
|
130
|
-
"level": "
|
|
132
|
+
"handlers": ["console"],
|
|
133
|
+
"level": "DEBUG",
|
|
131
134
|
"propagate": True,
|
|
132
135
|
},
|
|
133
136
|
},
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
# Redis, if enabled
|
|
137
|
-
|
|
138
|
-
redis_cache_port = env("REDIS_CACHE_PORT", default=None)
|
|
139
|
-
redis_cache_db = env("REDIS_CACHE_DB", default=None)
|
|
140
|
-
|
|
141
|
-
if redis_cache_host and redis_cache_port and redis_cache_db:
|
|
142
|
-
# This will enable the health check to update the Redis credentials
|
|
143
|
-
AZURE_REDIS_CREDENTIALS = True
|
|
140
|
+
REDIS_SIDECAR = env("REDIS_SIDECAR", default=False)
|
|
144
141
|
|
|
145
|
-
|
|
142
|
+
if REDIS_SIDECAR:
|
|
143
|
+
# This will prevent the website from failing if Redis is not available.
|
|
146
144
|
DJANGO_REDIS_IGNORE_EXCEPTIONS = True
|
|
147
145
|
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
|
|
148
146
|
|
|
149
|
-
REDIS_CACHE_HOST = redis_cache_host
|
|
150
|
-
REDIS_CACHE_PORT = redis_cache_port
|
|
151
|
-
REDIS_CACHE_DB = redis_cache_db
|
|
152
|
-
redis_credentials = get_redis_credentials()
|
|
153
|
-
REDIS_USERNAME = redis_credentials.username
|
|
154
|
-
REDIS_PASSWORD = redis_credentials.password
|
|
155
|
-
|
|
156
147
|
CACHES = {
|
|
157
148
|
"default": {
|
|
158
149
|
"BACKEND": "django_redis.cache.RedisCache",
|
|
159
|
-
"LOCATION":
|
|
150
|
+
"LOCATION": "redis://localhost:6379/0",
|
|
160
151
|
"OPTIONS": {
|
|
161
152
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
162
153
|
"PARSER_CLASS": "redis.connection._HiredisParser",
|
|
163
|
-
"PASSWORD": REDIS_PASSWORD,
|
|
164
154
|
},
|
|
165
155
|
},
|
|
166
156
|
}
|
|
167
|
-
|
|
168
|
-
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# Django tasks
|
|
160
|
+
DJANGO_TASKS = env("DJANGO_TASKS", default=False)
|
|
161
|
+
if DJANGO_TASKS and REDIS_SIDECAR:
|
|
162
|
+
RQ_QUEUES = {
|
|
163
|
+
"default": {
|
|
164
|
+
"USE_REDIS_CACHE": "default",
|
|
165
|
+
"QUEUES": ["default"],
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
TASKS = {
|
|
170
|
+
"default": {
|
|
171
|
+
"BACKEND": "django_tasks.backends.rq.RQBackend",
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def patch_django_settings_for_azure(INSTALLED_APPS: list, MIDDLEWARE: list, TEMPLATES: list):
|
|
177
|
+
"""
|
|
178
|
+
Patch the Django settings to add the required apps and middleware.
|
|
179
|
+
|
|
180
|
+
:param INSTALLED_APPS: Reference to INSTALLED_APPS setting.
|
|
181
|
+
:param MIDDLEWARE: Reference to MIDDLEWARE setting.
|
|
182
|
+
:param TEMPLATES: Reference to TEMPLATES setting.
|
|
183
|
+
"""
|
|
184
|
+
# Insert collectfasta at the correct position
|
|
185
|
+
INSTALLED_APPS.insert(INSTALLED_APPS.index("django.contrib.staticfiles"), "collectfasta")
|
|
186
|
+
|
|
187
|
+
# Add the required apps
|
|
188
|
+
INSTALLED_APPS.append("pulumi_django_azure")
|
|
189
|
+
INSTALLED_APPS.append("django_rq")
|
|
190
|
+
INSTALLED_APPS.append("django_tasks")
|
|
191
|
+
|
|
192
|
+
# Add the middleware
|
|
193
|
+
MIDDLEWARE.append("pulumi_django_azure.middleware.HealthCheckMiddleware")
|
|
194
|
+
|
|
195
|
+
# Add the template context processors
|
|
196
|
+
TEMPLATES[0]["OPTIONS"]["context_processors"].append("pulumi_django_azure.context_processors.add_build_info")
|