def source_info(req, service_name): service = Service(name=service_name) input_dict = { 'cluster_id': req.zato.cluster_id, 'name': service_name } zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.get-source-info', input_dict) if zato_path('response.item').get_from(zato_message) is not None: msg_item = zato_message.response.item service.id = msg_item.service_id.text source = msg_item.source.text.decode('base64') if msg_item.source else '' if source: source_html = highlight(source, PythonLexer(stripnl=False), HtmlFormatter(linenos='table')) service.source_info = SourceInfo() service.source_info.source = source service.source_info.source_html = source_html service.source_info.path = msg_item.source_path.text service.source_info.hash = msg_item.source_hash.text service.source_info.hash_method = msg_item.source_hash_method.text service.source_info.server_name = msg_item.server_name.text return_data = { 'cluster_id':req.zato.cluster_id, 'service':service, } return TemplateResponse(req, 'zato/service/source-info.html', return_data)
def source_info(req, service_name): service = Service(name=service_name) input_dict = {"cluster_id": req.zato.cluster_id, "name": service_name} response = req.zato.client.invoke("zato.service.get-source-info", input_dict) if response.has_data: service.id = response.data.service_id source = response.data.source.decode("base64") if response.data.source else "" if source: source_html = highlight(source, PythonLexer(stripnl=False), HtmlFormatter(linenos="table")) service.source_info = SourceInfo() service.source_info.source = source service.source_info.source_html = source_html service.source_info.path = response.data.source_path service.source_info.hash = response.data.source_hash service.source_info.hash_method = response.data.source_hash_method service.source_info.server_name = response.data.server_name return_data = {"cluster_id": req.zato.cluster_id, "service": service} return TemplateResponse(req, "zato/service/source-info.html", return_data)
def source_info(req, service_name): service = Service(name=service_name) input_dict = { 'cluster_id': req.zato.cluster_id, 'name': service_name } response = req.zato.client.invoke('zato.service.get-source-info', input_dict) if response.has_data: service.id = response.data.service_id source = response.data.source.decode('base64').decode('utf-8') if response.data.source else '' if source: source_html = highlight(source, PythonLexer(stripnl=False), HtmlFormatter(linenos='table')) service.source_info = SourceInfo() service.source_info.source = source service.source_info.source_html = source_html service.source_info.path = response.data.source_path service.source_info.hash = response.data.source_hash service.source_info.hash_method = response.data.source_hash_method service.source_info.server_name = response.data.server_name return_data = { 'cluster_id':req.zato.cluster_id, 'service':service, } return TemplateResponse(req, 'zato/service/source-info.html', return_data)
def source_info(req, service_name): service = Service(name=service_name) input_dict = {'cluster_id': req.zato.cluster_id, 'name': service_name} response = req.zato.client.invoke('zato.service.get-source-info', input_dict) if response.has_data: service.id = response.data.service_id source = b64decode( response.data.source) if response.data.source else '' if source: source_html = highlight(source, PythonLexer(stripnl=False), HtmlFormatter(linenos='table')) service.source_info = SourceCodeInfo() service.source_info.source = source service.source_info.source_html = source_html service.source_info.path = response.data.source_path service.source_info.hash = response.data.source_hash service.source_info.hash_method = response.data.source_hash_method service.source_info.server_name = response.data.server_name return_data = { 'cluster_id': req.zato.cluster_id, 'service': service, } return TemplateResponse(req, 'zato/service/source-info.html', return_data)
def request_response(req, service_name): service = Service(name=service_name) pretty_print = asbool(req.GET.get('pretty_print')) input_dict = { 'name': service_name, 'cluster_id': req.zato.cluster_id } zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.get-request-response', input_dict) if zato_path('response.item').get_from(zato_message) is not None: item = zato_message.response.item request = (item.sample_req.text if item.sample_req.text else '').decode('base64') request_data_format = known_data_format(request) if request_data_format: if pretty_print: request = get_pretty_print(request, request_data_format) service.sample_req_html = highlight(request, data_format_lexer[request_data_format](), HtmlFormatter(linenos='table')) response = (item.sample_resp.text if item.sample_resp.text else '').decode('base64') response_data_format = known_data_format(response) if response_data_format: if pretty_print: response = get_pretty_print(response, response_data_format) service.sample_resp_html = highlight(response, data_format_lexer[response_data_format](), HtmlFormatter(linenos='table')) service.sample_req = request service.sample_resp = response ts = {} for name in('req', 'resp'): full_name = 'sample_{}_ts'.format(name) value = getattr(item, full_name).text or '' if value: value = from_utc_to_user(value+'+00:00', req.zato.user_profile) ts[full_name] = value service.id = item.service_id.text service.sample_cid = item.sample_cid.text service.sample_req_ts = ts['sample_req_ts'] service.sample_resp_ts = ts['sample_resp_ts'] service.sample_req_resp_freq = item.sample_req_resp_freq.text return_data = { 'cluster_id': req.zato.cluster_id, 'service': service, 'pretty_print': not pretty_print, } return TemplateResponse(req, 'zato/service/request-response.html', return_data)
def request_response(req, service_name): service = Service(name=service_name) pretty_print = asbool(req.GET.get('pretty_print')) input_dict = { 'name': service_name, 'cluster_id': req.zato.cluster_id } service_response = req.zato.client.invoke('zato.service.get-request-response', input_dict) if service_response.ok: request = (service_response.data.sample_req if service_response.data.sample_req else '').decode('base64') request_data_format = known_data_format(request) if request_data_format: if pretty_print: request = get_pretty_print(request, request_data_format) service.sample_req_html = highlight(request, data_format_lexer[request_data_format](), HtmlFormatter(linenos='table')) response = (service_response.data.sample_resp if service_response.data.sample_resp else '').decode('base64') response_data_format = known_data_format(response) if response_data_format: if pretty_print: response = get_pretty_print(response, response_data_format) service.sample_resp_html = highlight(response, data_format_lexer[response_data_format](), HtmlFormatter(linenos='table')) service.sample_req = request service.sample_resp = response ts = {} for name in('req', 'resp'): full_name = 'sample_{}_ts'.format(name) value = getattr(service_response.data, full_name, '') if value: value = from_utc_to_user(value+'+00:00', req.zato.user_profile) ts[full_name] = value service.id = service_response.data.service_id service.sample_cid = service_response.data.sample_cid service.sample_req_ts = ts['sample_req_ts'] service.sample_resp_ts = ts['sample_resp_ts'] service.sample_req_resp_freq = service_response.data.sample_req_resp_freq return_data = { 'cluster_id': req.zato.cluster_id, 'service': service, 'pretty_print': not pretty_print, } return TemplateResponse(req, 'zato/service/request-response.html', return_data)
def add_soap_services(self, session, cluster, admin_invoke_sec, pubapi_sec): """ Adds these Zato internal services that can be accessed through SOAP requests. """ # # HTTPSOAP + services # for name, impl_name in zato_services.iteritems(): service = Service(None, name, True, impl_name, True, cluster) session.add(service) # Add the HTTP channel for WSDLs if name == 'zato.service.get-wsdl': http_soap = HTTPSOAP( None, '{}.soap'.format(name), True, True, 'channel', 'plain_http', None, '/zato/wsdl', None, '', None, None, service=service, cluster=cluster) session.add(http_soap) elif name == 'zato.service.invoke': self.add_admin_invoke(session, cluster, service, admin_invoke_sec) elif name == 'zato.pubsub.rest-handler': self.add_pubsub_rest_handler(session, cluster, service) session.add(get_http_soap_channel(name, service, cluster, pubapi_sec)) session.add(get_http_json_channel(name, service, cluster, pubapi_sec))
def add_service(self, name, impl_name, is_internal, deployment_time, details, source_info): """ Adds information about the server's service into the ODB. """ try: service = Service(None, name, True, impl_name, is_internal, self.cluster) self._session.add(service) try: self._session.commit() except (IntegrityError, ProgrammingError), e: logger.log(TRACE1, 'IntegrityError (Service), e:[%s]', format_exc(e).decode('utf-8')) self._session.rollback() service = self._session.query(Service).\ join(Cluster, Service.cluster_id==Cluster.id).\ filter(Service.name==name).\ filter(Cluster.id==self.cluster.id).\ one() self.add_deployed_service(deployment_time, details, service, source_info) return service.id, service.is_active, service.slow_threshold
def test_response(self): request = {'cluster_id': rand_int()} expected_keys = get_data().keys() expected_data = tuple(get_data() for x in range(rand_int(10))) expected = Expected() for datum in expected_data: item = Service() for key in expected_keys: value = getattr(datum, key) setattr(item, key, value) expected.add(item) instance = self.invoke(GetList, request, expected) response = loads(instance.response.payload.getvalue())[ GetList.SimpleIO.response_elem] for idx, item in enumerate(response): expected = expected_data[idx] given = Bunch(item) for key in expected_keys: given_value = getattr(given, key) expected_value = getattr(expected, key) eq_(given_value, expected_value)
def add_soap_services(self, session, cluster, admin_invoke_sec, pubapi_sec): """ Adds these Zato internal services that can be accessed through SOAP requests. """ # # HTTPSOAP + services # zato_soap_channels = [] for name, impl_name in zato_services.iteritems(): service = Service(None, name, True, impl_name, True, cluster) session.add(service) # Add the HTTP channel for WSDLs if name == 'zato.service.get-wsdl': http_soap = HTTPSOAP(None, '{}.soap'.format(name), True, True, 'channel', 'plain_http', None, '/zato/wsdl', None, '', None, None, service=service, cluster=cluster) session.add(http_soap) elif name == 'zato.service.invoke': self.add_admin_invoke(session, cluster, service, admin_invoke_sec) zato_soap = HTTPSOAP(None, name, True, True, 'channel', 'soap', None, '/zato/soap', None, name, '1.1', SIMPLE_IO.FORMAT.XML, service=service, cluster=cluster, security=pubapi_sec) session.add(zato_soap) json_url_path = '/zato/json/{}'.format(name) json_http = HTTPSOAP(None, '{}.json'.format(name), True, True, 'channel', 'plain_http', None, json_url_path, None, '', None, SIMPLE_IO.FORMAT.JSON, service=service, cluster=cluster, security=pubapi_sec) session.add(json_http)
def add_internal_services(self, session, cluster, admin_invoke_sec, pubapi_sec, internal_invoke_sec, live_browser_sec): """ Adds these Zato internal services that can be accessed through SOAP requests. """ # # HTTPSOAP + services # for name, impl_name in zato_services.iteritems(): service = Service(None, name, True, impl_name, True, cluster) session.add(service) # Add the HTTP channel for WSDLs if name == 'zato.service.get-wsdl': http_soap = HTTPSOAP(None, '{}.soap'.format(name), True, True, 'channel', 'plain_http', None, '/zato/wsdl', None, '', None, None, service=service, cluster=cluster) session.add(http_soap) elif name == 'zato.service.invoke': self.add_admin_invoke(session, cluster, service, admin_invoke_sec) self.add_internal_invoke(session, cluster, service, internal_invoke_sec) elif name == 'zato.pubsub.rest-handler': self.add_pubsub_rest_handler(session, cluster, service) elif name == 'zato.security.jwt.log-in': self.add_jwt_log_in(session, cluster, service) elif name == 'zato.security.jwt.log-out': self.add_jwt_log_out(session, cluster, service) elif name == 'zato.message.live-browser.dispatch': self.add_live_browser(session, cluster, service, live_browser_sec) elif 'apispec.pub' in name: self.add_apispec_pub(session, cluster, service) session.add( get_http_soap_channel(name, service, cluster, pubapi_sec)) session.add( get_http_json_channel(name, service, cluster, pubapi_sec))
def request_response(req, service_name): service = Service(name=service_name) pretty_print = asbool(req.GET.get("pretty_print")) input_dict = {"name": service_name, "cluster_id": req.zato.cluster_id} service_response = req.zato.client.invoke("zato.service.get-request-response", input_dict) if service_response.ok: request = (service_response.data.sample_req if service_response.data.sample_req else "").decode("base64") request_data_format = known_data_format(request) if request_data_format: if pretty_print: request = get_pretty_print(request, request_data_format) service.sample_req_html = highlight( request, data_format_lexer[request_data_format](), HtmlFormatter(linenos="table") ) response = (service_response.data.sample_resp if service_response.data.sample_resp else "").decode("base64") response_data_format = known_data_format(response) if response_data_format: if pretty_print: response = get_pretty_print(response, response_data_format) service.sample_resp_html = highlight( response, data_format_lexer[response_data_format](), HtmlFormatter(linenos="table") ) service.sample_req = request service.sample_resp = response ts = {} for name in ("req", "resp"): full_name = "sample_{}_ts".format(name) value = getattr(service_response.data, full_name, "") if value: value = from_utc_to_user(value + "+00:00", req.zato.user_profile) ts[full_name] = value service.id = service_response.data.service_id service.sample_cid = service_response.data.sample_cid service.sample_req_ts = ts["sample_req_ts"] service.sample_resp_ts = ts["sample_resp_ts"] service.sample_req_resp_freq = service_response.data.sample_req_resp_freq return_data = {"cluster_id": req.zato.cluster_id, "service": service, "pretty_print": not pretty_print} return TemplateResponse(req, "zato/service/request-response.html", return_data)
def test_response(self): request = {'cluster_id': rand_int(), 'name': rand_string()} expected_id = rand_int() expected_name = rand_string() expected_is_active = rand_bool() expected_impl_name = rand_string() expected_is_internal = rand_bool() service = Service() service.id = expected_id service.name = expected_name service.is_active = expected_is_active service.impl_name = expected_impl_name service.is_internal = expected_is_internal expected = Expected() expected.add(service) instance = self.invoke(GetByName, request, expected) response = Bunch( loads(instance.response.payload.getvalue()) ['zato_service_get_by_name_response']) eq_(response.id, expected_id) eq_(response.name, expected_name) eq_(response.is_active, expected_is_active) eq_(response.impl_name, expected_impl_name) eq_(response.is_internal, expected_is_internal) eq_(response.usage, 0)
def wsdl(req, service_name): service = Service(name=service_name) has_wsdl = False wsdl_public_url = get_public_wsdl_url(req.zato.cluster, service_name) input_dict = {"name": service_name, "cluster_id": req.zato.cluster_id} response = req.zato.client.invoke("zato.service.has-wsdl", input_dict) if response.has_data: service.id = response.data.service_id has_wsdl = response.data.has_wsdl return_data = { "cluster_id": req.zato.cluster_id, "service": service, "has_wsdl": has_wsdl, "wsdl_public_url": wsdl_public_url, } return TemplateResponse(req, "zato/service/wsdl.html", return_data)
def wsdl(req, service_name): service = Service(name=service_name) has_wsdl = False wsdl_public_url = get_public_wsdl_url(req.zato.cluster, service_name) input_dict = {'name': service_name, 'cluster_id': req.zato.cluster_id} response = req.zato.client.invoke('zato.service.has-wsdl', input_dict) if response.has_data: service.id = response.data.service_id has_wsdl = response.data.has_wsdl return_data = { 'cluster_id': req.zato.cluster_id, 'service': service, 'has_wsdl': has_wsdl, 'wsdl_public_url': wsdl_public_url, } return TemplateResponse(req, 'zato/service/wsdl.html', return_data)
def setUp(self): self.service_class = Create self.sio = self.service_class.SimpleIO self.id = rand_int() self.def_id = rand_int() self.name = rand_string() self.mock_data = { 'odb': [{'session.query.filter.filter.filter.first': False}, {'session.query.filter.filter.first': Service()}, ], }
def setUp(self): self.service_class = Edit self.sio = self.service_class.SimpleIO self.id = rand_int() self.def_id = rand_int() self.name = rand_string() self.mock_data = { 'odb': [{'session.query.filter.filter.filter.filter.first': False}, {'session.query.filter.filter.first': Service()}, {'session.query.filter_by.one': ChannelAMQP(self.id)}, ] }
def test_response(self): request = {'cluster_id':rand_int(), 'name':rand_string()} expected_id = rand_int() expected_name = rand_string() expected_is_active = rand_bool() expected_impl_name = rand_string() expected_is_internal = rand_bool() service = Service() service.id = expected_id service.name = expected_name service.is_active = expected_is_active service.impl_name = expected_impl_name service.is_internal = expected_is_internal expected = Expected() expected.add(service) instance = self.invoke(GetByName, request, expected) response = Bunch(loads(instance.response.payload.getvalue())['response']) eq_(response.id, expected_id) eq_(response.name, expected_name) eq_(response.is_active, expected_is_active) eq_(response.impl_name, expected_impl_name) eq_(response.is_internal, expected_is_internal) eq_(response.usage, 0)
def _get_service(req, name): """ Returns service details by its name. """ service = Service(name=name) input_dict = {'name': name, 'cluster_id': req.zato.cluster_id} response = req.zato.client.invoke('zato.service.get-by-name', input_dict) if response.has_data: for name in ('id', 'slow_threshold'): setattr(service, name, getattr(response.data, name)) return service
def wsdl(req, service_name): service = Service(name=service_name) has_wsdl = False wsdl_public_url = get_public_wsdl_url(req.zato.cluster, service_name) input_dict = { 'name': service_name, 'cluster_id': req.zato.cluster_id } zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.has-wsdl', input_dict) if zato_path('response.item').get_from(zato_message) is not None: service.id = zato_message.response.item.service_id.text has_wsdl = is_boolean(zato_message.response.item.has_wsdl.text) return_data = { 'cluster_id':req.zato.cluster_id, 'service':service, 'has_wsdl':has_wsdl, 'wsdl_public_url':wsdl_public_url, } return TemplateResponse(req, 'zato/service/wsdl.html', return_data)
def wsdl(req, service_name): service = Service(name=service_name) has_wsdl = False wsdl_public_url = get_public_wsdl_url(req.zato.cluster, service_name) input_dict = { 'name': service_name, 'cluster_id': req.zato.cluster_id } response = req.zato.client.invoke('zato.service.has-wsdl', input_dict) if response.has_data: service.id = response.data.service_id has_wsdl = response.data.has_wsdl return_data = { 'cluster_id':req.zato.cluster_id, 'service':service, 'has_wsdl':has_wsdl, 'wsdl_public_url':wsdl_public_url, } return TemplateResponse(req, 'zato/service/wsdl.html', return_data)
def add_sso_endpoints(self, session, cluster): from zato.common.api import DATA_FORMAT from zato.common.odb.model import HTTPSOAP, Service data = [ # Users ['zato.sso.user.create', 'zato.server.service.internal.sso.user.Create', '/zato/sso/user/create'], ['zato.sso.user.signup', 'zato.server.service.internal.sso.user.Signup', '/zato/sso/user/signup'], ['zato.sso.user.approve', 'zato.server.service.internal.sso.user.Approve', '/zato/sso/user/approve'], ['zato.sso.user.reject', 'zato.server.service.internal.sso.user.Reject', '/zato/sso/user/reject'], ['zato.sso.user.login', 'zato.server.service.internal.sso.user.Login', '/zato/sso/user/login'], ['zato.sso.user.logout', 'zato.server.service.internal.sso.user.Logout', '/zato/sso/user/logout'], ['zato.sso.user.user', 'zato.server.service.internal.sso.user.User', '/zato/sso/user'], ['zato.sso.user.password', 'zato.server.service.internal.sso.user.Password', '/zato/sso/user/password'], ['zato.sso.user.search', 'zato.server.service.internal.sso.user.Search', '/zato/sso/user/search'], ['zato.sso.user.totp', 'zato.server.service.internal.sso.user.TOTP', '/zato/sso/user/totp'], ['zato.sso.user.lock', 'zato.server.service.internal.sso.user.Lock', '/zato/sso/user/lock'], # Linked accounts ['zato.sso.user.linked-auth', 'zato.server.service.internal.sso.user.LinkedAuth', '/zato/sso/user/linked'], # User sessions ['zato.sso.session.session', 'zato.server.service.internal.sso.session.Session', '/zato/sso/user/session'], ['zato.sso.session.session-list', 'zato.server.service.internal.sso.session.SessionList', '/zato/sso/user/session/list'], # Password reset ['zato.sso.user.password-reset.begin', 'zato.server.service.internal.sso.password_reset.Begin', '/zato/sso/user/password/reset/begin'], ['zato.sso.user.password-reset.complete', 'zato.server.service.internal.sso.password_reset.Complete', '/zato/sso/user/password/reset/complete'], # User attributes ['zato.sso.user-attr.user-attr', 'zato.server.service.internal.sso.user_attr.UserAttr', '/zato/sso/user/attr'], ['zato.sso.user-attr.user-attr-exists', 'zato.server.service.internal.sso.user_attr.UserAttrExists', '/zato/sso/user/attr/exists'], ['zato.sso.user-attr.user-attr-names', 'zato.server.service.internal.sso.user_attr.UserAttrNames', '/zato/sso/user/attr/names'], # Session attributes ['zato.sso.session-attr.session-attr', 'zato.server.service.internal.sso.session_attr.SessionAttr', '/zato/sso/session/attr'], ['zato.sso.session-attr.session-attr-exists', 'zato.server.service.internal.sso.session_attr.SessionAttrExists', '/zato/sso/session/attr/exists'], ['zato.sso.session-attr.session-attr-names', 'zato.server.service.internal.sso.session_attr.SessionAttrNames', '/zato/sso/session/attr/names'], ] for name, impl_name, url_path in data: service = Service(None, name, True, impl_name, True, cluster) channel = HTTPSOAP(None, url_path, True, True, 'channel', 'plain_http', None, url_path, None, '', None, DATA_FORMAT.JSON, security=None, service=service, cluster=cluster) session.add(service) session.add(channel)
def add_internal_callback_wmq(self, session, cluster): from zato.common.api import IPC from zato.common.odb.model import HTTPBasicAuth, HTTPSOAP, Service impl_name = 'zato.server.service.internal.channel.jms_wmq.OnMessageReceived' service = Service(None, 'zato.channel.jms-wmq.on-message-received', True, impl_name, True, cluster) username = IPC.CONNECTOR.USERNAME.IBM_MQ sec = HTTPBasicAuth(None, username, True, username, 'Zato IBM MQ', new_password(), cluster) channel = HTTPSOAP(None, 'zato.internal.callback.wmq', True, True, 'channel', 'plain_http', None, '/zato/internal/callback/wmq', None, '', None, None, security=sec, service=service, cluster=cluster) session.add(sec) session.add(service) session.add(channel)
def add_internal_services(self, session, cluster, admin_invoke_sec, pubapi_sec, internal_invoke_sec, ide_pub_rbac_role): """ Adds these Zato internal services that can be accessed through SOAP requests. """ # # HTTPSOAP + services # # Python 2/3 compatibility from future.utils import iteritems # Zato from zato.common.api import DATA_FORMAT from zato.common.odb.model import Service from zato.common.util.api import get_http_json_channel, get_http_soap_channel for name, impl_name in iteritems(zato_services): service = Service(None, name, True, impl_name, True, cluster) session.add(service) if name == 'pub.zato.service.service-invoker': self.add_api_invoke(session, cluster, service, pubapi_sec) elif name == 'zato.service.invoke': self.add_admin_invoke(session, cluster, service, admin_invoke_sec) self.add_internal_invoke(session, cluster, service, internal_invoke_sec) elif name == 'zato.security.jwt.log-in': self.add_jwt_log_in(session, cluster, service) elif name == 'zato.security.jwt.log-out': self.add_jwt_log_out(session, cluster, service) elif name == 'zato.ide-deploy.create': self.add_rbac_channel(session, cluster, service, ide_pub_rbac_role, '/ide-deploy', permit_write=True, data_format=DATA_FORMAT.JSON) elif 'check' in name: self.add_check(session, cluster, service, pubapi_sec) session.add(get_http_soap_channel(name, service, cluster, pubapi_sec)) session.add(get_http_json_channel(name, service, cluster, pubapi_sec))
def add_crypto_endpoints(self, session, cluster): # Python 2/3 compatibility from future.utils import iteritems # Zato from zato.common.api import DATA_FORMAT from zato.common.odb.model import HTTPBasicAuth, HTTPSOAP, Service service_to_endpoint = { 'zato.crypto.encrypt': '/zato/crypto/encrypt', 'zato.crypto.decrypt': '/zato/crypto/decrypt', 'zato.crypto.hash-secret': '/zato/crypto/hash-secret', 'zato.crypto.verify-hash': '/zato/crypto/verify-hash', 'zato.crypto.generate-secret': '/zato/crypto/generate-secret', 'zato.crypto.generate-password': '******', } service_to_impl = { 'zato.crypto.encrypt': 'zato.server.service.internal.crypto.Encrypt', 'zato.crypto.decrypt': 'zato.server.service.internal.crypto.Decrypt', 'zato.crypto.hash-secret': 'zato.server.service.internal.crypto.HashSecret', 'zato.crypto.verify-hash': 'zato.server.service.internal.crypto.VerifyHash', 'zato.crypto.generate-secret': 'zato.server.service.internal.crypto.GenerateSecret', 'zato.crypto.generate-password': '******', } sec = HTTPBasicAuth(None, 'zato.default.crypto.client', True, 'zato.crypto', 'Zato crypto', new_password(), cluster) session.add(sec) for name, impl_name in iteritems(service_to_impl): service = Service(None, name, True, impl_name, True, cluster) session.add(service) url_path = service_to_endpoint[name] http_soap = HTTPSOAP(None, name, True, True, 'channel', 'plain_http', None, url_path, None, '', None, DATA_FORMAT.JSON, security=None, service=service, cluster=cluster) session.add(http_soap)
def add_pubsub_sec_endpoints(self, session, cluster): from zato.common.api import CONNECTION, DATA_FORMAT, PUBSUB, URL_TYPE from zato.common.json_internal import dumps from zato.common.odb.model import HTTPBasicAuth, HTTPSOAP, PubSubEndpoint, PubSubSubscription, PubSubTopic, \ Service from zato.common.pubsub import new_sub_key from zato.common.util.time_ import utcnow_as_ms sec_demo = HTTPBasicAuth( None, 'zato.pubsub.demo.secdef', True, 'zato.pubsub.demo', 'Zato pub/sub demo', new_password(), cluster) session.add(sec_demo) sec_default_internal = HTTPBasicAuth(None, 'zato.pubsub.internal.secdef', True, 'zato.pubsub.internal', 'Zato pub/sub internal', new_password(), cluster) session.add(sec_default_internal) impl_name1 = 'zato.server.service.internal.pubsub.pubapi.TopicService' impl_name2 = 'zato.server.service.internal.pubsub.pubapi.SubscribeService' impl_name3 = 'zato.server.service.internal.pubsub.pubapi.MessageService' impl_demo = 'zato.server.service.internal.helpers.JSONRawRequestLogger' service_topic = Service(None, 'zato.pubsub.pubapi.topic-service', True, impl_name1, True, cluster) service_sub = Service(None, 'zato.pubsub.pubapi.subscribe-service', True, impl_name2, True, cluster) service_msg = Service(None, 'zato.pubsub.pubapi.message-service', True, impl_name3, True, cluster) service_demo = Service(None, 'zato.pubsub.helpers.json-raw-request-logger', True, impl_demo, True, cluster) # Opaque data that lets clients use topic contain slash characters opaque = dumps({'match_slash':True}) chan_topic = HTTPSOAP(None, 'zato.pubsub.topic.topic_name', True, True, CONNECTION.CHANNEL, URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/topic/{topic_name}', None, '', None, DATA_FORMAT.JSON, security=None, service=service_topic, opaque=opaque, cluster=cluster) chan_sub = HTTPSOAP(None, 'zato.pubsub.subscribe.topic.topic_name', True, True, CONNECTION.CHANNEL, URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/subscribe/topic/{topic_name}', None, '', None, DATA_FORMAT.JSON, security=None, service=service_sub, opaque=opaque, cluster=cluster) chan_msg = HTTPSOAP(None, 'zato.pubsub.msg.msg_id', True, True, CONNECTION.CHANNEL, URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/msg/{msg_id}', None, '', None, DATA_FORMAT.JSON, security=None, service=service_msg, opaque=opaque, cluster=cluster) chan_demo = HTTPSOAP(None, 'pubsub.demo.sample.channel', True, True, CONNECTION.CHANNEL, URL_TYPE.PLAIN_HTTP, None, '/zato/pubsub/zato.demo.sample', None, '', None, DATA_FORMAT.JSON, security=sec_demo, service=service_demo, opaque=opaque, cluster=cluster) outconn_demo = HTTPSOAP(None, 'pubsub.demo.sample.outconn', True, True, CONNECTION.OUTGOING, URL_TYPE.PLAIN_HTTP, 'http://localhost:11223', '/zato/pubsub/zato.demo.sample', None, '', None, DATA_FORMAT.JSON, security=sec_demo, opaque=opaque, cluster=cluster) endpoint_default_internal = PubSubEndpoint() endpoint_default_internal.name = PUBSUB.DEFAULT.INTERNAL_ENDPOINT_NAME endpoint_default_internal.is_internal = True endpoint_default_internal.role = PUBSUB.ROLE.PUBLISHER_SUBSCRIBER.id endpoint_default_internal.topic_patterns = 'pub=/*\nsub=/*' endpoint_default_internal.security = sec_default_internal endpoint_default_internal.cluster = cluster endpoint_default_internal.endpoint_type = PUBSUB.ENDPOINT_TYPE.INTERNAL.id endpoint_demo = PubSubEndpoint() endpoint_demo.name = 'zato.pubsub.demo.endpoint' endpoint_demo.is_internal = True endpoint_demo.role = PUBSUB.ROLE.PUBLISHER_SUBSCRIBER.id endpoint_demo.topic_patterns = 'pub=/zato/demo/*\nsub=/zato/demo/*' endpoint_demo.security = sec_demo endpoint_demo.cluster = cluster endpoint_demo.endpoint_type = PUBSUB.ENDPOINT_TYPE.REST.id topic = PubSubTopic() topic.name = '/zato/demo/sample' topic.is_active = True topic.is_api_sub_allowed = True topic.is_internal = True topic.max_depth = 100 topic.has_gd = False topic.cluster = cluster sub = PubSubSubscription() sub.creation_time = utcnow_as_ms() sub.topic = topic sub.endpoint = endpoint_demo sub.sub_key = new_sub_key(endpoint_demo.endpoint_type) sub.has_gd = False sub.sub_pattern_matched = 'sub=/zato/demo/*' sub.active_status = PUBSUB.QUEUE_ACTIVE_STATUS.FULLY_ENABLED.id sub.cluster = cluster sub.wrap_one_msg_in_list = False sub.delivery_err_should_block = False sub.out_http_soap = outconn_demo session.add(endpoint_default_internal) session.add(endpoint_demo) session.add(topic) session.add(sub) session.add(service_topic) session.add(service_sub) session.add(service_msg) session.add(chan_topic) session.add(chan_sub) session.add(chan_msg) session.add(chan_demo) session.add(outconn_demo)
def add_ping_services(self, session, cluster): """ Adds a ping service and channels, with and without security checks. """ passwords = { 'ping.plain_http.basic_auth': None, 'ping.soap.basic_auth': None, 'ping.soap.wss.clear_text': None, } for password in passwords: passwords[password] = uuid4().hex ping_impl_name = 'zato.server.service.internal.Ping' ping_service_name = 'zato.ping' ping_service = Service(None, ping_service_name, True, ping_impl_name, True, cluster) session.add(ping_service) # # .. no security .. # # TODO # Change it to /zato/json/ping # and add an actual /zato/ping with no data format specified. ping_no_sec_channel = HTTPSOAP( None, 'zato.ping', True, True, 'channel', 'plain_http', None, '/zato/ping', None, '', None, SIMPLE_IO.FORMAT.JSON, service=ping_service, cluster=cluster) session.add(ping_no_sec_channel) # # All the possible options # # Plain HTTP / Basic auth # SOAP / Basic auth # SOAP / WSS / Clear text # transports = ['plain_http', 'soap'] wss_types = ['clear_text'] for transport in transports: if transport == 'plain_http': data_format = SIMPLE_IO.FORMAT.JSON else: data_format = SIMPLE_IO.FORMAT.XML base_name = 'ping.{0}.basic_auth'.format(transport) zato_name = 'zato.{0}'.format(base_name) url = '/zato/{0}'.format(base_name) soap_action, soap_version = (zato_name, '1.1') if transport == 'soap' else ('', None) password = passwords[base_name] sec = HTTPBasicAuth(None, zato_name, True, zato_name, 'Zato ping', password, cluster) session.add(sec) channel = HTTPSOAP( None, zato_name, True, True, 'channel', transport, None, url, None, soap_action, soap_version, data_format, service=ping_service, security=sec, cluster=cluster) session.add(channel) if transport == 'soap': for wss_type in wss_types: base_name = 'ping.{0}.wss.{1}'.format(transport, wss_type) zato_name = 'zato.{0}'.format(base_name) url = '/zato/{0}'.format(base_name) password = passwords[base_name] sec = WSSDefinition(None, zato_name, True, zato_name, password, wss_type, False, True, 3600, 3600, cluster) session.add(sec) channel = HTTPSOAP( None, zato_name, True, True, 'channel', transport, None, url, None, soap_action, soap_version, data_format, service=ping_service, security=sec, cluster=cluster) session.add(channel)
def add_cache_endpoints(self, session, cluster): # Python 2/3 compatibility from future.utils import iteritems # Zato from zato.common.api import DATA_FORMAT from zato.common.odb.model import HTTPBasicAuth, HTTPSOAP, Service service_to_endpoint = { # For single keys 'zato.cache.builtin.pubapi.single-key-service': '/zato/cache/{key}', # Multi-key get 'zato.cache.builtin.pubapi.get-by-prefix': '/zato/cache/get/by-prefix/{key}', 'zato.cache.builtin.pubapi.get-by-regex': '/zato/cache/get/by-regex/{key}', 'zato.cache.builtin.pubapi.get-by-suffix': '/zato/cache/get/by-suffix/{key}', 'zato.cache.builtin.pubapi.get-contains': '/zato/cache/get/contains/{key}', 'zato.cache.builtin.pubapi.get-not-contains': '/zato/cache/get/not-contains/{key}', 'zato.cache.builtin.pubapi.get-contains-all': '/zato/cache/get/contains-all', 'zato.cache.builtin.pubapi.get-contains-any': '/zato/cache/get/contains-any', # Multi-key set 'zato.cache.builtin.pubapi.set-by-prefix': '/zato/cache/set/by-prefix/{key}', 'zato.cache.builtin.pubapi.set-by-regex': '/zato/cache/set/by-regex/{key}', 'zato.cache.builtin.pubapi.set-by-suffix': '/zato/cache/set/by-suffix/{key}', 'zato.cache.builtin.pubapi.set-contains': '/zato/cache/set/contains/{key}', 'zato.cache.builtin.pubapi.set-not-contains': '/zato/cache/set/not-contains/{key}', 'zato.cache.builtin.pubapi.set-contains-all': '/zato/cache/set/contains-all', 'zato.cache.builtin.pubapi.set-contains-any': '/zato/cache/set/contains-any', # Multi-key delete 'zato.cache.builtin.pubapi.delete-by-prefix': '/zato/cache/delete/by-prefix/{key}', 'zato.cache.builtin.pubapi.delete-by-regex': '/zato/cache/delete/by-regex/{key}', 'zato.cache.builtin.pubapi.delete-by-suffix': '/zato/cache/delete/by-suffix/{key}', 'zato.cache.builtin.pubapi.delete-contains': '/zato/cache/delete/contains/{key}', 'zato.cache.builtin.pubapi.delete-not-contains': '/zato/cache/delete/not-contains/{key}', 'zato.cache.builtin.pubapi.delete-contains-all': '/zato/cache/delete/contains-all', 'zato.cache.builtin.pubapi.delete-contains-any': '/zato/cache/delete/contains-any', # Multi-key expire 'zato.cache.builtin.pubapi.expire-by-prefix': '/zato/cache/expire/by-prefix/{key}', 'zato.cache.builtin.pubapi.expire-by-regex': '/zato/cache/expire/by-regex/{key}', 'zato.cache.builtin.pubapi.expire-by-suffix': '/zato/cache/expire/by-suffix/{key}', 'zato.cache.builtin.pubapi.expire-contains': '/zato/cache/expire/contains/{key}', 'zato.cache.builtin.pubapi.expire-not-contains': '/zato/cache/expire/not-contains/{key}', 'zato.cache.builtin.pubapi.expire-contains-all': '/zato/cache/expire/contains-all', 'zato.cache.builtin.pubapi.expire-contains-any': '/zato/cache/expire/contains-any', } service_to_impl = { # For single keys 'zato.cache.builtin.pubapi.single-key-service': 'zato.server.service.internal.cache.builtin.pubapi.SingleKeyService', # Multi-key get 'zato.cache.builtin.pubapi.get-by-prefix': 'zato.server.service.internal.cache.builtin.pubapi.GetByPrefix', 'zato.cache.builtin.pubapi.get-by-regex': 'zato.server.service.internal.cache.builtin.pubapi.GetByRegex', 'zato.cache.builtin.pubapi.get-by-suffix': 'zato.server.service.internal.cache.builtin.pubapi.GetBySuffix', 'zato.cache.builtin.pubapi.get-contains': 'zato.server.service.internal.cache.builtin.pubapi.GetContains', 'zato.cache.builtin.pubapi.get-not-contains': 'zato.server.service.internal.cache.builtin.pubapi.GetNotContains', 'zato.cache.builtin.pubapi.get-contains-all': 'zato.server.service.internal.cache.builtin.pubapi.GetContainsAll', 'zato.cache.builtin.pubapi.get-contains-any': 'zato.server.service.internal.cache.builtin.pubapi.GetContainsAny', # Multi-key set 'zato.cache.builtin.pubapi.set-by-prefix': 'zato.server.service.internal.cache.builtin.pubapi.SetByPrefix', 'zato.cache.builtin.pubapi.set-by-regex': 'zato.server.service.internal.cache.builtin.pubapi.SetByRegex', 'zato.cache.builtin.pubapi.set-by-suffix': 'zato.server.service.internal.cache.builtin.pubapi.SetBySuffix', 'zato.cache.builtin.pubapi.set-contains': 'zato.server.service.internal.cache.builtin.pubapi.SetContains', 'zato.cache.builtin.pubapi.set-not-contains': 'zato.server.service.internal.cache.builtin.pubapi.SetNotContains', 'zato.cache.builtin.pubapi.set-contains-all': 'zato.server.service.internal.cache.builtin.pubapi.SetContainsAll', 'zato.cache.builtin.pubapi.set-contains-any': 'zato.server.service.internal.cache.builtin.pubapi.SetContainsAny', # Multi-key delete 'zato.cache.builtin.pubapi.delete-by-prefix': 'zato.server.service.internal.cache.builtin.pubapi.DeleteByPrefix', 'zato.cache.builtin.pubapi.delete-by-regex': 'zato.server.service.internal.cache.builtin.pubapi.DeleteByRegex', 'zato.cache.builtin.pubapi.delete-by-suffix': 'zato.server.service.internal.cache.builtin.pubapi.DeleteBySuffix', 'zato.cache.builtin.pubapi.delete-contains': 'zato.server.service.internal.cache.builtin.pubapi.DeleteContains', 'zato.cache.builtin.pubapi.delete-not-contains': 'zato.server.service.internal.cache.builtin.pubapi.DeleteNotContains', 'zato.cache.builtin.pubapi.delete-contains-all': 'zato.server.service.internal.cache.builtin.pubapi.DeleteContainsAll', 'zato.cache.builtin.pubapi.delete-contains-any': 'zato.server.service.internal.cache.builtin.pubapi.DeleteContainsAny', # Multi-key expire 'zato.cache.builtin.pubapi.expire-by-prefix': 'zato.server.service.internal.cache.builtin.pubapi.ExpireByPrefix', 'zato.cache.builtin.pubapi.expire-by-regex': 'zato.server.service.internal.cache.builtin.pubapi.ExpireByRegex', 'zato.cache.builtin.pubapi.expire-by-suffix': 'zato.server.service.internal.cache.builtin.pubapi.ExpireBySuffix', 'zato.cache.builtin.pubapi.expire-contains': 'zato.server.service.internal.cache.builtin.pubapi.ExpireContains', 'zato.cache.builtin.pubapi.expire-not-contains': 'zato.server.service.internal.cache.builtin.pubapi.ExpireNotContains', 'zato.cache.builtin.pubapi.expire-contains-all': 'zato.server.service.internal.cache.builtin.pubapi.ExpireContainsAll', 'zato.cache.builtin.pubapi.expire-contains-any': 'zato.server.service.internal.cache.builtin.pubapi.ExpireContainsAny', } sec = HTTPBasicAuth(None, 'zato.default.cache.client', True, 'zato.cache', 'Zato cache', new_password(), cluster) session.add(sec) for name, impl_name in iteritems(service_to_impl): service = Service(None, name, True, impl_name, True, cluster) session.add(service) url_path = service_to_endpoint[name] http_soap = HTTPSOAP(None, name, True, True, 'channel', 'plain_http', None, url_path, None, '', None, DATA_FORMAT.JSON, security=None, service=service, cluster=cluster) session.add(http_soap)
def overview(req, service_name): cluster_id = req.GET.get('cluster') service = None create_form = CreateForm() edit_form = EditForm(prefix='edit') if cluster_id and req.method == 'GET': input_dict = {'name': service_name, 'cluster_id': req.zato.cluster_id} response = req.zato.client.invoke('zato.service.get-by-name', input_dict) if response.has_data: service = Service() for name in ('id', 'name', 'is_active', 'impl_name', 'is_internal', 'usage', 'time_last', 'time_min_all_time', 'time_max_all_time', 'time_mean_all_time'): value = getattr(response.data, name) if name in ('is_active', 'is_internal'): value = is_boolean(value) setattr(service, name, value) now = datetime.utcnow() start = now + relativedelta(minutes=-60) response = req.zato.client.invoke('zato.stats.get-by-service', { 'service_id': service.id, 'start': start, 'stop': now }) if response.has_data: for name in ('mean_trend', 'usage_trend', 'min_resp_time', 'max_resp_time', 'mean', 'usage', 'rate'): value = getattr(response.data, name) if not value or value == ZATO_NONE: value = '' setattr(service, 'time_{}_1h'.format(name), value) for channel_type in ('plain_http', 'soap', 'amqp', 'jms-wmq', 'zmq'): channels = _get_channels(req.zato.client, req.zato.cluster, service.id, channel_type) getattr(service, channel_type.replace('jms-', '') + '_channels').extend(channels) for item in req.zato.client.invoke( 'zato.service.get-deployment-info-list', {'id': service.id}): service.deployment_info.append( DeploymentInfo(item.server_name, item.details)) # TODO: There needs to be a new service added zato.service.scheduler.job.get-by-service # or .get-list should start accept a service name. Right now we pull all the # jobs which is suboptimal. response = req.zato.client.invoke('zato.scheduler.job.get-list', {'cluster_id': cluster_id}) if response.has_data: for item in response.data: if item.service_name == service_name: url = reverse('scheduler') url += '?cluster={}'.format(cluster_id) url += '&highlight={}'.format(item.id) service.scheduler_jobs.append( ExposedThrough(item.id, item.name, url)) return_data = { 'zato_clusters': req.zato.clusters, 'service': service, 'cluster_id': cluster_id, 'search_form': req.zato.search_form, 'create_form': create_form, 'edit_form': edit_form, } return TemplateResponse(req, 'zato/service/overview.html', return_data)
def request_response(req, service_name): service = Service(name=service_name) pretty_print = asbool(req.GET.get('pretty_print')) input_dict = {'name': service_name, 'cluster_id': req.zato.cluster_id} service_response = req.zato.client.invoke( 'zato.service.get-request-response', input_dict) if service_response.ok: request = b64decode(service_response.data.sample_req if service_response.data.sample_req else '') request = request.decode('utf8') request_data_format = known_data_format(request) if request_data_format: if pretty_print: request = get_pretty_print(request, request_data_format) service.sample_req_html = highlight( request, data_format_lexer[request_data_format](), HtmlFormatter(linenos='table')) response = b64decode(service_response.data.sample_resp if service_response.data.sample_resp else '') response = response.decode('utf8') response_data_format = known_data_format(response) if response_data_format: if pretty_print: response = get_pretty_print(response, response_data_format) service.sample_resp_html = highlight( response, data_format_lexer[response_data_format](), HtmlFormatter(linenos='table')) service.sample_req = request service.sample_resp = response ts = {} for name in ('req', 'resp'): full_name = 'sample_{}_ts'.format(name) value = getattr(service_response.data, full_name, '') if value: value = from_utc_to_user(value + '+00:00', req.zato.user_profile) ts[full_name] = value service.id = service_response.data.service_id service.sample_cid = service_response.data.sample_cid service.sample_req_ts = ts['sample_req_ts'] service.sample_resp_ts = ts['sample_resp_ts'] service.sample_req_resp_freq = service_response.data.sample_req_resp_freq return_data = { 'cluster_id': req.zato.cluster_id, 'service': service, 'pretty_print': not pretty_print, } return TemplateResponse(req, 'zato/service/request-response.html', return_data)