Skip to content

Commit

Permalink
Merge branch 'main' into support/3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuch committed Sep 22, 2023
2 parents 3b1e864 + 898404e commit 3c174b6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 27 deletions.
3 changes: 1 addition & 2 deletions code/zato-common/src/zato/common/marshal_/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class _Sentinel:
# ################################################################################################################################
# ################################################################################################################################

def is_list(field_type, is_class):
# type: (Field, bool) -> bool
def is_list(field_type:'Field', is_class:'bool') -> 'bool':

# Using str is the only reliable method
if 'typing.Union' in str(field_type):
Expand Down
14 changes: 10 additions & 4 deletions code/zato-common/src/zato/common/odb/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,16 @@ def _sec_base(session, cluster_id):
filter(SecurityBase.cluster_id==Cluster.id).\
filter(Cluster.id==cluster_id)

def sec_base(session, cluster_id, sec_base_id):
return _sec_base(session, cluster_id).\
filter(SecurityBase.id==sec_base_id).\
one()
def sec_base(session, cluster_id, sec_base_id, use_one=True):
q = _sec_base(session, cluster_id).\
filter(SecurityBase.id==sec_base_id)

if use_one:
result = q.one()
else:
result = q.first()

return result

@query_wrapper
def apikey_security_list(session, cluster_id, needs_columns=False):
Expand Down
15 changes: 10 additions & 5 deletions code/zato-server/src/zato/server/apispec/parser/service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-

"""
Copyright (C) 2021, Zato Source s.r.o. https://zato.io
Copyright (C) 2023, Zato Source s.r.o. https://zato.io
Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""

# Zato
from zato.common.marshal_.api import extract_model_class, is_list
from zato.common.marshal_.api import Model
from zato.common.marshal_.simpleio import DataClassSimpleIO
from zato.server.apispec.model import APISpecInfo, Config, FieldInfo, SimpleIO
Expand All @@ -18,7 +19,7 @@
# ################################################################################################################################
# ################################################################################################################################

_SIO_TYPE_MAP = SIO_TYPE_MAP()
_SIO_TYPE_MAP = SIO_TYPE_MAP() # type: ignore

# ################################################################################################################################
# ################################################################################################################################
Expand All @@ -39,16 +40,20 @@ def build_field_list(model:'Model | str', api_spec_info:'any_') -> 'anylist':
# Response to produce
out = [] # type: anylist

# All the fields of this dataclass
# All the fields of this dataclass ..
if isinstance(model, str):
return out

# .. handle list models as well ..
if is_list(model, True): # type: ignore
model = extract_model_class(model) # type: ignore

python_field_list = model.zato_get_fields()

for _, field in sorted(python_field_list.items()):

# Parameter details object
info = FieldInfo.from_python_field(model, field, api_spec_info)
info = FieldInfo.from_python_field(model, field, api_spec_info) # type: ignore
out.append(info)

return out
Expand Down Expand Up @@ -120,7 +125,7 @@ def parse_simple_io(self) -> 'None':
# This can be reused across all the output data formats
sio_desc = self.docstring.get_sio_desc(sio)

for api_spec_info in _SIO_TYPE_MAP:
for api_spec_info in _SIO_TYPE_MAP: # type: ignore

# A structure that contains an API specification for each major output format, e.g. Zato or OpenAPI
spec_info = APISpecInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from zato.common.broker_message import CHANNEL
from zato.common.odb.model import ChannelWebSocket, PubSubSubscription, PubSubTopic, SecurityBase, Service as ServiceModel, \
WebSocketClient
from zato.common.odb.query import channel_web_socket_list, channel_web_socket, service, web_socket_client, \
from zato.common.odb.query import channel_web_socket_list, channel_web_socket, sec_base, service, web_socket_client, \
web_socket_client_by_pub_id, web_socket_client_list, web_socket_sub_key_data_list
from zato.common.util.api import is_port_taken
from zato.common.util.sql import elems_with_opaque
Expand Down Expand Up @@ -57,7 +57,7 @@
create_edit_input_required_extra = ['service_name']
create_edit_input_optional_extra = generic_attrs + ['extra_properties']
input_optional_extra = ['security']
output_optional_extra = ['sec_type', 'service_name', 'address'] + generic_attrs
output_optional_extra = ['sec_type', 'service_name', 'address', 'security_name'] + generic_attrs
create_edit_force_rewrite = {'service_name', 'address'}

# ################################################################################################################################
Expand Down Expand Up @@ -126,10 +126,22 @@ def instance_hook(self, input, instance, attrs):
# ################################################################################################################################

def response_hook(self, input, _ignored_instance, attrs, service_type):

if service_type == 'get_list' and self.name == 'zato.channel.web-socket.get-list':

with closing(self.odb.session()) as session:
for item in self.response.payload:
item.service_name = service(session, self.server.cluster_id, item.service_id).name

_service = service(session, self.server.cluster_id, item.service_id)
item.service_name = _service.name

if item.security_id:
_security = sec_base(session, self.server.cluster_id, item.security_id, use_one=False)

if _security:
item.security_name = _security.name
else:
item.security_name = None

# ################################################################################################################################

Expand Down
56 changes: 43 additions & 13 deletions code/zato-server/src/zato/server/service/internal/http_soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,26 @@ def handle(self):
input.hl7_version = input.get('hl7_version') or HL7.Const.Version.v2.id

# Remove extra whitespace
input.name = input.name.strip()
input.host = input.host.strip()
input.url_path = input.url_path.strip()
input.ping_method = input.get('ping_method', '').strip() or DEFAULT_HTTP_PING_METHOD
input.content_type = input.get('content_type', '').strip()
input_name = input.name
input_host = input.host
input_url_path = input.url_path
input_ping_method = input.get('ping_method')
input_content_type = input.get('content_type')

if input_name:
input.name = input_name.strip()

if input_host:
input.host = input_host.strip()

if input_url_path:
input.url_path = input_url_path.strip()

if input_ping_method:
input.ping_method = input_ping_method.strip() or DEFAULT_HTTP_PING_METHOD

if input_content_type:
input.content_type = input_content_type.strip()

if input.content_encoding and input.content_encoding != 'gzip':
raise Exception('Content encoding must be empty or equal to `gzip`')
Expand Down Expand Up @@ -462,11 +477,26 @@ def handle(self):
input.hl7_version = input.get('hl7_version') or HL7.Const.Version.v2.id

# Remove extra whitespace
input.name = input.name.strip()
input.host = input.host.strip()
input.url_path = input.url_path.strip()
input.ping_method = input.get('ping_method', '').strip() or DEFAULT_HTTP_PING_METHOD
input.content_type = input.get('content_type', '').strip()
input_name = input.name
input_host = input.host
input_url_path = input.url_path
input_ping_method = input.get('ping_method')
input_content_type = input.get('content_type')

if input_name:
input.name = input_name.strip()

if input_host:
input.host = input_host.strip()

if input_url_path:
input.url_path = input_url_path.strip()

if input_ping_method:
input.ping_method = input_ping_method.strip() or DEFAULT_HTTP_PING_METHOD

if input_content_type:
input.content_type = input_content_type.strip()

if input.content_encoding and input.content_encoding != 'gzip':
raise Exception('Content encoding must be empty or equal to `gzip`')
Expand Down Expand Up @@ -521,10 +551,10 @@ def handle(self):
old_http_method = item.method
old_http_accept = opaque.get('http_accept')

item.name = input.name.strip()
item.name = input.name
item.is_active = input.is_active
item.host = input.host.strip()
item.url_path = input.url_path.strip()
item.host = input.host
item.url_path = input.url_path
item.security_id = input.security_id or None # So that SQLite does not reject ''
item.connection = input.connection
item.transport = input.transport
Expand Down

0 comments on commit 3c174b6

Please sign in to comment.