Skip to content

Commit 1a9f3bf

Browse files
authored
Merge pull request #28 from Clariteia/0.0.2
0.0.2
2 parents 161cf07 + 4f91840 commit 1a9f3bf

File tree

10 files changed

+226
-91
lines changed

10 files changed

+226
-91
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
## 0.0.1 (2021-06-14)
44

55
* First release on PyPI.
6+
7+
## 0.0.2 (2021-06-18)
8+
9+
* Bugfix.

minos/api_gateway/rest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Minos framework can not be copied and/or distributed without the express permission of Clariteia SL.
77
"""
8-
__version__ = "0.0.1"
8+
__version__ = "0.0.2"
99

1010
from .coordinator import (
1111
MicroserviceCallCoordinator,

minos/api_gateway/rest/coordinator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def call_microservice(self, data: dict):
5656

5757
req_data = await self.original_req.text()
5858

59-
url = "http://{host}:{port}/{path}".format(host=data["ip"], port=data["port"], path=data["name"])
59+
url = "http://{host}:{port}{path}".format(host=data["ip"], port=data["port"], path=self.original_req.url.path)
6060

6161
try:
6262
async with aiohttp.ClientSession(headers=self.original_req.headers) as session:

poetry.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "minos_apigateway"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
description = "Python Package containing the main API Gateway implementation used in Minos Microservices."
55
readme = "README.md"
66
repository = "https://github.com/clariteia/api_gateway"
@@ -47,6 +47,7 @@ sphinx-autodoc-typehints = "^1.12.0"
4747
sphinxcontrib-apidoc = "^0.3.0"
4848
sphinx-rtd-theme = "^0.5.2"
4949
m2r2 = "^0.2.7"
50+
Flask = "^2.0.1"
5051

5152
[build-system]
5253
requires = ["poetry-core>=1.0.0"]

tests/config.yml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,31 @@ rest:
55
- name: GetOrder
66
route: /order/{id}
77
method: GET
8-
controller: minos.api_gateway.rest.handlers.ApiGatewayHandler
8+
controller: tests.handlers.ApiGatewayHandler
99
action: get_order
1010
- name: AddOrder
1111
route: /order
1212
method: POST
13-
controller: minos.api_gateway.rest.handlers.ApiGatewayHandler
13+
controller: tests.handlers.ApiGatewayHandler
1414
action: post_order
1515
- name: PutOrder
1616
route: /order/{id}
1717
method: PUT
18-
controller: minos.api_gateway.rest.handlers.ApiGatewayHandler
18+
controller: tests.handlers.ApiGatewayHandler
1919
action: put_order
2020
- name: PatchOrder
2121
route: /order/{id}
2222
method: PATCH
23-
controller: minos.api_gateway.rest.handlers.ApiGatewayHandler
23+
controller: tests.handlers.ApiGatewayHandler
2424
action: patch_order
2525
- name: DeleteOrder
2626
route: /order/{id}
2727
method: DELETE
28-
controller: minos.api_gateway.rest.handlers.ApiGatewayHandler
28+
controller: tests.handlers.ApiGatewayHandler
2929
action: delete_order
30-
- name: Discovery
31-
route: /discover
32-
method: GET
33-
controller: tests.services.DiscoveryService.Discovery
34-
action: discover
35-
- name: OrderMicroservice
36-
route: /order-microservice
37-
method: GET
38-
controller: tests.services.OrderMicroservice.Order
39-
action: order
40-
- name: OrderMicroservice
41-
route: /order-microservice
42-
method: POST
43-
controller: tests.services.OrderMicroservice.Order
44-
action: order
45-
- name: TestGetOrder
46-
route: /test-get-order/{id}
47-
method: GET
48-
controller: tests.services.TestService.TestService
49-
action: test_get_order
5030
discovery:
5131
host: localhost
52-
port: 55909
32+
port: 5567
5333
path: discover
5434
endpoints:
5535
- name: Discover

minos/api_gateway/rest/handlers.py renamed to tests/handlers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212

1313
class ApiGatewayHandler(object):
1414
async def get_order(self, request: web.Request, config: MinosConfig, **kwargs):
15-
coordinator = MicroserviceCallCoordinator(config, request, request.url.host, request.url.port)
15+
coordinator = MicroserviceCallCoordinator(config, request)
1616
response = await coordinator.orchestrate()
1717
return response
1818

1919
async def post_order(self, request: web.Request, config: MinosConfig, **kwargs):
20-
coordinator = MicroserviceCallCoordinator(config, request, request.url.host, request.url.port)
20+
coordinator = MicroserviceCallCoordinator(config, request)
2121
response = await coordinator.orchestrate()
2222
return response
2323

2424
async def put_order(self, request: web.Request, config: MinosConfig, **kwargs):
25-
coordinator = MicroserviceCallCoordinator(config, request, request.url.host, request.url.port)
25+
coordinator = MicroserviceCallCoordinator(config, request)
2626
response = await coordinator.orchestrate()
2727
return response
2828

2929
async def patch_order(self, request: web.Request, config: MinosConfig, **kwargs):
30-
coordinator = MicroserviceCallCoordinator(config, request, request.url.host, request.url.port)
30+
coordinator = MicroserviceCallCoordinator(config, request)
3131
response = await coordinator.orchestrate()
3232
return response
3333

3434
async def delete_order(self, request: web.Request, config: MinosConfig, **kwargs):
35-
coordinator = MicroserviceCallCoordinator(config, request, request.url.host, request.url.port)
35+
coordinator = MicroserviceCallCoordinator(config, request)
3636
response = await coordinator.orchestrate()
3737
return response

tests/mock_servers/server.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import uuid
2+
from threading import (
3+
Thread,
4+
)
5+
6+
import requests
7+
from flask import (
8+
Flask,
9+
jsonify,
10+
)
11+
12+
13+
class MockServer(Thread):
14+
def __init__(self, host="http://localhost", port=5000):
15+
super().__init__()
16+
self.host = host
17+
self.port = port
18+
self.app = Flask(__name__)
19+
self.url = "http://%s:%s" % (self.host, self.port)
20+
21+
self.app.add_url_rule("/shutdown", view_func=self._shutdown_server)
22+
23+
def _shutdown_server(self):
24+
from flask import (
25+
request,
26+
)
27+
28+
if "werkzeug.server.shutdown" not in request.environ:
29+
raise RuntimeError("Not running the development server")
30+
request.environ["werkzeug.server.shutdown"]()
31+
return "Server shutting down..."
32+
33+
def shutdown_server(self):
34+
requests.get("http://%s:%s/shutdown" % (self.host, self.port))
35+
self.join()
36+
37+
def add_callback_response(self, url, callback, methods=("GET",)):
38+
# change name of method to mitigate flask exception
39+
callback.__name__ = str(uuid.uuid4())
40+
self.app.add_url_rule(url, view_func=callback, methods=methods)
41+
42+
def add_json_response(self, url, serializable, methods=("GET",)):
43+
def callback():
44+
return jsonify(serializable)
45+
46+
self.add_callback_response(url, callback, methods=methods)
47+
48+
def run(self):
49+
self.app.run(port=self.port)

0 commit comments

Comments
 (0)