FeatureManagement 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. featuremanagement-1.0.0/CHANGELOG.md +17 -0
  2. featuremanagement-1.0.0/CODE_OF_CONDUCT.md +9 -0
  3. featuremanagement-1.0.0/FeatureManagement.egg-info/PKG-INFO +87 -0
  4. featuremanagement-1.0.0/FeatureManagement.egg-info/SOURCES.txt +41 -0
  5. featuremanagement-1.0.0/FeatureManagement.egg-info/dependency_links.txt +1 -0
  6. featuremanagement-1.0.0/FeatureManagement.egg-info/not-zip-safe +1 -0
  7. featuremanagement-1.0.0/FeatureManagement.egg-info/requires.txt +4 -0
  8. featuremanagement-1.0.0/FeatureManagement.egg-info/top_level.txt +1 -0
  9. featuremanagement-1.0.0/LICENSE +21 -0
  10. featuremanagement-1.0.0/MANIFEST.in +6 -0
  11. featuremanagement-1.0.0/PKG-INFO +87 -0
  12. featuremanagement-1.0.0/README.md +40 -0
  13. featuremanagement-1.0.0/SECURITY.md +41 -0
  14. featuremanagement-1.0.0/SUPPORT.md +25 -0
  15. featuremanagement-1.0.0/featuremanagement/__init__.py +20 -0
  16. featuremanagement-1.0.0/featuremanagement/_defaultfilters.py +162 -0
  17. featuremanagement-1.0.0/featuremanagement/_featurefilters.py +48 -0
  18. featuremanagement-1.0.0/featuremanagement/_featuremanager.py +190 -0
  19. featuremanagement-1.0.0/featuremanagement/_models/__init__.py +12 -0
  20. featuremanagement-1.0.0/featuremanagement/_models/_constants.py +18 -0
  21. featuremanagement-1.0.0/featuremanagement/_models/_evaluation_event.py +23 -0
  22. featuremanagement-1.0.0/featuremanagement/_models/_feature_conditions.py +70 -0
  23. featuremanagement-1.0.0/featuremanagement/_models/_feature_flag.py +102 -0
  24. featuremanagement-1.0.0/featuremanagement/_models/_targeting_context.py +27 -0
  25. featuremanagement-1.0.0/featuremanagement/_version.py +7 -0
  26. featuremanagement-1.0.0/featuremanagement/aio/__init__.py +10 -0
  27. featuremanagement-1.0.0/featuremanagement/aio/_defaultfilters.py +51 -0
  28. featuremanagement-1.0.0/featuremanagement/aio/_featurefilters.py +48 -0
  29. featuremanagement-1.0.0/featuremanagement/aio/_featuremanager.py +142 -0
  30. featuremanagement-1.0.0/featuremanagement/py.typed +0 -0
  31. featuremanagement-1.0.0/pyproject.toml +47 -0
  32. featuremanagement-1.0.0/samples/feature_flag_sample.py +34 -0
  33. featuremanagement-1.0.0/samples/feature_flag_with_azure_app_configuration_sample.py +46 -0
  34. featuremanagement-1.0.0/samples/formatted_feature_flags.json +230 -0
  35. featuremanagement-1.0.0/samples/random_filter.py +21 -0
  36. featuremanagement-1.0.0/setup.cfg +4 -0
  37. featuremanagement-1.0.0/setup.py +64 -0
  38. featuremanagement-1.0.0/tests/test_default_feature_flags.py +263 -0
  39. featuremanagement-1.0.0/tests/test_default_feature_flags_async.py +268 -0
  40. featuremanagement-1.0.0/tests/test_feature_manager.py +136 -0
  41. featuremanagement-1.0.0/tests/test_feature_manager_async.py +143 -0
  42. featuremanagement-1.0.0/tests/test_feature_manager_refresh.py +65 -0
  43. featuremanagement-1.0.0/tests/validation_tests/test_json_validations.py +101 -0
@@ -0,0 +1,17 @@
1
+ # Release History
2
+
3
+ ## 1.0.0 (06/26/2024)
4
+
5
+ Updated version to 1.0.0.
6
+
7
+ ## 1.0.0b1 (05/22/2024)
8
+
9
+ New Feature Management library.
10
+
11
+ Provides the ability to manage feature flags in a project. Enables:
12
+
13
+ * Loading of feature flags from a file, see: https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureManagement.v2.0.0.schema.json
14
+ * Loading of feature flags from Azure App Configuration.
15
+ * Checking if a feature is enabled.
16
+ * Default feature filters: TimeWindowFilter, TargetingFilter.
17
+ * Custom feature filters.
@@ -0,0 +1,9 @@
1
+ # Microsoft Open Source Code of Conduct
2
+
3
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4
+
5
+ Resources:
6
+
7
+ - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8
+ - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9
+ - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: FeatureManagement
3
+ Version: 1.0.0
4
+ Summary: A library for enabling/disabling features at runtime.
5
+ Home-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/appconfiguration/feature-management
6
+ Author: Microsoft Corporation
7
+ Author-email: Microsoft Corporation <appconfig@microsoft.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE
29
+
30
+ Project-URL: Homepage, https://github.com/microsoft/FeatureManagement-Python
31
+ Project-URL: Issues, https://github.com/microsoft/FeatureManagement-Python/issues
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Programming Language :: Python
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.8
37
+ Classifier: Programming Language :: Python :: 3.9
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Requires-Python: >=3.6
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Provides-Extra: appinsights
45
+ Requires-Dist: azure-monitor-opentelemetry<2.0.0,>=1.3.0; extra == "appinsights"
46
+ Requires-Dist: azure-monitor-events-extension<2.0.0; extra == "appinsights"
47
+
48
+ # Microsoft Feature Management for Python
49
+
50
+ [![FeatureManagement](https://img.shields.io/pypi/v/FeatureManagement?label=FeatureManagement)](https://pypi.org/project/FeatureManagement/)
51
+
52
+ Feature management provides a way to develop and expose application functionality based on features. Many applications have special requirements when a new feature is developed such as when the feature should be enabled and under what conditions. This library provides a way to define these relationships, and also integrates into common Python code patterns to make exposing these features possible.
53
+
54
+ ## Get Started
55
+
56
+ [Quickstart](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-feature-flag-python): A quickstart guide is available to learn how to integrate feature flags from Azure App Configuration into your Python applications.
57
+
58
+ [API Reference](https://microsoft.github.io/FeatureManagement-Python/): This API reference details the API surface of the libraries contained within this repository.
59
+
60
+ ## Examples
61
+
62
+ * [Python Application](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_sample.py)
63
+ * [Python Application with Azure App Configuration](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_with_azure_app_configuration_sample.py)
64
+ * [Django Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-django-webapp-sample)
65
+ * [Flask Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-flask-webapp-sample)
66
+
67
+ ## Contributing
68
+
69
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
70
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
71
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
72
+
73
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
74
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
75
+ provided by the bot. You will only need to do this once across all repos using our CLA.
76
+
77
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
78
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
79
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
80
+
81
+ ## Trademarks
82
+
83
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
84
+ trademarks or logos is subject to and must follow
85
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
86
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
87
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,41 @@
1
+ CHANGELOG.md
2
+ CODE_OF_CONDUCT.md
3
+ LICENSE
4
+ MANIFEST.in
5
+ README.md
6
+ SECURITY.md
7
+ SUPPORT.md
8
+ pyproject.toml
9
+ setup.py
10
+ FeatureManagement.egg-info/PKG-INFO
11
+ FeatureManagement.egg-info/SOURCES.txt
12
+ FeatureManagement.egg-info/dependency_links.txt
13
+ FeatureManagement.egg-info/not-zip-safe
14
+ FeatureManagement.egg-info/requires.txt
15
+ FeatureManagement.egg-info/top_level.txt
16
+ featuremanagement/__init__.py
17
+ featuremanagement/_defaultfilters.py
18
+ featuremanagement/_featurefilters.py
19
+ featuremanagement/_featuremanager.py
20
+ featuremanagement/_version.py
21
+ featuremanagement/py.typed
22
+ featuremanagement/_models/__init__.py
23
+ featuremanagement/_models/_constants.py
24
+ featuremanagement/_models/_evaluation_event.py
25
+ featuremanagement/_models/_feature_conditions.py
26
+ featuremanagement/_models/_feature_flag.py
27
+ featuremanagement/_models/_targeting_context.py
28
+ featuremanagement/aio/__init__.py
29
+ featuremanagement/aio/_defaultfilters.py
30
+ featuremanagement/aio/_featurefilters.py
31
+ featuremanagement/aio/_featuremanager.py
32
+ samples/feature_flag_sample.py
33
+ samples/feature_flag_with_azure_app_configuration_sample.py
34
+ samples/formatted_feature_flags.json
35
+ samples/random_filter.py
36
+ tests/test_default_feature_flags.py
37
+ tests/test_default_feature_flags_async.py
38
+ tests/test_feature_manager.py
39
+ tests/test_feature_manager_async.py
40
+ tests/test_feature_manager_refresh.py
41
+ tests/validation_tests/test_json_validations.py
@@ -0,0 +1,4 @@
1
+
2
+ [AppInsights]
3
+ azure-monitor-opentelemetry<2.0.0,>=1.3.0
4
+ azure-monitor-events-extension<2.0.0
@@ -0,0 +1 @@
1
+ featuremanagement
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,6 @@
1
+ recursive-include tests *.py
2
+ include *.md
3
+ include LICENSE
4
+ include featuremanagement/*.py
5
+ include featuremanagement/aio/*.py
6
+ recursive-include samples *.py *.json
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: FeatureManagement
3
+ Version: 1.0.0
4
+ Summary: A library for enabling/disabling features at runtime.
5
+ Home-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/appconfiguration/feature-management
6
+ Author: Microsoft Corporation
7
+ Author-email: Microsoft Corporation <appconfig@microsoft.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE
29
+
30
+ Project-URL: Homepage, https://github.com/microsoft/FeatureManagement-Python
31
+ Project-URL: Issues, https://github.com/microsoft/FeatureManagement-Python/issues
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Programming Language :: Python
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.8
37
+ Classifier: Programming Language :: Python :: 3.9
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Requires-Python: >=3.6
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Provides-Extra: appinsights
45
+ Requires-Dist: azure-monitor-opentelemetry<2.0.0,>=1.3.0; extra == "appinsights"
46
+ Requires-Dist: azure-monitor-events-extension<2.0.0; extra == "appinsights"
47
+
48
+ # Microsoft Feature Management for Python
49
+
50
+ [![FeatureManagement](https://img.shields.io/pypi/v/FeatureManagement?label=FeatureManagement)](https://pypi.org/project/FeatureManagement/)
51
+
52
+ Feature management provides a way to develop and expose application functionality based on features. Many applications have special requirements when a new feature is developed such as when the feature should be enabled and under what conditions. This library provides a way to define these relationships, and also integrates into common Python code patterns to make exposing these features possible.
53
+
54
+ ## Get Started
55
+
56
+ [Quickstart](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-feature-flag-python): A quickstart guide is available to learn how to integrate feature flags from Azure App Configuration into your Python applications.
57
+
58
+ [API Reference](https://microsoft.github.io/FeatureManagement-Python/): This API reference details the API surface of the libraries contained within this repository.
59
+
60
+ ## Examples
61
+
62
+ * [Python Application](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_sample.py)
63
+ * [Python Application with Azure App Configuration](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_with_azure_app_configuration_sample.py)
64
+ * [Django Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-django-webapp-sample)
65
+ * [Flask Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-flask-webapp-sample)
66
+
67
+ ## Contributing
68
+
69
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
70
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
71
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
72
+
73
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
74
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
75
+ provided by the bot. You will only need to do this once across all repos using our CLA.
76
+
77
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
78
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
79
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
80
+
81
+ ## Trademarks
82
+
83
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
84
+ trademarks or logos is subject to and must follow
85
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
86
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
87
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,40 @@
1
+ # Microsoft Feature Management for Python
2
+
3
+ [![FeatureManagement](https://img.shields.io/pypi/v/FeatureManagement?label=FeatureManagement)](https://pypi.org/project/FeatureManagement/)
4
+
5
+ Feature management provides a way to develop and expose application functionality based on features. Many applications have special requirements when a new feature is developed such as when the feature should be enabled and under what conditions. This library provides a way to define these relationships, and also integrates into common Python code patterns to make exposing these features possible.
6
+
7
+ ## Get Started
8
+
9
+ [Quickstart](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-feature-flag-python): A quickstart guide is available to learn how to integrate feature flags from Azure App Configuration into your Python applications.
10
+
11
+ [API Reference](https://microsoft.github.io/FeatureManagement-Python/): This API reference details the API surface of the libraries contained within this repository.
12
+
13
+ ## Examples
14
+
15
+ * [Python Application](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_sample.py)
16
+ * [Python Application with Azure App Configuration](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_with_azure_app_configuration_sample.py)
17
+ * [Django Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-django-webapp-sample)
18
+ * [Flask Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-flask-webapp-sample)
19
+
20
+ ## Contributing
21
+
22
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
23
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
24
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
25
+
26
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
27
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
28
+ provided by the bot. You will only need to do this once across all repos using our CLA.
29
+
30
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
31
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
32
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
33
+
34
+ ## Trademarks
35
+
36
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
37
+ trademarks or logos is subject to and must follow
38
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
39
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
40
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,41 @@
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->
@@ -0,0 +1,25 @@
1
+ # TODO: The maintainer of this repo has not yet edited this file
2
+
3
+ **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
4
+
5
+ - **No CSS support:** Fill out this template with information about how to file issues and get help.
6
+ - **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps.
7
+ - **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide.
8
+
9
+ *Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
10
+
11
+ # Support
12
+
13
+ ## How to file issues and get help
14
+
15
+ This project uses GitHub Issues to track bugs and feature requests. Please search the existing
16
+ issues before filing new issues to avoid duplicates. For new issues, file your bug or
17
+ feature request as a new Issue.
18
+
19
+ For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
20
+ FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
21
+ CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
22
+
23
+ ## Microsoft Support Policy
24
+
25
+ Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
@@ -0,0 +1,20 @@
1
+ # ------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # -------------------------------------------------------------------------
6
+ from ._featuremanager import FeatureManager
7
+ from ._featurefilters import FeatureFilter
8
+ from ._defaultfilters import TimeWindowFilter, TargetingFilter
9
+ from ._models import TargetingContext
10
+
11
+ from ._version import VERSION
12
+
13
+ __version__ = VERSION
14
+ __all__ = [
15
+ "FeatureManager",
16
+ "TimeWindowFilter",
17
+ "TargetingFilter",
18
+ "FeatureFilter",
19
+ "TargetingContext",
20
+ ]
@@ -0,0 +1,162 @@
1
+ # ------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # -------------------------------------------------------------------------
6
+ import logging
7
+ import hashlib
8
+
9
+ from datetime import datetime, timezone
10
+ from email.utils import parsedate_to_datetime
11
+
12
+ from ._featurefilters import FeatureFilter
13
+
14
+ FEATURE_FLAG_NAME_KEY = "feature_name"
15
+ ROLLOUT_PERCENTAGE_KEY = "RolloutPercentage"
16
+ DEFAULT_ROLLOUT_PERCENTAGE_KEY = "DefaultRolloutPercentage"
17
+ PARAMETERS_KEY = "parameters"
18
+
19
+ # Time Window Constants
20
+ START_KEY = "Start"
21
+ END_KEY = "End"
22
+
23
+ # Targeting kwargs
24
+ TARGETED_USER_KEY = "user"
25
+ TARGETED_GROUPS_KEY = "groups"
26
+
27
+ # Targeting Constants
28
+ AUDIENCE_KEY = "Audience"
29
+ USERS_KEY = "Users"
30
+ GROUPS_KEY = "Groups"
31
+ EXCLUSION_KEY = "Exclusion"
32
+ FEATURE_FILTER_NAME_KEY = "Name"
33
+ IGNORE_CASE_KEY = "ignore_case"
34
+
35
+
36
+ class TargetingException(Exception):
37
+ """
38
+ Exception raised when the targeting filter is not configured correctly.
39
+ """
40
+
41
+
42
+ @FeatureFilter.alias("Microsoft.TimeWindow")
43
+ class TimeWindowFilter(FeatureFilter):
44
+ """
45
+ Feature Filter that determines if the current time is within the time window.
46
+ """
47
+
48
+ def evaluate(self, context, **kwargs):
49
+ """
50
+ Determine if the feature flag is enabled for the given context.
51
+
52
+ :keyword Mapping context: Mapping with the Start and End time for the feature flag.
53
+ :return: True if the current time is within the time window.
54
+ :rtype: bool
55
+ """
56
+ start = context.get(PARAMETERS_KEY, {}).get(START_KEY)
57
+ end = context.get(PARAMETERS_KEY, {}).get(END_KEY)
58
+
59
+ current_time = datetime.now(timezone.utc)
60
+
61
+ if not start and not end:
62
+ logging.warning("%s: At least one of Start or End is required.", TimeWindowFilter.__name__)
63
+ return False
64
+
65
+ start_time = parsedate_to_datetime(start) if start else None
66
+ end_time = parsedate_to_datetime(end) if end else None
67
+
68
+ return (start_time is None or start_time <= current_time) and (end_time is None or current_time < end_time)
69
+
70
+
71
+ @FeatureFilter.alias("Microsoft.Targeting")
72
+ class TargetingFilter(FeatureFilter):
73
+ """
74
+ Feature Filter that determines if the user is targeted for the feature flag.
75
+ """
76
+
77
+ @staticmethod
78
+ def _is_targeted(context_id, rollout_percentage):
79
+ """Determine if the user is targeted for the given context"""
80
+ # Always return true if rollout percentage is 100
81
+ if rollout_percentage == 100:
82
+ return True
83
+
84
+ hashed_context_id = hashlib.sha256(context_id.encode()).digest()
85
+ context_marker = int.from_bytes(hashed_context_id[:4], byteorder="little", signed=False)
86
+
87
+ percentage = (context_marker / (2**32 - 1)) * 100
88
+ return percentage < rollout_percentage
89
+
90
+ def _target_group(self, target_user, target_group, group, feature_flag_name):
91
+ group_rollout_percentage = group.get(ROLLOUT_PERCENTAGE_KEY, 0)
92
+ if not target_user:
93
+ target_user = ""
94
+ audience_context_id = target_user + "\n" + feature_flag_name + "\n" + target_group
95
+
96
+ return self._is_targeted(audience_context_id, group_rollout_percentage)
97
+
98
+ def evaluate(self, context, **kwargs):
99
+ """
100
+ Determine if the feature flag is enabled for the given context.
101
+
102
+ :keyword Mapping context: Context for evaluating the user/group.
103
+ :return: True if the user is targeted for the feature flag.
104
+ :rtype: bool
105
+ """
106
+ target_user = kwargs.get(TARGETED_USER_KEY, None)
107
+ target_groups = kwargs.get(TARGETED_GROUPS_KEY, [])
108
+
109
+ if not target_user and not (target_groups and len(target_groups) > 0):
110
+ logging.warning("%s: Name or Groups are required parameters", TargetingFilter.__name__)
111
+ return False
112
+
113
+ audience = context.get(PARAMETERS_KEY, {}).get(AUDIENCE_KEY, None)
114
+ feature_flag_name = context.get(FEATURE_FLAG_NAME_KEY, None)
115
+
116
+ if not audience:
117
+ raise TargetingException("Audience is required for " + TargetingFilter.__name__)
118
+
119
+ groups = audience.get(GROUPS_KEY, [])
120
+ default_rollout_percentage = audience.get(DEFAULT_ROLLOUT_PERCENTAGE_KEY, 0)
121
+
122
+ self._validate(groups, default_rollout_percentage)
123
+
124
+ # Check if the user is excluded
125
+ if target_user in audience.get(EXCLUSION_KEY, {}).get(USERS_KEY, []):
126
+ return False
127
+
128
+ # Check if the user is in an excluded group
129
+ for group in audience.get(EXCLUSION_KEY, {}).get(GROUPS_KEY, []):
130
+ if group in target_groups:
131
+ return False
132
+
133
+ # Check if the user is targeted
134
+ if target_user in audience.get(USERS_KEY, []):
135
+ return True
136
+
137
+ # Check if the user is in a targeted group
138
+ for group in groups:
139
+ for target_group in target_groups:
140
+ group_name = group.get(FEATURE_FILTER_NAME_KEY, "")
141
+ if kwargs.get(IGNORE_CASE_KEY, False):
142
+ target_group = target_group.lower()
143
+ group_name = group_name.lower()
144
+ if group_name == target_group:
145
+ if self._target_group(target_user, target_group, group, feature_flag_name):
146
+ return True
147
+
148
+ if not target_user:
149
+ target_user = ""
150
+ # Check if the user is in the default rollout
151
+ context_id = target_user + "\n" + feature_flag_name
152
+ return self._is_targeted(context_id, default_rollout_percentage)
153
+
154
+ @staticmethod
155
+ def _validate(groups, default_rollout_percentage):
156
+ # Validate the audience settings
157
+ if default_rollout_percentage < 0 or default_rollout_percentage > 100:
158
+ raise TargetingException("DefaultRolloutPercentage must be between 0 and 100")
159
+
160
+ for group in groups:
161
+ if group.get(ROLLOUT_PERCENTAGE_KEY) < 0 or group.get(ROLLOUT_PERCENTAGE_KEY) > 100:
162
+ raise TargetingException("RolloutPercentage must be between 0 and 100")
@@ -0,0 +1,48 @@
1
+ # ------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # -------------------------------------------------------------------------
6
+ from abc import ABC, abstractmethod
7
+
8
+
9
+ class FeatureFilter(ABC):
10
+ """
11
+ Parent class for all feature filters.
12
+ """
13
+
14
+ @abstractmethod
15
+ def evaluate(self, context, **kwargs):
16
+ """
17
+ Determine if the feature flag is enabled for the given context.
18
+
19
+ :param Mapping context: Context for the feature flag.
20
+ """
21
+
22
+ @property
23
+ def name(self):
24
+ """
25
+ Get the name of the filter.
26
+
27
+ :return: Name of the filter, or alias if it exists.
28
+ :rtype: str
29
+ """
30
+ if hasattr(self, "_alias"):
31
+ return self._alias
32
+ return self.__class__.__name__
33
+
34
+ @staticmethod
35
+ def alias(alias):
36
+ """
37
+ Decorator to set the alias for the filter.
38
+
39
+ :param str alias: Alias for the filter.
40
+ :return: Decorator.
41
+ :rtype: callable
42
+ """
43
+
44
+ def wrapper(cls):
45
+ cls._alias = alias # pylint: disable=protected-access
46
+ return cls
47
+
48
+ return wrapper