21 |
21 |
import zeep.helpers
|
22 |
22 |
import zeep.xsd
|
23 |
23 |
from django.db import models
|
|
24 |
from django.forms import ValidationError
|
24 |
25 |
from django.utils.functional import cached_property
|
25 |
26 |
from django.utils.translation import ugettext_lazy as _
|
26 |
27 |
|
27 |
28 |
from passerelle.base.models import BaseResource, HTTPResource
|
28 |
29 |
from passerelle.utils.api import endpoint
|
|
30 |
from passerelle.utils.conversion import exception_to_text
|
29 |
31 |
from passerelle.utils.json import unflatten
|
30 |
32 |
|
31 |
33 |
|
... | ... | |
42 |
44 |
class Meta:
|
43 |
45 |
verbose_name = _('SOAP connector')
|
44 |
46 |
|
|
47 |
def clean(self):
|
|
48 |
try:
|
|
49 |
self.operations_and_schemas
|
|
50 |
except Exception as e:
|
|
51 |
raise ValidationError(e)
|
|
52 |
|
45 |
53 |
@classmethod
|
46 |
54 |
def get_manager_form_class(cls, **kwargs):
|
47 |
55 |
form_class = super().get_manager_form_class(**kwargs)
|
... | ... | |
107 |
115 |
|
108 |
116 |
def get_endpoints_infos(self):
|
109 |
117 |
endpoints = super().get_endpoints_infos()
|
110 |
|
for name, input_schema, output_schema in self.operations_and_schemas:
|
|
118 |
|
|
119 |
try:
|
|
120 |
operations_and_schemas = self.operations_and_schemas
|
|
121 |
except Exception as e:
|
|
122 |
self.set_availability_status('down', message=exception_to_text(e)[:500])
|
|
123 |
return endpoints
|
|
124 |
|
|
125 |
for name, input_schema, output_schema in operations_and_schemas:
|
111 |
126 |
kwargs = dict(
|
112 |
127 |
name='method',
|
113 |
128 |
pattern=f'{name}/',
|
... | ... | |
137 |
152 |
@property
|
138 |
153 |
def operations_and_schemas(self):
|
139 |
154 |
operations = self.client.service._binding._operations
|
|
155 |
operations_and_schemas = []
|
140 |
156 |
for name in operations:
|
141 |
157 |
operation = operations[name]
|
142 |
158 |
input_type = operation.input.body.type
|
143 |
159 |
output_type = operation.output.body.type
|
144 |
160 |
input_schema = self.type2schema(input_type, keep_root=True)
|
145 |
161 |
output_schema = self.type2schema(output_type, compress=True)
|
146 |
|
yield name, input_schema, output_schema
|
|
162 |
operations_and_schemas.append((name, input_schema, output_schema))
|
|
163 |
return operations_and_schemas
|
147 |
164 |
|
148 |
165 |
def type2schema(self, xsd_type, keep_root=False, compress=False):
|
149 |
166 |
# simplify schema: when a type contains a unique element, it will try
|