Commit 13a7da98 authored by Roque's avatar Roque

slapos_panel: include connection parameters in monitoring links (fix)

- do not return url if connection parameters are not available
- use byteify instead of encode to handle dict json data
- drop obsolete setting_configurator url
- drop json loads/dumps
- set slapos master url parameter
parent 5c050627
# TODO how to avoid hardcode here? from InstanceTree_getConnectionParameterList?
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_landing'
from ZTUtils import make_query
request = context.REQUEST
try:
instance_tree = context
if context.getPortalType() in ["Software Instance", "Slave Instance"]:
instance_tree = context.getSpecialise()
connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict()
connection_url = '&url=%s'% connection_parameter_dict['url'] + '&username=%s'% connection_parameter_dict['username'] + '&password=%s'% connection_parameter_dict['password']
except (AttributeError, TypeError) as _:
connection_url = ''
# TODO how to avoid hardcode here?
base_url = 'https://monitor.app.officejs.com/#/?'
url_parameter_kw = { 'page': 'ojsm_landing' }
if request is not None :
url_parameter_kw['slapos_master_url'] = request["BASE0"]
instance_tree = context
if context.getPortalType() in ["Software Instance", "Slave Instance"]:
instance_tree = context.getSpecialiseValue(portal_type="Instance Tree")
connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict()
if all(key in connection_parameter_dict for key in ('username', 'password', 'url')):
url_parameter_kw['username'] = connection_parameter_dict['username']
url_parameter_kw['password'] = connection_parameter_dict['password']
url_parameter_kw['url'] = connection_parameter_dict['url']
else:
return ''
if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True):
if connection_parameter['connection_key'] == "monitor-setup-url":
# connection_parameter['connection_value'] looks like #page=settings_configurator&url=xx/public/feeds&username=admin&password=yy
# workaround until settings_configurator is c on software releases / buildout cfg files are updated
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
url_parameter_kw['query'] = 'portal_type:"Instance Tree" AND title:"%s"' % context.getTitle()
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)
import json
def getCredentialFromUrl(url_string):
username = password = url = ''
param_list = url_string.split('#')
......@@ -13,17 +11,16 @@ def getCredentialFromUrl(url_string):
username = value
elif key == 'password':
password = value
return (url, username, password,)
instance_tree = context
if instance_tree.getSlapState() == 'destroy_requested':
return json.dumps({})
return {}
instance = instance_tree.getSuccessorValue()
if instance is None or instance.getSlapState() == 'destroy_requested':
return json.dumps({})
return {}
parameter_dict = instance.getConnectionXmlAsDict()
......@@ -38,10 +35,10 @@ if url_string:
else:
url, username, password = getCredentialFromUrl(url_string)
else:
return json.dumps({})
return {}
return json.dumps({
return {
'username': username,
'password': password,
'url': url
})
}
\ No newline at end of file
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