maleo-foundation 0.1.21__py3-none-any.whl → 0.1.23__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  from fastapi import FastAPI
2
2
  from pydantic import BaseModel, Field
3
3
  from typing import List, Optional
4
- from maleo_foundation.middlewares.authentication import Backend, add_authentication_middleware
4
+ from maleo_foundation.middlewares.authentication import add_authentication_middleware
5
5
  from maleo_foundation.middlewares.base import add_base_middleware, RequestProcessor
6
6
  from maleo_foundation.middlewares.cors import add_cors_middleware
7
7
  from maleo_foundation.utils.logging import MiddlewareLogger
@@ -46,27 +46,11 @@ class MiddlewareManager:
46
46
  self,
47
47
  loggers:MiddlewareLoggers,
48
48
  key:str,
49
- authentication_backend:Optional[Backend] = None,
50
49
  request_processor:Optional[RequestProcessor] = None
51
50
  ):
52
51
  self.add_cors()
53
- self.add_base(
54
- logger=loggers.base,
55
- allow_origins=self._configurations.general.allow_origins,
56
- allow_methods=self._configurations.general.allow_methods,
57
- allow_headers=self._configurations.general.allow_headers,
58
- allow_credentials=self._configurations.general.allow_credentials,
59
- limit=self._configurations.base.limit,
60
- window=self._configurations.base.window,
61
- cleanup_interval=self._configurations.base.cleanup_interval,
62
- ip_timeout=self._configurations.base.ip_timeout,
63
- request_processor=request_processor
64
- )
65
- if authentication_backend is None:
66
- self._authentication_backend = Backend(logger=loggers.authentication, key=key)
67
- else:
68
- self._authentication_backend = authentication_backend
69
- self.add_authentication(backend=self._authentication_backend)
52
+ self.add_base(logger=loggers.base, request_processor=request_processor)
53
+ self.add_authentication(logger=loggers.authentication, key=key)
70
54
 
71
55
  def add_cors(self) -> None:
72
56
  add_cors_middleware(
@@ -93,9 +77,5 @@ class MiddlewareManager:
93
77
  request_processor=request_processor
94
78
  )
95
79
 
96
- def add_authentication(self, logger:MiddlewareLogger, key:str, backend:Optional[Backend] = None):
97
- if backend is None:
98
- self._authentication_backend = Backend(logger=logger, key=key)
99
- else:
100
- self._authentication_backend = backend
101
- add_authentication_middleware(app=self._app, backend=self._authentication_backend)
80
+ def add_authentication(self, logger:MiddlewareLogger, key:str):
81
+ add_authentication_middleware(app=self._app, logger=logger, key=key)
@@ -36,7 +36,7 @@ class Backend(AuthenticationBackend):
36
36
  self._logger.info(f"Authentication - Request | IP: {client_ip} | URL: {conn.url.path} - Result | Username: {decode_token_result.data.u_u} | Email: {decode_token_result.data.u_e}")
37
37
  return Credentials(token=token), User(authenticated=True, username=decode_token_result.data.u_u, email=decode_token_result.data.u_e)
38
38
 
39
- def add_authentication_middleware(app:FastAPI, backend:Backend) -> None:
39
+ def add_authentication_middleware(app:FastAPI, logger:MiddlewareLogger, key:str) -> None:
40
40
  """
41
41
  Adds Authentication middleware to the FastAPI application.
42
42
 
@@ -44,8 +44,11 @@ def add_authentication_middleware(app:FastAPI, backend:Backend) -> None:
44
44
  app: FastAPI
45
45
  The FastAPI application instance to which the middleware will be added.
46
46
 
47
- backend: Backend
48
- The authentication middleware backend to be used.
47
+ logger: MiddlewareLogger
48
+ Authentication middleware logger to be used.
49
+
50
+ key: str
51
+ Public key to be used for token decoding.
49
52
 
50
53
  Returns:
51
54
  None: The function modifies the FastAPI app by adding Base middleware.
@@ -59,4 +62,4 @@ def add_authentication_middleware(app:FastAPI, backend:Backend) -> None:
59
62
  add_authentication_middleware(app=app, limit=10, window=1, cleanup_interval=60, ip_timeout=300)
60
63
  ```
61
64
  """
62
- app.add_middleware(AuthenticationMiddleware, backend=backend)
65
+ app.add_middleware(AuthenticationMiddleware, backend=Backend(logger=logger, key=key))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.1.21
3
+ Version: 0.1.23
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -31,7 +31,7 @@ maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rv
31
31
  maleo_foundation/expanded_types/token.py,sha256=4fRTJw6W5MYq71NksNrWNi7qYHQ4_lQwfu9WxwrMipc,355
32
32
  maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  maleo_foundation/managers/db.py,sha256=Jf0w-9JOAG5X2quDxqqw6d2WUIX7MYGdlPGxWP0rxHs,4699
34
- maleo_foundation/managers/middleware.py,sha256=lmlXpUN66PhOzaqu-u11VcUD0meTDU0ZNvtAmEHuD8E,5086
34
+ maleo_foundation/managers/middleware.py,sha256=7CDXPMb28AR7J72TWOeKFxOlMypKezEtO9mr53a88B0,4032
35
35
  maleo_foundation/managers/service.py,sha256=RSjaJDjrvzfTE2z0IYpzJMKYnl4BFaF7UEPl3uupH5k,19215
36
36
  maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  maleo_foundation/managers/client/base.py,sha256=K8AFV2MTZrC1jbTqxkx7eedmxodJirNIjoRXGGcppy4,1022
@@ -42,7 +42,7 @@ maleo_foundation/managers/client/google/base.py,sha256=1lrGoyGnYW5Xq05bVXbKqnsqq
42
42
  maleo_foundation/managers/client/google/secret.py,sha256=bWR_3Xl_wUFqj4M48w8ZE692U7PQKX9ap0ndDJviV80,3074
43
43
  maleo_foundation/managers/client/google/storage.py,sha256=041iSSaFubnZrP-pS8MiLVtOgeLQ591Iz64JekZ5K7o,2350
44
44
  maleo_foundation/middlewares/__init__.py,sha256=bqE2EIFC3rWcR2AwFPR0fk2kSFfeTRzgA24GbnuT5RA,3697
45
- maleo_foundation/middlewares/authentication.py,sha256=acMYZES6OPan6U15s8Nr5C1DC43U2Yz0MY-cla1Zkk4,3072
45
+ maleo_foundation/middlewares/authentication.py,sha256=y67sWz6FLl6NAtUWyK4mxC661dsBeKsDYRH3o7L_ZFQ,3188
46
46
  maleo_foundation/middlewares/base.py,sha256=3OaB5F57F3epKNieoAgarYM6PimoUdUl3DgpadtVuqs,11743
47
47
  maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
48
48
  maleo_foundation/models/__init__.py,sha256=AaKehO7c1HyKhoTGRmNHDddSeBXkW-_YNrpOGBu8Ms8,246
@@ -83,7 +83,7 @@ maleo_foundation/utils/logging.py,sha256=MwvZmZSA8SIdfq-knEvpYIgqnSpHcyHrZY9TVHW
83
83
  maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
84
84
  maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
85
85
  maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
86
- maleo_foundation-0.1.21.dist-info/METADATA,sha256=t2pn-zWyUPUUJU13xcpM0H4ipGlP7FJyfXq9MC_CA6Q,3190
87
- maleo_foundation-0.1.21.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
88
- maleo_foundation-0.1.21.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
89
- maleo_foundation-0.1.21.dist-info/RECORD,,
86
+ maleo_foundation-0.1.23.dist-info/METADATA,sha256=IyQWkb3bbyLlrfs-ah3AIHil03lB2s4zsOovEZ3FJOg,3190
87
+ maleo_foundation-0.1.23.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
88
+ maleo_foundation-0.1.23.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
89
+ maleo_foundation-0.1.23.dist-info/RECORD,,