Skip to content

Commit

Permalink
Merge pull request #88 from minos-framework/0.3.0
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
Sergio García Prado authored Feb 4, 2022
2 parents 5e393ad + 49ff84f commit 3276904
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@
* Add PostgreSQL database with SQLAlchemy dependency.
* Auth Rules for authentication.
* Administration section for rules management.

## 0.3.0 (2022-02-04)

* Administration section BugFix getting index file.
* Adjust default auth routes
2 changes: 1 addition & 1 deletion minos/api_gateway/rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.0"
__version__ = "0.3.0"

from .config import (
ApiGatewayConfig,
Expand Down
12 changes: 12 additions & 0 deletions minos/api_gateway/rest/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ async def authentication_default(request: web.Request) -> web.Response:
return await authentication_call(request, url)


async def login_default(request: web.Request) -> web.Response:
""" Orchestrate discovery and microservice call """
auth_host = request.app["config"].rest.auth.host
auth_port = request.app["config"].rest.auth.port
auth_path = request.app["config"].rest.auth.path
default_service = request.app["config"].rest.auth.default

url = URL(f"http://{auth_host}:{auth_port}{auth_path}/{default_service}/login")

return await authentication_call(request, url)


async def authentication(request: web.Request) -> web.Response:
""" Orchestrate discovery and microservice call """

Expand Down
6 changes: 5 additions & 1 deletion minos/api_gateway/rest/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
AdminHandler,
authentication,
authentication_default,
login_default,
orchestrate,
)

Expand Down Expand Up @@ -57,8 +58,10 @@ async def create_application(self) -> web.Application:
auth = self.config.rest.auth
if auth is not None and auth.enabled:
app.router.add_route("*", "/auth", authentication_default)
app.router.add_route("*", "/auth/login", login_default)
for service in auth.services:
app.router.add_route("*", f"/auth/{service.name}", authentication)
app.router.add_route("POST", f"/auth/{service.name}/login", authentication)

app.router.add_route("POST", "/admin/login", AdminHandler.login)
app.router.add_route("GET", "/admin/endpoints", AdminHandler.get_endpoints)
Expand All @@ -68,7 +71,8 @@ async def create_application(self) -> web.Application:
app.router.add_route("DELETE", "/admin/rules/{id}", AdminHandler.delete_rule)

# Administration routes
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("minos/api_gateway/rest/backend/templates"))
path = Path(Path.cwd())
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(f"{path}/minos/api_gateway/rest/backend/templates"))
app.router.add_route("*", "/administration{path:.*}", self.handler)
# app.router.add_route("GET", "/administration/{filename:.*}", self._serve_files)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "minos_apigateway"
version = "0.2.0"
version = "0.3.0"
description = "Python Package containing the main API Gateway implementation used in Minos Microservices."
readme = "README.md"
repository = "https://github.com/clariteia/api_gateway"
Expand Down
2 changes: 1 addition & 1 deletion tests/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rest:
services:
- name: token
- name: credentials
default: token
default: credentials
database:
dbname: api_gateway_db
user: minos
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api_gateway/test_rest/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def test_auth_headers_3(self):

@unittest_run_loop
async def test_default_auth_headers(self):
url = "/auth"
url = "/auth/token"
headers = {"Authorization": "Bearer credential-token-test"}

response = await self.client.request("POST", url, headers=headers)
Expand Down

0 comments on commit 3276904

Please sign in to comment.