Commit 67e775b6 authored by Roque's avatar Roque

slapos_jio: encode monitoring url parameters

parent 304c7ddf
from ZTUtils import make_query
# TODO how to avoid hardcode here? from InstanceTree_getConnectionParameterList? # TODO how to avoid hardcode here? from InstanceTree_getConnectionParameterList?
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_landing' base_url = 'https://monitor.app.officejs.com/#/?'
url_parameter_kw = { 'page': 'ojsm_landing' }
try: instance_tree = context
instance_tree = context if context.getPortalType() in ["Software Instance", "Slave Instance"]:
if context.getPortalType() in ["Software Instance", "Slave Instance"]: instance_tree = context.getSpecialiseValue(portal_type="Instance Tree")
instance_tree = context.getSpecialise() connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict()
connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict() if all(key in connection_parameter_dict for key in ('username', 'password', 'url')):
connection_url = '&url=%s'% connection_parameter_dict['url'] + '&username=%s'% connection_parameter_dict['username'] + '&password=%s'% connection_parameter_dict['password'] url_parameter_kw['username'] = connection_parameter_dict['username']
except (AttributeError, TypeError) as _: url_parameter_kw['password'] = connection_parameter_dict['password']
connection_url = '' url_parameter_kw['url'] = connection_parameter_dict['url']
if context.getPortalType() == "Instance Tree": if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True): for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True):
if connection_parameter['connection_key'] == "monitor-setup-url": if 'connection_key' in connection_parameter and connection_parameter['connection_key'] == "monitor-setup-url":
# connection_parameter['connection_value'] looks like #page=settings_configurator&url=xx/public/feeds&username=admin&password=yy return connection_parameter['connection_value']
# workaround until settings_configurator is c on software releases / buildout cfg files are updated url_parameter_kw['query'] = 'portal_type:"Instance Tree" AND title:"%s"' % context.getTitle()
return connection_parameter['connection_value'].replace("settings_configurator", "ojsm_landing")
return base_url + '&query=portal_type:"Instance Tree" AND title:"%s"' % context.getTitle() + connection_url
if context.getPortalType() in ["Software Instance", "Slave Instance"]: if context.getPortalType() in ["Software Instance", "Slave Instance"]:
return base_url + '&query=portal_type:"Software Instance" AND title:"%s" AND ' % context.getTitle() + 'specialise_title:"%s"' % context.getSpecialiseTitle() + connection_url url_parameter_kw['query'] = 'portal_type:"Software Instance" AND title:"%s" AND ' % context.getTitle() + 'specialise_title:"%s"' % context.getSpecialiseTitle()
return base_url + make_query(url_parameter_kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment