-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfeature_flag_with_azure_app_configuration_sample.py
More file actions
49 lines (40 loc) · 1.93 KB
/
feature_flag_with_azure_app_configuration_sample.py
File metadata and controls
49 lines (40 loc) · 1.93 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
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""Sample demonstrating feature flags with Azure App Configuration."""
from time import sleep
import os
from azure.appconfiguration.provider import load
from azure.identity import DefaultAzureCredential
from random_filter import RandomFilter
from featuremanagement import FeatureManager, TargetingContext
endpoint = os.environ["APPCONFIGURATION_ENDPOINT"]
credential = DefaultAzureCredential()
# Connecting to Azure App Configuration using Entra ID
config = load(endpoint=endpoint, credential=credential, feature_flag_enabled=True, feature_flag_refresh_enabled=True)
feature_manager = FeatureManager(config, feature_filters=[RandomFilter()])
def check_for_changes():
alpha = feature_manager.is_enabled("Alpha")
# Is always true
print("Alpha is ", alpha is True)
while feature_manager.is_enabled("Alpha") == alpha:
sleep(5)
config.refresh()
alpha = feature_manager.is_enabled("Alpha")
print("Alpha is ", feature_manager.is_enabled("Alpha"))
# Is always false
print("Beta is ", feature_manager.is_enabled("Beta"))
# Is false 50% of the time
print("Gamma is ", feature_manager.is_enabled("Gamma"))
# Is true between two dates
print("Delta is ", feature_manager.is_enabled("Delta"))
# Is true After 06-27-2023
print("Sigma is ", feature_manager.is_enabled("Sigma"))
# Is true Before 06-28-2023
print("Epsilon is ", feature_manager.is_enabled("Epsilon"))
# Target is true for Adam, group Stage 1, and 50% of users
print("Target is ", feature_manager.is_enabled("Target", TargetingContext(user_id="Adam")))
print("Target is ", feature_manager.is_enabled("Target", TargetingContext(user_id="Brian")))
check_for_changes()