Skip to content

Commit 5fa8b9e

Browse files
update README
1 parent 35c6c14 commit 5fa8b9e

3 files changed

Lines changed: 7 additions & 29 deletions

File tree

samples/web-app-sql-database/python/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Web App with Azure SQL Database and Azure Key Vault
22

3-
This sample demonstrates a Python Flask single-page web application called *Vacation Planner* hosted on an [Azure Web App](https://learn.microsoft.com/en-us/azure/app-service/overview). The app runs on an Azure App Service Plan and stores activity data in an `activities` table within the `sampledb` database on an [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/) instance. The connection string of the SQL database is stored as a secret in [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview).
3+
This sample demonstrates a Python Flask single-page web application called *Vacation Planner* hosted on an [Azure Web App](https://learn.microsoft.com/en-us/azure/app-service/overview). The app runs on an Azure App Service Plan and stores activity data in an `activities` table within the `sampledb` database on an [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/) instance. The connection string of the SQL database is stored as a secret in [Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview). The application also retrieves its certificate from Key Vault to serve traffic over HTTPS.
44

55

66
## Architecture
@@ -12,7 +12,7 @@ The following diagram illustrates the architecture of the solution:
1212
- **Azure Web App**: Hosts the Python Flask application
1313
- **Azure App Service Plan**: Provides compute resources for the web app
1414
- **Azure SQL Database**: Stores activity data in a relational table
15-
- **Azure Key Vault**: Stores the database connection string
15+
- **Azure Key Vault**: Stores the database connection string and the certificate used to secure HTTPS traffic
1616

1717
## Prerequisites
1818

@@ -48,7 +48,7 @@ The application integrates with Azure Key Vault for managing secrets and certifi
4848

4949
Secrets: The SQL connection string is stored as a secret in Key Vault. At runtime, the app retrieves it using the Azure Key Vault Secrets SDK. This is configured via the KEY_VAULT_NAME and SECRET_NAME environment variables.
5050

51-
Certificates: A self-signed certificate is created in Key Vault during deployment. The app exposes a GET /api/certificate/validate endpoint that retrieves the certificate using the Azure Key Vault Certificates SDK and returns its name, confirming the integration works. This is configured via the KEYVAULT_URI and CERT_NAME environment variables.
51+
Certificates: A self-signed certificate is created in Key Vault during deployment. The app exposes a GET /api/certificate endpoint that retrieves the certificate using the Azure Key Vault Certificates SDK and returns its name, confirming the integration works. This is configured via the KEYVAULT_URI and CERT_NAME environment variables.
5252

5353
## Deployment
5454

samples/web-app-sql-database/python/scripts/get-web-app-url.sh

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,6 @@ get_docker_container_port_mapping() {
6565
echo "$host_port"
6666
}
6767

68-
wait_for_http_response() {
69-
local url="$1"
70-
local description="$2"
71-
local max_retries="${3:-5}"
72-
local retry_interval="${4:-5}"
73-
74-
echo "Waiting for [$description] to respond at [$url]..."
75-
76-
for i in $(seq 1 $max_retries); do
77-
http_status=$(curl -s -o /dev/null -w "%{http_code}" "$url" --max-time 5)
78-
if [ "$http_status" -eq 200 ]; then
79-
echo "[$description] is responding with HTTP 200"
80-
return 0
81-
fi
82-
echo "Attempt $i/$max_retries - HTTP $http_status. Retrying in ${retry_interval}s..."
83-
sleep $retry_interval
84-
done
85-
86-
echo "Error: [$description] failed to respond with HTTP 200 after $max_retries attempts" >&2
87-
return 1
88-
}
89-
9068
call_web_app() {
9169
# Get the web app name
9270
echo "Getting web app name..."
@@ -204,7 +182,7 @@ call_web_app() {
204182
fi
205183

206184
echo "Validating certificate from Key Vault..."
207-
KV_RESPONSE=$(curl -sk "https://$container_ip:8443/api/certificate/validate")
185+
KV_RESPONSE=$(curl -sk "https://$container_ip:8443/api/certificate")
208186
KV_THUMBPRINT=$(echo "$KV_RESPONSE" | jq -r '.thumbprint')
209187
KV_NAME=$(echo "$KV_RESPONSE" | jq -r '.name')
210188
KV_SUBJECT=$(echo "$KV_RESPONSE" | jq -r '.subject')

samples/web-app-sql-database/python/src/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ def update(activity_id: int):
136136

137137
return redirect(url_for('index'))
138138

139-
@app.route('/api/certificate/validate', methods=['GET'])
139+
@app.route('/api/certificate', methods=['GET'])
140140
def validate_certificate():
141141
"""
142142
Downloads the certificate from Key Vault, loads it as X509,
143143
and returns its properties to validate that Key Vault certificate
144144
emulation works correctly.
145145
"""
146146
vault_uri = os.environ.get('KEYVAULT_URI')
147-
cert_name = os.environ.get('CERT_NAME', 'test-cert')
147+
cert_name = os.environ.get('CERT_NAME')
148148

149-
if not vault_uri:
149+
if not vault_uri or not cert_name:
150150
return jsonify({"error": "KEYVAULT_URI not configured"}), 500
151151

152152
try:

0 commit comments

Comments
 (0)