pulumi-django-azure 1.0.32__py3-none-any.whl → 1.0.34__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.

Potentially problematic release.


This version of pulumi-django-azure might be problematic. Click here for more details.

@@ -2,7 +2,6 @@ import base64
2
2
  import json
3
3
  import logging
4
4
  import os
5
- import time
6
5
  from dataclasses import dataclass
7
6
  from subprocess import check_output
8
7
 
@@ -10,9 +9,6 @@ from azure.identity import DefaultAzureCredential
10
9
  from azure.mgmt.resource import SubscriptionClient
11
10
  from azure.mgmt.resource.subscriptions.models import Subscription
12
11
 
13
- _redis_token_cache = None
14
- _database_token_cache = None
15
-
16
12
  logger = logging.getLogger("pulumi_django_azure.azure_helper")
17
13
 
18
14
 
@@ -30,26 +26,11 @@ def get_db_password() -> str:
30
26
  """
31
27
  Get a valid password for the database.
32
28
  """
33
- global _database_token_cache
34
- _database_token_cache = AZURE_CREDENTIAL.get_token("https://ossrdbms-aad.database.windows.net/.default")
35
-
36
- logger.debug("New database token: %s", _database_token_cache)
37
-
38
- return _database_token_cache.token
39
-
40
-
41
- def db_token_will_expire(treshold=300) -> bool:
42
- """
43
- Check if the database token will expire in the next treshold seconds.
44
- """
45
- # If the token is not cached, we consider it expired (so a new one will be fetched)
46
- if _database_token_cache is None:
47
- return True
29
+ token = AZURE_CREDENTIAL.get_token("https://ossrdbms-aad.database.windows.net/.default")
48
30
 
49
- logger.debug("Database token expires on: %s", _database_token_cache.expires_on)
31
+ logger.debug("New database token: %s", token)
50
32
 
51
- # If the token is cached, check if it will expire in the next treshold seconds
52
- return _database_token_cache.expires_on - time.time() < treshold
33
+ return token.token
53
34
 
54
35
 
55
36
  @dataclass
@@ -62,28 +43,11 @@ def get_redis_credentials() -> RedisCredentials:
62
43
  """
63
44
  Get valid credentials for the Redis cache.
64
45
  """
65
- global _redis_token_cache
66
- _redis_token_cache = AZURE_CREDENTIAL.get_token("https://redis.azure.com/.default")
67
-
68
- t = _redis_token_cache.token
69
-
70
- logger.debug("New Redis token: %s", _redis_token_cache)
71
-
72
- return RedisCredentials(_extract_username_from_token(t), t)
73
-
74
-
75
- def redis_token_will_expire(treshold=300) -> bool:
76
- """
77
- Check if the Redis token will expire in the next treshold seconds.
78
- """
79
- # If the token is not cached, we consider it expired (so a new one will be fetched)
80
- if _redis_token_cache is None:
81
- return True
46
+ token = AZURE_CREDENTIAL.get_token("https://redis.azure.com/.default")
82
47
 
83
- logger.debug("Redis token expires on: %s", _redis_token_cache.expires_on)
48
+ logger.debug("New Redis token: %s", token)
84
49
 
85
- # If the token is cached, check if it will expire in the next treshold seconds
86
- return _redis_token_cache.expires_on - time.time() < treshold
50
+ return RedisCredentials(_extract_username_from_token(token.token), token.token)
87
51
 
88
52
 
89
53
  def get_subscription() -> Subscription:
@@ -8,7 +8,7 @@ from django.db.utils import OperationalError
8
8
  from django.http import HttpResponse
9
9
  from django_redis import get_redis_connection
10
10
 
11
- from .azure_helper import db_token_will_expire, get_db_password, get_redis_credentials, redis_token_will_expire
11
+ from .azure_helper import get_db_password, get_redis_credentials
12
12
 
13
13
  logger = logging.getLogger("pulumi_django_azure.health_check")
14
14
 
@@ -27,25 +27,30 @@ class HealthCheckMiddleware:
27
27
  # Update the database credentials if needed
28
28
  if settings.AZURE_DB_PASSWORD:
29
29
  try:
30
- if db_token_will_expire():
31
- logger.debug("Database token will expire, fetching new credentials")
32
- settings.DATABASES["default"]["PASSWORD"] = get_db_password()
30
+ current_db_password = settings.DATABASES["default"]["PASSWORD"]
31
+ new_db_password = get_db_password()
32
+
33
+ if new_db_password != current_db_password:
34
+ logger.debug("Database password has changed, updating credentials")
35
+ settings.DATABASES["default"]["PASSWORD"] = new_db_password
36
+
37
+ # Close existing connections to force reconnect with new password
38
+ connection.close()
33
39
  else:
34
- logger.debug("Database token is still valid, skipping credentials update")
40
+ logger.debug("Database password unchanged, keeping existing credentials")
35
41
  except Exception as e:
36
42
  logger.error("Failed to update database credentials: %s", str(e))
37
-
38
43
  self._self_heal()
39
-
40
44
  return HttpResponse(status=503)
41
45
 
42
46
  # Update the Redis credentials if needed
43
47
  if settings.AZURE_REDIS_CREDENTIALS:
44
48
  try:
45
- if redis_token_will_expire():
46
- logger.debug("Redis token will expire, fetching new credentials")
49
+ current_redis_password = settings.CACHES["default"]["OPTIONS"]["PASSWORD"]
50
+ redis_credentials = get_redis_credentials()
47
51
 
48
- redis_credentials = get_redis_credentials()
52
+ if redis_credentials.password != current_redis_password:
53
+ logger.debug("Redis password has changed, updating credentials")
49
54
 
50
55
  # Re-authenticate the Redis connection
51
56
  redis_connection = get_redis_connection("default")
@@ -53,12 +58,10 @@ class HealthCheckMiddleware:
53
58
 
54
59
  settings.CACHES["default"]["OPTIONS"]["PASSWORD"] = redis_credentials.password
55
60
  else:
56
- logger.debug("Redis token is still valid, skipping credentials update")
61
+ logger.debug("Redis password unchanged, keeping existing credentials")
57
62
  except Exception as e:
58
63
  logger.error("Failed to update Redis credentials: %s", str(e))
59
-
60
64
  self._self_heal()
61
-
62
65
  return HttpResponse(status=503)
63
66
 
64
67
  try:
@@ -72,11 +75,10 @@ class HealthCheckMiddleware:
72
75
 
73
76
  return HttpResponse("OK")
74
77
 
75
- except OperationalError as e:
76
- logger.error("Database connection failed: %s", str(e))
77
- return HttpResponse(status=503)
78
78
  except Exception as e:
79
79
  logger.error("Health check failed with unexpected error: %s", str(e))
80
+ logger.warning("Self-healing by gracefully restarting workers.")
81
+ self._self_heal()
80
82
  return HttpResponse(status=503)
81
83
 
82
84
  return self.get_response(request)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pulumi-django-azure
3
- Version: 1.0.32
3
+ Version: 1.0.34
4
4
  Summary: Simply deployment of Django on Azure with Pulumi
5
5
  Author-email: Maarten Ureel <maarten@youreal.eu>
6
6
  License-Expression: MIT
@@ -19,10 +19,10 @@ Requires-Dist: django-azure-communication-email<2.0.0,>=1.3.2
19
19
  Requires-Dist: django-environ<0.13.0,>=0.12.0
20
20
  Requires-Dist: django-redis<6.0.0,>=5.4.0
21
21
  Requires-Dist: django-storages[azure]<2.0.0,>=1.14.6
22
- Requires-Dist: pulumi>=3.165.0
22
+ Requires-Dist: pulumi>=3.166.0
23
23
  Requires-Dist: pulumi-azure-native>=3.2.0
24
- Requires-Dist: pulumi-random>=4.18.1
25
- Requires-Dist: redis[hiredis]<6.0.0,>=5.2.1
24
+ Requires-Dist: pulumi-random>=4.18.2
25
+ Requires-Dist: redis[hiredis]<7.0.0,>=6.0.0
26
26
 
27
27
  # Pulumi Django Deployment
28
28
 
@@ -1,13 +1,13 @@
1
1
  pulumi_django_azure/__init__.py,sha256=WoTHLNGnqc3dQoJtzrAJY8OVA7ReP6XFkDb9BXZGfJ8,117
2
- pulumi_django_azure/azure_helper.py,sha256=eIaOoajwQuIRyt6Q3KHIA1qctLxOqwSF9yurwk2WgzY,3417
2
+ pulumi_django_azure/azure_helper.py,sha256=7YCVlsygGUVBfvAsaHaqe_-A_6VVcvuryTgr1QMXqgs,2126
3
3
  pulumi_django_azure/context_processors.py,sha256=Qm2e_WBipJYMDH3clYAAaHvEDkG8au2czSQqRkS5928,1136
4
4
  pulumi_django_azure/django_deployment.py,sha256=l3hXP8Eo5ZUjojQtDsWeBGCFoSKN76NSz7tW9d-s9FA,50964
5
- pulumi_django_azure/middleware.py,sha256=Lp05G_wn9vlSueRJsnk-g2Rs9FFG155Po2MP2Cv0LDc,3348
5
+ pulumi_django_azure/middleware.py,sha256=7egut5QhBCleB-D3LHWMhZPh6bdrgWQqSShaXuV2tAM,3656
6
6
  pulumi_django_azure/settings.py,sha256=BTP5y6KE3oP9pY01TR1ML6GArpLhnzx-mFflrhTQ4SE,5906
7
7
  pulumi_django_azure/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pulumi_django_azure/management/commands/purge_cache.py,sha256=yjMoNvEPFmtuZctOKXMUacfKJLlTC9xfF-0W-IH3kF0,488
9
9
  pulumi_django_azure/management/commands/purge_cdn.py,sha256=8iLuqjndvreTHXRp37sjpvcNltdGTpwhY9YiQokS_P0,2095
10
- pulumi_django_azure-1.0.32.dist-info/METADATA,sha256=V64GcOLJ9OzFjHRM6CUIqBEaUw-llhbmRFgdDsZxZjI,9759
11
- pulumi_django_azure-1.0.32.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
12
- pulumi_django_azure-1.0.32.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
13
- pulumi_django_azure-1.0.32.dist-info/RECORD,,
10
+ pulumi_django_azure-1.0.34.dist-info/METADATA,sha256=uNApn_QFC2kZWPEoQuVe3pPOARO42tfa0tgs3uIzGZM,9759
11
+ pulumi_django_azure-1.0.34.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
12
+ pulumi_django_azure-1.0.34.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
13
+ pulumi_django_azure-1.0.34.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.0.0)
2
+ Generator: setuptools (80.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5