-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path_defaultfilters.py
More file actions
53 lines (42 loc) · 1.85 KB
/
_defaultfilters.py
File metadata and controls
53 lines (42 loc) · 1.85 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
50
51
52
53
# ------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Built-in async feature filter implementations."""
from typing import Mapping, Any
from ._featurefilters import FeatureFilter
from .._defaultfilters import (
TargetingFilter as SyncTargetingFilter,
TimeWindowFilter as SyncTimeWindowFilter,
)
@FeatureFilter.alias("Microsoft.TimeWindow")
class TimeWindowFilter(FeatureFilter):
"""
Feature Filter that determines if the current time is within the time window.
"""
def __init__(self) -> None:
self._filter = SyncTimeWindowFilter()
async def evaluate(self, context: Mapping[Any, Any], **kwargs: Any) -> bool:
"""
Determine if the feature flag is enabled for the given context.
:keyword Mapping context: Mapping with the Start and End time for the feature flag.
:return: True if the current time is within the time window.
:rtype: bool
"""
return self._filter.evaluate(context, **kwargs)
@FeatureFilter.alias("Microsoft.Targeting")
class TargetingFilter(FeatureFilter):
"""
Feature Filter that determines if the user is targeted for the feature flag.
"""
def __init__(self) -> None:
self._filter = SyncTargetingFilter()
async def evaluate(self, context: Mapping[Any, Any], **kwargs: Any) -> bool:
"""
Determine if the feature flag is enabled for the given context.
:keyword Mapping context: Context for evaluating the user/group.
:return: True if the user is targeted for the feature flag.
:rtype: bool
"""
return self._filter.evaluate(context, **kwargs)