Skip to content

Commit f94a907

Browse files
committed
review comments
1 parent c45cb42 commit f94a907

File tree

3 files changed

+16
-137
lines changed

3 files changed

+16
-137
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,14 @@
158158
href: howto-targetingfilter.md
159159
- name: ASP.NET Core
160160
href: howto-targetingfilter-aspnet-core.md
161-
- name: Python
162-
href: use-variant-feature-flags-python.md
163-
- name: Run experiments with variant feature flags
164161
- name: Use variant feature flags
165162
items:
166163
- name: Overview
167164
href: use-variant-feature-flags.md
168165
- name: ASP.NET Core
169166
href: use-variant-feature-flags-aspnet-core.md
167+
- name: Python
168+
href: use-variant-feature-flags-python.md
170169
- name: Enable Azure monitoring
171170
items:
172171
- name: Monitor App Configuration

articles/azure-app-configuration/index.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,10 @@ landingContent:
162162
url: howto-timewindow-filter.md
163163
- text: Roll out features to targeted audience
164164
url: howto-targetingfilter.md
165-
- text: Use variant feature flags in Python
166-
url: use-variant-feature-flags-python.md
167-
- text: Run experiments with variant feature flags
168-
url: run-experiments-aspnet-core.md
169165
- text: Use variant feature flags
170166
url: use-variant-feature-flags.md
167+
- text: Use variant feature flags in Python
168+
url: use-variant-feature-flags-python.md
171169
- linkListType: reference
172170
links:
173171
- text: .NET feature management

articles/azure-app-configuration/use-variant-feature-flags-python.md

Lines changed: 12 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: 'Tutorial: Use variant feature flags from Azure App Configuration in a Python application (preview)'
2+
title: 'Use variant feature flags application'
33
titleSuffix: Azure App configuration
44
description: In this tutorial, you learn how to use variant feature flags in an Python application
55
#customerintent: As a user of Azure App Configuration, I want to learn how I can use variants and variant feature flags in my python application.
66
author: mrm9084
77
ms.author: mametcal
88
ms.service: azure-app-configuration
99
ms.devlang: python
10-
ms.topic: tutorial
10+
ms.topic: how-to
1111
ms.date: 12/02/2024
1212
---
1313

14-
# Tutorial: Use variant feature flags in Azure App Configuration (preview)
14+
# Tutorial: Use variant feature flags in Azure App Configuration
1515

1616
In this tutorial, you use a variant feature flag to manage experiences for different user segments in an example application, *Quote of the Day*. You utilize the variant feature flag created in [Use variant feature flags](./use-variant-feature-flags.md). Before proceeding, ensure you create the variant feature flag named *Greeting* in your App Configuration store.
1717

@@ -36,25 +36,19 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
3636
.\venv\Scripts\Activate
3737
```
3838

39-
1. Install the required packages. The latest preview versions of `azure-appconfiguration-provider`, and `featuremanagement` are required for variant feature flags (preview).
39+
1. Install the required packages. The latest preview versions of `azure-appconfiguration-provider`, and `featuremanagement` are required for variant feature flags.
4040

4141
```bash
4242
pip install flask azure-appconfiguration-provider==2.0.0b3 azure-identity featuremanagement[AzureMonitor]==2.0.0b3 flask-login flask_sqlalchemy flask_bcrypt
4343
```
4444

45-
1. Create a new file named *app.py* in the *QuoteOfTheDay* folder.
46-
47-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
48-
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
45+
1. Create a new file named *app.py* in the *QuoteOfTheDay* folder. You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
4946

5047
```python
5148
import os
5249
from azure.appconfiguration.provider import load
5350
from featuremanagement import FeatureManager
54-
from featuremanagement.azuremonitor import publish_telemetry
5551
from azure.identity import DefaultAzureCredential
56-
from opentelemetry import trace
57-
from opentelemetry.trace import get_tracer_provider
5852
from flask_bcrypt import Bcrypt
5953
6054
from flask_sqlalchemy import SQLAlchemy
@@ -65,8 +59,6 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
6559
app = Flask(__name__, template_folder="../templates", static_folder="../static")
6660
bcrypt = Bcrypt(app)
6761
68-
tracer = trace.get_tracer(__name__, tracer_provider=get_tracer_provider())
69-
7062
ENDPOINT = os.getenv("AzureAppConfigurationEndpoint")
7163
7264
def callback():
@@ -81,15 +73,14 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
8173
feature_flag_refresh_enabled=True,
8274
)
8375
app.config.update(azure_app_config)
84-
feature_manager = FeatureManager(azure_app_config, on_feature_evaluated=publish_telemetry)
76+
feature_manager = FeatureManager(azure_app_config)
8577
8678
db = SQLAlchemy()
8779
db.init_app(app)
8880
8981
login_manager = LoginManager()
9082
login_manager.init_app(app)
9183
92-
9384
from .model import Users
9485
9586
@login_manager.user_loader
@@ -105,77 +96,19 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
10596
from . import routes
10697
app.register_blueprint(routes.bp)
10798
```
108-
### [Connection string](#tab/connection-string)
109-
```python
110-
import os
111-
from azure.appconfiguration.provider import load
112-
from featuremanagement import FeatureManager
113-
from featuremanagement.azuremonitor import publish_telemetry
114-
from opentelemetry import trace
115-
from opentelemetry.trace import get_tracer_provider
116-
from flask_bcrypt import Bcrypt
117-
118-
from flask_sqlalchemy import SQLAlchemy
119-
from flask_login import LoginManager
120-
121-
from flask import Flask
122-
123-
app = Flask(__name__, template_folder="../templates", static_folder="../static")
124-
bcrypt = Bcrypt(app)
125-
126-
tracer = trace.get_tracer(__name__, tracer_provider=get_tracer_provider())
127-
128-
def callback():
129-
app.config.update(azure_app_config)
130-
131-
global azure_app_config
132-
azure_app_config = load(
133-
connection_string=os.getenv("AzureAppConfigurationConnectionString"),
134-
on_refresh_success=callback,
135-
feature_flag_enabled=True,
136-
feature_flag_refresh_enabled=True,
137-
)
138-
app.config.update(azure_app_config)
139-
feature_manager = FeatureManager(azure_app_config, on_feature_evaluated=publish_telemetry)
140-
141-
db = SQLAlchemy()
142-
db.init_app(app)
143-
144-
login_manager = LoginManager()
145-
login_manager.init_app(app)
146-
147-
148-
from .model import Users
149-
150-
@login_manager.user_loader
151-
def loader_user(user_id):
152-
return Users.query.get(user_id)
153-
154-
with app.app_context():
155-
db.create_all()
156-
157-
if __name__ == "__main__":
158-
app.run(debug=True)
159-
160-
from . import routes
161-
app.register_blueprint(routes.bp)
162-
```
163-
---
99+
164100
1. Create a new file called *model.py* in the *QuoteOfTheDay* folder.
165101
166102
```python
167103
from dataclasses import dataclass
168104
from flask_login import UserMixin
169105
from . import db
170-
171-
172-
106+
173107
@dataclass
174108
class Quote:
175109
message: str
176110
author: str
177111
178-
179112
# Create user model
180113
class Users(UserMixin, db.Model):
181114
@@ -234,18 +167,6 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
234167
235168
return render_template("index.html", **context)
236169
237-
@bp.route("/privacy", methods=["GET"])
238-
def privacy():
239-
context = {}
240-
user = ""
241-
if current_user.is_authenticated:
242-
user = current_user.username
243-
context["user"] = user
244-
else:
245-
context["user"] = "Guest"
246-
context["isAuthenticated"] = current_user.is_authenticated
247-
return render_template("privacy.html", **context)
248-
249170
@bp.route("/register", methods=["GET", "POST"])
250171
def register():
251172
if request.method == "POST":
@@ -274,7 +195,6 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
274195
return redirect(url_for("pages.index"))
275196
return render_template("login.html")
276197
277-
278198
@bp.route("/logout")
279199
def logout():
280200
logout_user()
@@ -358,9 +278,6 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
358278
<li class="nav-item">
359279
<a class="nav-link text-dark" href="/">Home</a>
360280
</li>
361-
<li class="nav-item">
362-
<a class="nav-link text-dark" href="/privacy">Privacy</a>
363-
</li>
364281
</ul>
365282
{% block login_partial %}
366283
<ul class="navbar-nav">
@@ -395,7 +312,7 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
395312
396313
<footer class="border-top footer text-muted">
397314
<div class="container">
398-
&copy; 2024 - QuoteOfTheDay - <a href="/privacy">Privacy</a>
315+
&copy; 2024 - QuoteOfTheDay
399316
</div>
400317
</footer>
401318
@@ -443,21 +360,11 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
443360
{% endblock %}
444361
```
445362
446-
1. Create a new file named *privacy.html* in the *templates* folder.
447-
448-
```html
449-
{% extends 'base.html' %}
450-
451-
{% block content %}
452-
<p>Use this page to detail your site's privacy policy.</p>
453-
{% endblock %}
454-
```
455-
456363
1. Create a new folder named *static* in the *QuoteOfTheDay* folder.
457364
458365
1. Create a new folder named *css* in the *static* folder.
459366
460-
1. Create a new file named *site.css* in the *static* folder.
367+
1. Create a new file named *site.css* in the *css* folder.
461368
462369
```css
463370
html {
@@ -549,12 +456,9 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
549456
}
550457
```
551458
552-
### Build and run the app (preview)
553-
554-
1. Set an environment variable.
459+
### Build and run the app
555460
556-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
557-
Set the environment variable named **Endpoint** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
461+
1. Set an environment variable. Set the environment variable named **Endpoint** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
558462
559463
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
560464
@@ -574,28 +478,6 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
574478
export AzureAppConfigurationEndpoint='endpoint-of-your-app-configuration-store'
575479
```
576480
577-
### [Connection string](#tab/connection-string)
578-
Set the environment variable named **ConnectionString** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
579-
580-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
581-
582-
```cmd
583-
setx AzureAppConfigurationConnectionString "connection-string-of-your-app-configuration-store"
584-
```
585-
586-
If you use PowerShell, run the following command:
587-
588-
```powershell
589-
$Env:AzureAppConfigurationConnectionString = "connection-string-of-your-app-configuration-store"
590-
```
591-
592-
If you use macOS or Linux, run the following command:
593-
594-
```bash
595-
export AzureAppConfigurationConnectionString='connection-string-of-your-app-configuration-store'
596-
```
597-
---
598-
599481
1. In the command prompt, in the *QuoteOfTheDay* folder, run: `flask run`.
600482
1. Wait for the app to start, and then open a browser and navigate to `http://localhost:5000/`.
601483
1. Once viewing the running application, select **Register** at the top right to register a new user.

0 commit comments

Comments
 (0)