Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions parameter-sets/basic-auth/parameter-set.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
"credentialRequestSettings": {
"type": "BASIC"
}
},
{
"name": "old_domain",
"label": "Old domain",
"type": "STRING",
"description": "(optional)"
},
{
"name": "new_domain",
"label": "New domain",
"type": "STRING",
"description": "(optional)"
}
]
}
42 changes: 42 additions & 0 deletions python-lib/osisoft_domain_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
48 changes: 35 additions & 13 deletions resource/browse_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataiku
from osisoft_client import OSIsoftClient
from osisoft_plugin_common import get_credentials, build_select_choices, check_debug_mode
from osisoft_domain_handling import DomainHandler


def do(payload, config, plugin_config, inputs):
Expand All @@ -11,6 +12,7 @@ def do(payload, config, plugin_config, inputs):
return {"choices": [{"label": "Requires DSS v10.0.4 or above. Please use the OSIsoft Search custom dataset instead"}]}
elif config.get("credentials") == {}:
return {"choices": [{"label": "Pick a credential"}]}
domain_handler = DomainHandler(config)

auth_type, username, password, server_url, is_ssl_check_disabled, credential_error = get_credentials(config, can_raise=False)

Expand All @@ -37,14 +39,20 @@ def do(payload, config, plugin_config, inputs):

if parameter_name == "server_name":
choices = []
choices.extend(client.get_asset_servers(can_raise=False))
choices.extend(
domain_handler.ui_side_url(client.get_asset_servers(can_raise=False))
)
return build_select_choices(choices)

if parameter_name == "database_name":
choices = []
next_url = config.get("server_name")
if next_url:
choices.extend(client.get_next_choices(next_url, "Self"))
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(domain_handler.client_side_url(next_url), "Self")
)
)
return build_select_choices(choices)
else:
return build_select_choices()
Expand All @@ -58,7 +66,9 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices()
next_url = next_links + "/elementcategories"
choices.extend(client.get_next_choices(next_url, "Self", use_name_as_link=True))
choices.extend(
client.get_next_choices(domain_handler.client_side_url(next_url), "Self", use_name_as_link=True)
)
return build_select_choices(choices)

if parameter_name == "element_template":
Expand All @@ -70,7 +80,7 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices()
next_url = next_links + "/elementtemplates"
choices.extend(client.get_next_choices(next_url, "Self", use_name_as_link=True, filter={'InstanceType': 'Element'}))
choices.extend(client.get_next_choices(domain_handler.client_side_url(next_url), "Self", use_name_as_link=True, filter={'InstanceType': 'Element'}))
choices.append({"label": "✍️ Enter manually", "value": "_DKU_manual_input"})
choices.append({"label": "🗄️ Use a variable", "value": "_DKU_variable_select"})
return build_select_choices(choices)
Expand Down Expand Up @@ -98,14 +108,16 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices()
next_url = next_links + "/attributecategories"
choices.extend(client.get_next_choices(next_url, "Self", use_name_as_link=True))
next_url = domain_handler.ui_side_url(next_url)
choices.extend(client.get_next_choices(domain_handler.client_side_url(next_url), "Self", use_name_as_link=True))
return build_select_choices(choices)

if parameter_name == "element_1":
choices = []
next_url = config.get("database_name", None)
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(client.get_next_choices_as_json(next_url+"/elements", "Elements"))
choices.extend(domain_handler.ui_side_url(client.get_next_choices_as_json(next_url+"/elements", "Elements")))
return build_select_choices(choices)
else:
return build_select_choices()
Expand All @@ -116,8 +128,9 @@ def do(payload, config, plugin_config, inputs):
json_string = config.get("element_{}".format(element_number - 1), "{}")
json_choice = json.loads(json_string)
next_url = json_choice.get("url")
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(client.get_next_choices_as_json(next_url, "Elements"))
choices.extend(domain_handler.ui_side_url(client.get_next_choices_as_json(next_url, "Elements")))
return build_select_choices(choices)
else:
return build_select_choices()
Expand All @@ -128,10 +141,14 @@ def do(payload, config, plugin_config, inputs):
json_string = json_string or "{}"
json_choice = json.loads(json_string)
next_url = json_choice.get("url")
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(client.get_next_choices(
next_url.replace("/elements", "/attributes").replace("/{}/attributes".format(client.endpoint.get_web_api_path()), "/{}/elements".format(client.endpoint.get_web_api_path())),
"Self")
choices.extend(
domain_handler.ui_site_url(
client.get_next_choices(
next_url.replace("/elements", "/attributes").replace("/{}/attributes".format(client.endpoint.get_web_api_path()), "/{}/elements".format(client.endpoint.get_web_api_path())),
"Self")
)
)
return build_select_choices(choices)
else:
Expand All @@ -143,10 +160,15 @@ def do(payload, config, plugin_config, inputs):
json_string = json_string or "{}"
json_choice = json.loads(json_string)
next_url = json_choice.get("url")
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(client.get_next_choices(
next_url.replace("/elements", "/eventframes").replace("/{}/eventframes".format(client.endpoint.get_web_api_path()), "/{}/elements".format(client.endpoint.get_web_api_path())),
"Self")
choices.extend(
domain_handler.ui_site_url(
client.get_next_choices(
next_url.replace("/elements", "/eventframes").replace("/{}/eventframes".format(client.endpoint.get_web_api_path()), "/{}/elements".format(client.endpoint.get_web_api_path())),
"Self"
)
)
)
return build_select_choices(choices)
else:
Expand Down
30 changes: 25 additions & 5 deletions resource/browse_event_frames.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from osisoft_client import OSIsoftClient
from osisoft_plugin_common import get_credentials, build_select_choices, build_requests_params
from osisoft_domain_handling import DomainHandler


def do(payload, config, plugin_config, inputs):
Expand All @@ -9,6 +10,7 @@ def do(payload, config, plugin_config, inputs):
return build_select_choices("Requires DSS v10.0.4 or above. Please use the OSIsoft Search custom dataset instead")
elif config.get("credentials") == {}:
return build_select_choices("Pick a credential")
domain_handler = DomainHandler(config)

auth_type, username, password, server_url, is_ssl_check_disabled, credential_error = get_credentials(config, can_raise=False)

Expand All @@ -32,14 +34,19 @@ def do(payload, config, plugin_config, inputs):

if parameter_name == "server_name":
choices = []
choices.extend(client.get_asset_servers())
choices.extend(domain_handler.ui_side_url(client.get_asset_servers()))
return build_select_choices(choices)

if parameter_name == "database_name":
choices = []
next_url = config.get("server_name")
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(client.get_next_choices(next_url, "Self"))
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self")
)
)
return build_select_choices(choices)
else:
return build_select_choices()
Expand All @@ -53,7 +60,12 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices()
next_url = next_links + "/elementcategories"
choices.extend(client.get_next_choices(next_url, "Self", use_name_as_link=True))
next_url = domain_handler.client_side_url(next_url)
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self", use_name_as_link=True)
)
)
return build_select_choices(choices)

if parameter_name == "template_name":
Expand All @@ -65,7 +77,10 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices()
next_url = next_links + "/elementtemplates"
next_choices = client.get_next_choices(next_url, "Self", use_name_as_link=True, filter={'InstanceType': 'EventFrame'})
next_url = domain_handler.client_side_url(next_url)
next_choices = domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self", use_name_as_link=True, filter={'InstanceType': 'EventFrame'})
)
choices.extend(next_choices)
return build_select_choices(choices)

Expand All @@ -75,13 +90,18 @@ def do(payload, config, plugin_config, inputs):
if not next_links:
return build_select_choices(choices)
next_url = next_links + "/eventframes"
next_url = domain_handler.client_side_url(next_url)
params = build_requests_params(
**config
)
endpoint_name = "Self"
if config.get("must_retrieve_metrics"):
endpoint_name = config.get("data_type", "Self")
choices.extend(client.get_next_choices(next_url, endpoint_name, params=params))
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, endpoint_name, params=params)
)
)
return build_select_choices(choices)

return build_select_choices()
8 changes: 7 additions & 1 deletion resource/browse_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from osisoft_client import OSIsoftClient
from osisoft_plugin_common import get_credentials, build_select_choices, check_debug_mode
from osisoft_domain_handling import DomainHandler


def do(payload, config, plugin_config, inputs):
Expand All @@ -9,6 +10,7 @@ def do(payload, config, plugin_config, inputs):
return {"choices": [{"label": "Requires DSS v10.0.4 or above. Please use the OSIsoft Search custom dataset instead"}]}
elif config.get("credentials") == {}:
return {"choices": [{"label": "Pick a credential"}]}
domain_handler = DomainHandler(config)

auth_type, username, password, server_url, is_ssl_check_disabled, credential_error = get_credentials(config, can_raise=False)

Expand All @@ -35,7 +37,11 @@ def do(payload, config, plugin_config, inputs):

if parameter_name == "data_server_url":
choices = []
choices.extend(client.get_data_servers(can_raise=False))
choices.extend(
domain_handler.ui_side_url(
client.get_data_servers(can_raise=False)
)
)
return build_select_choices(choices)

return build_select_choices()