maleo-foundation 0.0.81__tar.gz → 0.0.83__tar.gz

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.
Files changed (74) hide show
  1. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/PKG-INFO +2 -1
  2. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/utils/logger.py +22 -1
  3. maleo_foundation-0.0.83/maleo_foundation/expanded_types/token.py +13 -0
  4. maleo_foundation-0.0.83/maleo_foundation/models/schemas/token.py +16 -0
  5. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/general/token.py +6 -1
  6. maleo_foundation-0.0.83/maleo_foundation/models/transfers/parameters/token.py +16 -0
  7. maleo_foundation-0.0.83/maleo_foundation/models/transfers/results/token.py +12 -0
  8. maleo_foundation-0.0.83/maleo_foundation/services/__init__.py +5 -0
  9. maleo_foundation-0.0.83/maleo_foundation/services/token.py +43 -0
  10. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation.egg-info/PKG-INFO +2 -1
  11. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation.egg-info/SOURCES.txt +6 -0
  12. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation.egg-info/requires.txt +1 -0
  13. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/pyproject.toml +2 -1
  14. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/README.md +0 -0
  15. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/__init__.py +0 -0
  16. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/__init__.py +0 -0
  17. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/general/__init__.py +0 -0
  18. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/general/http.py +0 -0
  19. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/google/__init__.py +0 -0
  20. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/google/cloud/__init__.py +0 -0
  21. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/google/cloud/logging.py +0 -0
  22. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/google/cloud/secret.py +0 -0
  23. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/google/cloud/storage.py +0 -0
  24. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/clients/utils/__init__.py +0 -0
  25. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/constants.py +0 -0
  26. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/db/__init__.py +0 -0
  27. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/db/engine.py +0 -0
  28. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/db/manager.py +0 -0
  29. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/db/session.py +0 -0
  30. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/db/table.py +0 -0
  31. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/enums.py +0 -0
  32. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/expanded_types/__init__.py +0 -0
  33. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/expanded_types/client.py +0 -0
  34. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/expanded_types/general.py +0 -0
  35. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/expanded_types/query.py +0 -0
  36. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/expanded_types/service.py +0 -0
  37. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/extended_types.py +0 -0
  38. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/middlewares/__init__.py +0 -0
  39. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/middlewares/base.py +0 -0
  40. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/middlewares/cors.py +0 -0
  41. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/__init__.py +0 -0
  42. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/responses.py +0 -0
  43. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/schemas/__init__.py +0 -0
  44. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/schemas/general.py +0 -0
  45. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/schemas/parameter.py +0 -0
  46. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/schemas/result.py +0 -0
  47. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/__init__.py +0 -0
  48. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/general/__init__.py +0 -0
  49. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
  50. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/parameters/client.py +0 -0
  51. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/parameters/general.py +0 -0
  52. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/parameters/service.py +0 -0
  53. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/__init__.py +0 -0
  54. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
  55. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
  56. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
  57. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/client/service.py +0 -0
  58. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
  59. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
  60. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
  61. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/service/general.py +0 -0
  62. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/models/transfers/results/service/query.py +0 -0
  63. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/types.py +0 -0
  64. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/__init__.py +0 -0
  65. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/controller.py +0 -0
  66. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/exceptions.py +0 -0
  67. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/formatter/__init__.py +0 -0
  68. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/formatter/case.py +0 -0
  69. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/keyloader.py +0 -0
  70. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/logger.py +0 -0
  71. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation/utils/query.py +0 -0
  72. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation.egg-info/dependency_links.txt +0 -0
  73. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/maleo_foundation.egg-info/top_level.txt +0 -0
  74. {maleo_foundation-0.0.81 → maleo_foundation-0.0.83}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.81
3
+ Version: 0.0.83
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -57,6 +57,7 @@ Requires-Dist: pycparser>=2.22
57
57
  Requires-Dist: pydantic>=2.11.3
58
58
  Requires-Dist: pydantic_core>=2.33.1
59
59
  Requires-Dist: Pygments>=2.19.1
60
+ Requires-Dist: PyJWT>=2.10.1
60
61
  Requires-Dist: pyproject_hooks>=1.2.0
61
62
  Requires-Dist: readme_renderer>=44.0
62
63
  Requires-Dist: requests>=2.32.3
@@ -30,4 +30,25 @@ class ClientLoggerManager:
30
30
  """Return client logger (if exist) or raise Runtime Error"""
31
31
  if cls not in cls._loggers:
32
32
  raise RuntimeError("Logger has not been initialized. Call 'initialize' first.")
33
- return cls._loggers[cls]
33
+ return cls._loggers[cls]
34
+
35
+ class MaleoFoundationLoggerManager(ClientLoggerManager):
36
+ @classmethod
37
+ def initialize(
38
+ cls,
39
+ base_dir:str,
40
+ service_name:BaseTypes.OptionalString = None,
41
+ level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
42
+ ) -> BaseLogger:
43
+ """Initialize MaleoFoundation's client logger if not already initialized."""
44
+ return super().initialize(
45
+ base_dir=base_dir,
46
+ client_name="MaleoFoundation",
47
+ service_name=service_name,
48
+ level=level
49
+ )
50
+
51
+ @classmethod
52
+ def get(cls) -> BaseLogger:
53
+ """Return client logger (if exist) or raise Runtime Error"""
54
+ return super().get()
@@ -0,0 +1,13 @@
1
+ from typing import Union
2
+ from maleo_foundation.models.transfers.results.token import BaseTokenResultsTransfers
3
+
4
+ class BaseTokenResultsTypes:
5
+ Encode = Union[
6
+ BaseTokenResultsTransfers.Fail,
7
+ BaseTokenResultsTransfers.Encode
8
+ ]
9
+
10
+ Decode = Union[
11
+ BaseTokenResultsTransfers.Fail,
12
+ BaseTokenResultsTransfers.Decode
13
+ ]
@@ -0,0 +1,16 @@
1
+ from __future__ import annotations
2
+ from pydantic import BaseModel, Field
3
+ from maleo_foundation.types import BaseTypes
4
+
5
+ class BaseTokenSchemas:
6
+ class Key(BaseModel):
7
+ key:str = Field(..., description="Key")
8
+
9
+ class Password(BaseModel):
10
+ password:BaseTypes.OptionalString = Field(None, min_length=32, max_length=1024, description="password")
11
+
12
+ class Token(BaseModel):
13
+ token:str = Field(..., description="Token")
14
+
15
+ class ExpIn(BaseModel):
16
+ exp_in:int = Field(5, ge=5, description="Expires in (integer, minutes)")
@@ -1,6 +1,8 @@
1
+ from __future__ import annotations
1
2
  from pydantic import BaseModel, Field, model_validator
2
3
  from datetime import datetime, timedelta, timezone
3
4
  from maleo_foundation.types import BaseTypes
5
+ from maleo_foundation.models.schemas.token import BaseTokenSchemas
4
6
 
5
7
  class BaseTokenGeneralTransfers:
6
8
  class BasePayload(BaseModel):
@@ -13,12 +15,15 @@ class BaseTokenGeneralTransfers:
13
15
  uor:BaseTypes.OptionalListOfStrings = Field(..., description="User Organization Role")
14
16
 
15
17
  class DecodePayload(BasePayload):
16
- iat_dt:datetime = Field(datetime.now(timezone.utc), description="Issued at (datetime)")
18
+ iat_dt:datetime = Field(..., description="Issued at (datetime)")
17
19
  iat:int = Field(..., description="Issued at (integer)")
18
20
  exp_dt:datetime = Field(..., description="Expired at (datetime)")
19
21
  exp:int = Field(..., description="Expired at (integet)")
20
22
 
23
+ class BaseEncodePayload(BasePayload, BaseTokenSchemas.ExpIn): pass
24
+
21
25
  class EncodePayload(DecodePayload):
26
+ iat_dt:datetime = Field(datetime.now(timezone.utc), description="Issued at (datetime)")
22
27
  exp_in:int = Field(5, ge=5, description="Expires in (integer, minutes)", exclude=True)
23
28
 
24
29
  @model_validator(mode="before")
@@ -0,0 +1,16 @@
1
+ from __future__ import annotations
2
+ from pydantic import Field
3
+ from maleo_foundation.models.schemas.token import BaseTokenSchemas
4
+ from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
5
+
6
+ class BaseTokenParametersTransfers:
7
+ class Encode(
8
+ BaseTokenSchemas.Password,
9
+ BaseTokenSchemas.Key
10
+ ):
11
+ payload:BaseTokenGeneralTransfers.BaseEncodePayload = Field(..., description="Encode payload")
12
+
13
+ class Decode(
14
+ BaseTokenSchemas.Token,
15
+ BaseTokenSchemas.Key
16
+ ): pass
@@ -0,0 +1,12 @@
1
+ from maleo_foundation.models.transfers.results.service.general import BaseServiceGeneralResultsTransfers
2
+ from maleo_foundation.models.schemas.token import BaseTokenSchemas
3
+ from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
4
+
5
+ class BaseTokenResultsTransfers:
6
+ class Fail(BaseServiceGeneralResultsTransfers.Fail): pass
7
+
8
+ class Encode(BaseServiceGeneralResultsTransfers.SingleData):
9
+ data:BaseTokenSchemas.Token
10
+
11
+ class Decode(BaseServiceGeneralResultsTransfers.SingleData):
12
+ data:BaseTokenGeneralTransfers.DecodePayload
@@ -0,0 +1,5 @@
1
+ from __future__ import annotations
2
+ from .token import BaseTokenService
3
+
4
+ class BaseServices:
5
+ Token = BaseTokenService
@@ -0,0 +1,43 @@
1
+ import jwt
2
+ from cryptography.hazmat.primitives import serialization
3
+ from cryptography.hazmat.backends import default_backend
4
+ from maleo_foundation.clients.utils.logger import MaleoFoundationLoggerManager
5
+ from maleo_foundation.utils.exceptions import BaseExceptions
6
+ from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
7
+ from maleo_foundation.models.schemas.token import BaseTokenSchemas
8
+ from maleo_foundation.models.transfers.parameters.token import BaseTokenParametersTransfers
9
+ from maleo_foundation.models.transfers.results.token import BaseTokenResultsTransfers
10
+ from maleo_foundation.expanded_types.token import BaseTokenResultsTypes
11
+
12
+ class BaseTokenService:
13
+ @staticmethod
14
+ @BaseExceptions.service_exception_handler(
15
+ operation="encoding a payload",
16
+ logger_factory=MaleoFoundationLoggerManager.get,
17
+ fail_result_class=BaseTokenResultsTransfers.Fail
18
+ )
19
+ def encode(parameters:BaseTokenParametersTransfers.Encode) -> BaseTokenResultsTypes.Encode:
20
+ #* Serialize private key
21
+ private_key_bytes = parameters.key.encode()
22
+ private_key = serialization.load_pem_private_key(
23
+ private_key_bytes,
24
+ password=parameters.password.encode() if parameters.password else None,
25
+ backend=default_backend()
26
+ )
27
+ payload = BaseTokenGeneralTransfers.EncodePayload.model_validate(parameters.payload.model_dump()).model_dump(mode="json")
28
+ token = jwt.encode(payload=payload, key=private_key, algorithm="RS256")
29
+ data = BaseTokenSchemas.Token(token=token)
30
+ MaleoFoundationLoggerManager.get().info("Payload successfully encoded")
31
+ return BaseTokenResultsTransfers.Encode(data=data)
32
+
33
+ @staticmethod
34
+ @BaseExceptions.service_exception_handler(
35
+ operation="decoding a token",
36
+ logger_factory=MaleoFoundationLoggerManager.get,
37
+ fail_result_class=BaseTokenResultsTransfers.Fail
38
+ )
39
+ def decode(parameters:BaseTokenParametersTransfers.Decode) -> BaseTokenResultsTypes.Decode:
40
+ payload = jwt.decode(jwt=parameters.token, key=parameters.key, algorithms=["RS256"])
41
+ data = BaseTokenGeneralTransfers.DecodePayload.model_validate(payload)
42
+ MaleoFoundationLoggerManager.get().info("Token successfully decoded")
43
+ return BaseTokenResultsTransfers.Decode(data=data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.81
3
+ Version: 0.0.83
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -57,6 +57,7 @@ Requires-Dist: pycparser>=2.22
57
57
  Requires-Dist: pydantic>=2.11.3
58
58
  Requires-Dist: pydantic_core>=2.33.1
59
59
  Requires-Dist: Pygments>=2.19.1
60
+ Requires-Dist: PyJWT>=2.10.1
60
61
  Requires-Dist: pyproject_hooks>=1.2.0
61
62
  Requires-Dist: readme_renderer>=44.0
62
63
  Requires-Dist: requests>=2.32.3
@@ -30,6 +30,7 @@ maleo_foundation/expanded_types/client.py
30
30
  maleo_foundation/expanded_types/general.py
31
31
  maleo_foundation/expanded_types/query.py
32
32
  maleo_foundation/expanded_types/service.py
33
+ maleo_foundation/expanded_types/token.py
33
34
  maleo_foundation/middlewares/__init__.py
34
35
  maleo_foundation/middlewares/base.py
35
36
  maleo_foundation/middlewares/cors.py
@@ -39,6 +40,7 @@ maleo_foundation/models/schemas/__init__.py
39
40
  maleo_foundation/models/schemas/general.py
40
41
  maleo_foundation/models/schemas/parameter.py
41
42
  maleo_foundation/models/schemas/result.py
43
+ maleo_foundation/models/schemas/token.py
42
44
  maleo_foundation/models/transfers/__init__.py
43
45
  maleo_foundation/models/transfers/general/__init__.py
44
46
  maleo_foundation/models/transfers/general/token.py
@@ -46,7 +48,9 @@ maleo_foundation/models/transfers/parameters/__init__.py
46
48
  maleo_foundation/models/transfers/parameters/client.py
47
49
  maleo_foundation/models/transfers/parameters/general.py
48
50
  maleo_foundation/models/transfers/parameters/service.py
51
+ maleo_foundation/models/transfers/parameters/token.py
49
52
  maleo_foundation/models/transfers/results/__init__.py
53
+ maleo_foundation/models/transfers/results/token.py
50
54
  maleo_foundation/models/transfers/results/client/__init__.py
51
55
  maleo_foundation/models/transfers/results/client/service.py
52
56
  maleo_foundation/models/transfers/results/client/controllers/__init__.py
@@ -56,6 +60,8 @@ maleo_foundation/models/transfers/results/service/general.py
56
60
  maleo_foundation/models/transfers/results/service/query.py
57
61
  maleo_foundation/models/transfers/results/service/controllers/__init__.py
58
62
  maleo_foundation/models/transfers/results/service/controllers/rest.py
63
+ maleo_foundation/services/__init__.py
64
+ maleo_foundation/services/token.py
59
65
  maleo_foundation/utils/__init__.py
60
66
  maleo_foundation/utils/controller.py
61
67
  maleo_foundation/utils/exceptions.py
@@ -49,6 +49,7 @@ pycparser>=2.22
49
49
  pydantic>=2.11.3
50
50
  pydantic_core>=2.33.1
51
51
  Pygments>=2.19.1
52
+ PyJWT>=2.10.1
52
53
  pyproject_hooks>=1.2.0
53
54
  readme_renderer>=44.0
54
55
  requests>=2.32.3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maleo_foundation"
7
- version = "0.0.81"
7
+ version = "0.0.83"
8
8
  description = "Foundation package for Maleo"
9
9
  authors = [
10
10
  { name = "Agra Bima Yuda", email = "agra@nexmedis.com" }
@@ -64,6 +64,7 @@ dependencies = [
64
64
  "pydantic>=2.11.3",
65
65
  "pydantic_core>=2.33.1",
66
66
  "Pygments>=2.19.1",
67
+ "PyJWT>=2.10.1",
67
68
  "pyproject_hooks>=1.2.0",
68
69
  "readme_renderer>=44.0",
69
70
  "requests>=2.32.3",