-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.py
More file actions
78 lines (56 loc) · 2.21 KB
/
settings.py
File metadata and controls
78 lines (56 loc) · 2.21 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
from azure.appconfiguration.provider import load, WatchKey
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry import configure_azure_monitor
from featuremanagement import FeatureManager, TargetingContext
from featuremanagement.azuremonitor import TargetingSpanProcessor, publish_telemetry
from opentelemetry.baggage import get_baggage
from pathlib import Path
ALLOWED_HOSTS = []
def my_targeting_accessor() -> TargetingContext:
return TargetingContext(user_id=get_baggage("Session-ID"))
# Configure Azure Monitor
configure_azure_monitor(
connection_string=os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"),
span_processors=[TargetingSpanProcessor(targeting_context_accessor=my_targeting_accessor)],
)
CONFIG = {}
ENDPOINT = os.environ.get("AZURE_APPCONFIG_ENDPOINT")
# Set up credentials and settings used in resolving key vault references.
credential = DefaultAzureCredential()
def callback():
global AZURE_APP_CONFIG
# Update Django settings with the app configuration key-values
CONFIG.update(AZURE_APP_CONFIG)
# Load app configuration key-values
AZURE_APP_CONFIG = load(
endpoint=ENDPOINT,
credential=credential,
refresh_on=[WatchKey("sentinel")],
feature_flag_enabled=True,
feature_flag_refresh_enabled=True,
on_refresh_success=callback,
)
FEATURE_MANAGER = FeatureManager(AZURE_APP_CONFIG, targeting_context_accessor=my_targeting_accessor, on_feature_evaluated=publish_telemetry)
# Updates the config object with the app configuration key-values and resolved key vault reference values.
# This will override any values in the config object with the same key.
CONFIG.update(AZURE_APP_CONFIG)
SECRET_KEY = "a"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ROOT_URLCONF = "quickstartproject.urls"
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'quickstartproject.middleware.SimpleMiddleware',
]
INSTALLED_APPS = [
"django.contrib.sessions",
]
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}