MCPcopy Create free account
hub / github.com/StackStorm/st2 / Router

Class Router

st2common/st2common/router.py:218–845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216
217
218class Router(object):
219 def __init__(self, arguments=None, debug=False, auth=True, is_gunicorn=True):
220 self.debug = debug
221 self.auth = auth
222 self.is_gunicorn = is_gunicorn
223
224 self.arguments = arguments or {}
225
226 self.spec = {}
227 self.spec_resolver = None
228 self.routes = routes.Mapper()
229
230 def add_spec(self, spec, transforms):
231 info = spec.get("info", {})
232 LOG.debug(
233 "Adding API: %s %s",
234 info.get("title", "untitled"),
235 info.get("version", "0.0.0"),
236 )
237
238 self.spec = spec
239 self.spec_resolver = jsonschema.RefResolver("", self.spec)
240
241 validate(fast_deepcopy_dict(self.spec))
242
243 for filter in transforms:
244 for (path, methods) in six.iteritems(spec["paths"]):
245 if not re.search(filter, path):
246 continue
247
248 for (method, endpoint) in six.iteritems(methods):
249 conditions = {"method": [method.upper()]}
250
251 connect_kw = {}
252 if "x-requirements" in endpoint:
253 connect_kw["requirements"] = endpoint["x-requirements"]
254
255 m = self.routes.submapper(
256 _api_path=path, _api_method=method, conditions=conditions
257 )
258 for transform in transforms[filter]:
259 m.connect(None, re.sub(filter, transform, path), **connect_kw)
260
261 module_name = endpoint["operationId"].split(":", 1)[0]
262 __import__(module_name)
263
264 for route in sorted(self.routes.matchlist, key=lambda r: r.routepath):
265 LOG.debug(
266 "Route registered: %+6s %s",
267 route.conditions["method"][0],
268 route.routepath,
269 )
270
271 def match(self, req):
272 # NOTE: webob.url_unquote doesn't work correctly under Python 3 when paths contain non-ascii
273 # characters. That method supposed to handle Python 2 and Python 3 compatibility, but it
274 # doesn't work correctly under Python 3.
275 try:

Callers 4

setup_appFunction · 0.90
setup_appFunction · 0.90
setup_appFunction · 0.90

Calls

no outgoing calls