-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Async * Update app.py * Updated with callback * Update app.py * Removing Async, formatting * Updating requirements
- Loading branch information
Showing
6 changed files
with
114 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,3 +338,6 @@ ASALocalRun/ | |
# MFractors (Xamarin productivity tool) working folder | ||
.mfractor/ | ||
.env | ||
|
||
# Python env | ||
env/ |
20 changes: 10 additions & 10 deletions
20
examples/Python/python-django-webapp-sample/hello_azure/views.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,15 +1,15 @@ | ||
from django.shortcuts import render | ||
from django.conf import settings | ||
|
||
def index(request): | ||
|
||
async def index(request): | ||
# Refresh the configuration from App Configuration service. | ||
settings.AZURE_APPCONFIGURATION.refresh() | ||
# Update Django settings with the app configuration key-values | ||
settings.CONFIG.update(settings.AZURE_APPCONFIGURATION) | ||
settings.AZURE_APP_CONFIG.refresh() | ||
|
||
context = { | ||
"message": settings.CONFIG.get('message'), | ||
"key": settings.CONFIG.get('secret_key'), | ||
"color": settings.CONFIG.get('color'), | ||
"font_size": settings.CONFIG.get('font_size') | ||
} | ||
return render(request, 'hello_azure/index.html', context) | ||
"message": settings.CONFIG.get("message"), | ||
"key": settings.CONFIG.get("secret_key"), | ||
"color": settings.CONFIG.get("color"), | ||
"font_size": settings.CONFIG.get("font_size"), | ||
} | ||
return render(request, "hello_azure/index.html", context) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Django==4.1.13 | ||
whitenoise==6.4.0 | ||
azure-appconfiguration-provider==1.1.0b1 | ||
azure-appconfiguration-provider==1.1.0b3 | ||
azure-identity==1.12.0 |
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,46 +1,49 @@ | ||
import os | ||
from flask import Flask, render_template | ||
from azure.appconfiguration.provider import load, SettingSelector, SentinelKey | ||
from azure.appconfiguration.provider import load, SettingSelector, WatchKey | ||
from azure.identity import DefaultAzureCredential | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
ENDPOINT = os.environ.get("AZURE_APPCONFIG_ENDPOINT") | ||
|
||
# Set up credentials and settings used in resolving key vault references. | ||
ENDPOINT = os.environ.get("AZURE_APPCONFIG_ENDPOINT") | ||
credential = DefaultAzureCredential() | ||
|
||
# Load app configuration key-values and resolved key vault reference values. | ||
# Select only key-values that start with 'testapp_settings_' and trim the prefix | ||
selects = SettingSelector(key_filter="testapp_settings_*") | ||
selects_secret = SettingSelector(key_filter="secret_key") | ||
azure_app_config = load(endpoint=ENDPOINT, | ||
keyvault_credential=credential, | ||
credential=credential, | ||
selects=[selects, selects_secret], | ||
trim_prefixes=["testapp_settings_"], | ||
refresh_on=[SentinelKey("sentinel")], | ||
) | ||
|
||
# App Configuration provider implements the Mapping Type which is compatible with the existing Flask config. | ||
# Update Flask config mapping with loaded values in the App Configuration provider. | ||
|
||
|
||
def callback(): | ||
app.config.update(azure_app_config) | ||
|
||
|
||
global azure_app_config | ||
azure_app_config = load( | ||
endpoint=ENDPOINT, | ||
selects=[selects, selects_secret], | ||
credential=credential, | ||
keyvault_credential=credential, | ||
trim_prefixes=["testapp_settings_"], | ||
refresh_on=[WatchKey("sentinel")], | ||
on_refresh_success=callback, | ||
) | ||
app.config.update(azure_app_config) | ||
|
||
@app.route('/') | ||
|
||
@app.route("/") | ||
def index(): | ||
# Refresh the configuration from App Configuration service. | ||
azure_app_config.refresh() | ||
# Update Flask config mapping with loaded values in the App Configuration provider. | ||
app.config.update(azure_app_config) | ||
print('Request for index page received') | ||
context = {} | ||
context['message'] = app.config.get('message') | ||
context['font_size'] = app.config.get('font_size') | ||
context['color'] = app.config.get('color') | ||
context['key'] = app.config.get('secret_key') # This is a key vault reference. The corresponding secret in key vault is returned. | ||
return render_template('index.html', **context) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run() | ||
global azure_app_config | ||
# Refresh the configuration from App Configuration service. | ||
azure_app_config.refresh() | ||
|
||
print("Request for index page received") | ||
context = {} | ||
context["message"] = app.config.get("message") | ||
context["font_size"] = app.config.get("font_size") | ||
context["color"] = app.config.get("color") | ||
context["key"] = app.config.get( | ||
"secret_key" | ||
) # This is a key vault reference. The corresponding secret in key vault is returned. | ||
return render_template("index.html", **context) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run() |
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,3 +1,3 @@ | ||
Flask==2.3.2 | ||
azure-identity==1.12.0 | ||
azure-appconfiguration-provider==1.1.0b2 | ||
azure-appconfiguration-provider==1.1.0b3 |