-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_env.py
More file actions
44 lines (29 loc) · 849 Bytes
/
_env.py
File metadata and controls
44 lines (29 loc) · 849 Bytes
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
import os
class EnvValue:
LOCAL: str = "local"
TEST: str = "test"
PRE: str = "pre"
PROD: str = "prod"
class Env:
@property
def env(self) -> str:
return os.getenv("ENV", EnvValue.LOCAL).lower()
def is_prod(self) -> bool:
return self.env == EnvValue.PROD
def is_pre(self) -> bool:
return self.env == EnvValue.PRE
def is_local(self) -> bool:
return self.env == EnvValue.LOCAL
def is_test(self) -> bool:
return self.env == EnvValue.TEST
@staticmethod
def is_k8s() -> bool:
if os.getenv("KUBERNETES_SERVICE_HOST"):
return True
if os.path.isfile("/var/run/secrets/kubernetes.io/serviceaccount/token"):
return True
return False
def __str__(self):
return self.env
env = Env()
__all__ = ["env"]