-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathosisoft_domain_handling.py
More file actions
42 lines (36 loc) · 1.28 KB
/
osisoft_domain_handling.py
File metadata and controls
42 lines (36 loc) · 1.28 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
class DomainHandler():
def __init__(self, config):
credentials = config.get('credentials', {})
self.old_domain = credentials.get("old_domain")
self.new_domain = credentials.get("new_domain")
def ui_side_url(self, input):
if not self.old_domain:
return input
if isinstance(input, list):
return swap_in_list(input, self.new_domain, self.old_domain)
input = swap(input, self.new_domain, self.old_domain)
return input
def client_side_url(self, url):
if not self.old_domain:
return url
url = swap(url, self.old_domain, self.new_domain)
return url
def swap_in_list(items, domain_to_replace, domain_to_replace_with):
new_items = []
for item in items:
value = item.get("value")
label = item.get("label")
value = swap(value, domain_to_replace, domain_to_replace_with)
new_items.append(
{
"value": "{}".format(value),
"label": "{}".format(label)
}
)
return new_items
def swap(url, domain_to_replace, domain_to_replace_with):
if not url:
return url
if domain_to_replace in url:
return url.replace(domain_to_replace, domain_to_replace_with)
return url