-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_value_wrapper.py
More file actions
40 lines (36 loc) · 1.46 KB
/
config_value_wrapper.py
File metadata and controls
40 lines (36 loc) · 1.46 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
from datetime import date, datetime, timezone
import prefab_pb2 as Prefab
class ConfigValueWrapper:
@staticmethod
def wrap(value, confidential=None):
value_type = type(value)
if value_type == Prefab.ConfigValue:
return value
elif value_type == int:
return Prefab.ConfigValue(int=value, confidential=confidential)
elif value_type == float:
return Prefab.ConfigValue(double=value, confidential=confidential)
elif value_type == bool:
return Prefab.ConfigValue(bool=value, confidential=confidential)
elif value_type == list:
return Prefab.ConfigValue(
string_list=Prefab.StringList(values=[str(x) for x in value]),
confidential=confidential,
)
elif value_type == datetime:
return Prefab.ConfigValue(
string=ConfigValueWrapper._format_date_time(value),
confidential=confidential,
)
elif value_type == date:
return Prefab.ConfigValue(
string=ConfigValueWrapper._format_date_time(
datetime.combine(value, datetime.min.time(), timezone.utc)
),
confidential=confidential,
)
else:
return Prefab.ConfigValue(string=value, confidential=confidential)
@staticmethod
def _format_date_time(value: datetime):
return value.strftime("%Y-%m-%dT%H:%M:%SZ")