-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
61 lines (50 loc) · 1.43 KB
/
example.py
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
54
55
56
57
58
59
60
61
import asyncio
from pyflipt import (
ComparisonType,
Constraint,
Flag,
MatchType,
OperatorType,
Rule,
Segment,
get_client,
)
FLIPT_API_BASE_URL = "http://localhost:8083/api/v1"
async def main():
pf = get_client(FLIPT_API_BASE_URL)
flag = Flag(key="myflag", name="My Flag", enabled=True)
await pf.create(flag)
segments = [
Segment(key="user", name="Selected users", match_type=MatchType.ANY.value),
Segment(
key="account", name="Selected accounts", match_type=MatchType.ANY.value
),
]
for segment in segments:
await pf.create(segment)
constraints = [
Constraint(
segment_key=segments[0].key,
type=ComparisonType.STRING.value,
property="user",
operator=OperatorType.EQ,
value="[email protected]",
),
Constraint(
segment_key=segments[1].key,
type=ComparisonType.STRING.value,
property="account",
operator=OperatorType.EQ,
value="some-client-account",
),
]
for constraint in constraints:
await pf.create(constraint)
rules = []
for rank, segment in enumerate(segments):
rules.append(Rule(flag_key=flag.key, segment_key=segment.key, rank=rank + 1))
for rule in rules:
await pf.create(rule)
await pf.close()
if __name__ == "__main__":
asyncio.run(main())