-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.py
More file actions
31 lines (27 loc) · 904 Bytes
/
extensions.py
File metadata and controls
31 lines (27 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Extensions registry.
All extensions here are initialized in app.py or by the blueprints.
"""
import os
import ssl
import redis
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask_caching import Cache
limiter = Limiter(key_func=get_remote_address)
cache = Cache()
# Redis client for identity management and other features
# Handles both regular redis:// and secure rediss:// URLs
_redis_url = os.getenv('REDIS_URL', 'redis://localhost:6379/0')
redis_client = None
if _redis_url:
try:
# Handle Heroku Redis's self-signed SSL certs for rediss:// URLs
if _redis_url.startswith('rediss://'):
redis_client = redis.from_url(
_redis_url,
ssl_cert_reqs=ssl.CERT_NONE
)
else:
redis_client = redis.from_url(_redis_url)
except Exception:
redis_client = None