forked from flexcompute/Flow360
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.py
154 lines (128 loc) · 3.33 KB
/
environment.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
Environment Setup
"""
from pydantic import BaseModel
class EnvironmentConfig(BaseModel):
"""
Basic Configuration for definition environment.
"""
name: str
web_api_endpoint: str
web_url: str
aws_region: str
apikey_profile: str
portal_web_api_endpoint: str = None
def active(self):
"""
Activate the particular environment.
:return:
"""
Env.set_current(self)
def get_real_url(self, path: str):
"""
Get the real url for the particular environment.
:param path:
:return:
"""
return "/".join([self.web_api_endpoint, path])
def get_portal_real_url(self, path: str):
"""
Get the portal real url for the particular environment.
:param path:
:return:
"""
return "/".join([self.portal_web_api_endpoint, path])
def get_web_real_url(self, path: str):
"""
Get the web real url for the particular environment.
:param path:
:return:
"""
return "/".join([self.web_url, path])
dev = EnvironmentConfig(
name="dev",
web_api_endpoint="https://flow360-api.dev-simulation.cloud",
web_url="https://flow360.dev-simulation.cloud",
portal_web_api_endpoint="https://portal-api.dev-simulation.cloud",
aws_region="us-east-1",
apikey_profile="dev",
)
uat = EnvironmentConfig(
name="uat",
web_api_endpoint="https://uat-flow360-api.simulation.cloud",
web_url="https://uat-flow360.simulation.cloud",
portal_web_api_endpoint="https://uat-portal-api.simulation.cloud",
aws_region="us-gov-west-1",
apikey_profile="default",
)
prod = EnvironmentConfig(
name="prod",
web_api_endpoint="https://flow360-api.simulation.cloud",
web_url="https://flow360.simulation.cloud",
portal_web_api_endpoint="https://portal-api.simulation.cloud",
aws_region="us-gov-west-1",
apikey_profile="default",
)
FLOW360_SKIP_VERSION_CHECK = True
class Environment:
"""
Environment decorator for user interactive.
For example:
Env.dev.active()
Env.current.name == "dev"
"""
def __init__(self):
"""
Initialize the environment.
"""
self._impersonate = None
self._current = prod
@property
def current(self):
"""
Get the current environment.
:return: EnvironmentConfig
"""
return self._current
@property
def dev(self):
"""
Get the dev environment.
:return:
"""
return dev
@property
def uat(self):
"""
Get the uat environment.
:return:
"""
return uat
@property
def prod(self):
"""
Get the prod environment.
:return:
"""
return prod
def set_current(self, config: EnvironmentConfig):
"""
Set the current environment.
:param config:
:return:
"""
self._current = config
@property
def impersonate(self):
"""
Get the impersonate environment.
:return:
"""
return self._impersonate
@impersonate.setter
def impersonate(self, value):
self._impersonate = value
@impersonate.deleter
def impersonate(self):
self._impersonate = None
Env = Environment()