maleo-foundation 0.0.81__py3-none-any.whl → 0.0.83__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.
- maleo_foundation/clients/utils/logger.py +22 -1
- maleo_foundation/expanded_types/token.py +13 -0
- maleo_foundation/models/schemas/token.py +16 -0
- maleo_foundation/models/transfers/general/token.py +6 -1
- maleo_foundation/models/transfers/parameters/token.py +16 -0
- maleo_foundation/models/transfers/results/token.py +12 -0
- maleo_foundation/services/__init__.py +5 -0
- maleo_foundation/services/token.py +43 -0
- {maleo_foundation-0.0.81.dist-info → maleo_foundation-0.0.83.dist-info}/METADATA +2 -1
- {maleo_foundation-0.0.81.dist-info → maleo_foundation-0.0.83.dist-info}/RECORD +12 -6
- {maleo_foundation-0.0.81.dist-info → maleo_foundation-0.0.83.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.0.81.dist-info → maleo_foundation-0.0.83.dist-info}/top_level.txt +0 -0
|
@@ -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(
|
|
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,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.
|
|
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
|
|
@@ -12,7 +12,7 @@ maleo_foundation/clients/google/cloud/logging.py,sha256=b-q6Mhlt2Vl5HBh-YXeEEfGu
|
|
|
12
12
|
maleo_foundation/clients/google/cloud/secret.py,sha256=cFewA-EYsAaEfxc2G2XGzwHreW1FgyCK6MpwOARE24M,3452
|
|
13
13
|
maleo_foundation/clients/google/cloud/storage.py,sha256=y_HAsbcGSnu5sxZPxaQWFWvOlF3vEcqkej2834OgAS0,2617
|
|
14
14
|
maleo_foundation/clients/utils/__init__.py,sha256=hChEGABHH4tOFxPRcpxmlhkM9PgF18M7wXapH88hpu4,131
|
|
15
|
-
maleo_foundation/clients/utils/logger.py,sha256=
|
|
15
|
+
maleo_foundation/clients/utils/logger.py,sha256=FMnHKV4i6xR6e8XN7kCNwTf1jhSLdJUIO7teSm5g0D4,1829
|
|
16
16
|
maleo_foundation/db/__init__.py,sha256=fmvhCz4_siHfyKJujcUakKDKmuLxMhxn2w5tmfQwfcM,135
|
|
17
17
|
maleo_foundation/db/engine.py,sha256=kw2SMMiWy5KARquh4TLk7v6HwlHW97lUIUvqdFbhNxk,1600
|
|
18
18
|
maleo_foundation/db/manager.py,sha256=czs-6czNvKHZ7zWRX1nPpKJcdsadyX8R2DnZlA_6mlk,500
|
|
@@ -23,6 +23,7 @@ maleo_foundation/expanded_types/client.py,sha256=To0kRXp3QTmuSu5rWKaCiTsMK9qkYiy
|
|
|
23
23
|
maleo_foundation/expanded_types/general.py,sha256=bjIBREYTS73tvS-Key7P7db82a2HHlSJ1XBAvKuYmT0,826
|
|
24
24
|
maleo_foundation/expanded_types/query.py,sha256=0yUG-JIVsanzB7KAkrRz_OsrhP6J0bRqD9Q3l3atQnk,2384
|
|
25
25
|
maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rveduk2cFWzuhGw,2416
|
|
26
|
+
maleo_foundation/expanded_types/token.py,sha256=4fRTJw6W5MYq71NksNrWNi7qYHQ4_lQwfu9WxwrMipc,355
|
|
26
27
|
maleo_foundation/middlewares/__init__.py,sha256=bqE2EIFC3rWcR2AwFPR0fk2kSFfeTRzgA24GbnuT5RA,3697
|
|
27
28
|
maleo_foundation/middlewares/base.py,sha256=KcpODNs0DQXX8Cwc6T9dC6aiZIqxTLtuJjVAGWXPSKk,11633
|
|
28
29
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
|
@@ -32,14 +33,17 @@ maleo_foundation/models/schemas/__init__.py,sha256=Xj8Ahsqyra-fmEaVcGPok5GOOsPQl
|
|
|
32
33
|
maleo_foundation/models/schemas/general.py,sha256=hEQQPcddxMsJXMb36nqItIAfp3pqUyJOlaD7nXkNM2I,3609
|
|
33
34
|
maleo_foundation/models/schemas/parameter.py,sha256=K47z2NzmTEhUiOfRiRLyRPXoQurbWsKBL7ObXAxIWRY,2100
|
|
34
35
|
maleo_foundation/models/schemas/result.py,sha256=V3dljS2AdtWW4Pf8YsnQuiCylN1bZtEY1AtYC7okWuI,1747
|
|
36
|
+
maleo_foundation/models/schemas/token.py,sha256=u71kPXJyCxqn_INK05MSNFhQr9MaLfQM-icYc536xik,551
|
|
35
37
|
maleo_foundation/models/transfers/__init__.py,sha256=oJLJ3Geeme6vBw7R2Dhvdvg4ziVvzEYAGJaP-tm_90w,299
|
|
36
38
|
maleo_foundation/models/transfers/general/__init__.py,sha256=0yW67vJvKgJmZ9htteOVatG7mb-YEpHF62dpwH2g_Bk,146
|
|
37
|
-
maleo_foundation/models/transfers/general/token.py,sha256=
|
|
39
|
+
maleo_foundation/models/transfers/general/token.py,sha256=FrXIVgVBwOPTsri271WAkq54Sqa8WSzY75BzsNq2P6k,2411
|
|
38
40
|
maleo_foundation/models/transfers/parameters/__init__.py,sha256=oKW4RPIEISISRjsJzD8lsCGY1HhZRTzshPpWHcJu86k,353
|
|
39
41
|
maleo_foundation/models/transfers/parameters/client.py,sha256=tn_Hwa-k-Utp5rODe7GylqZB8djIKKupgkUFscYCyLc,4059
|
|
40
42
|
maleo_foundation/models/transfers/parameters/general.py,sha256=WoekZJCIoAllhXdRIJkNRdNq0QEIn0bteiHJLtzkCxU,579
|
|
41
43
|
maleo_foundation/models/transfers/parameters/service.py,sha256=d7Xy_R-DtLBRozyD6r8YnTiuKlE3sb9HMDCCq9WmUbY,6757
|
|
44
|
+
maleo_foundation/models/transfers/parameters/token.py,sha256=WTmCKoP-KJLqZjdwr__BeVnBrnRrsxzHSQ0IBaOKvqw,535
|
|
42
45
|
maleo_foundation/models/transfers/results/__init__.py,sha256=0_8uJ1IQW87RZ4nIxzWkQVi3Fxb7B8myZTngXfoxgNc,241
|
|
46
|
+
maleo_foundation/models/transfers/results/token.py,sha256=4zDgj8FWGK6Rcz_pprwnLcpRyyXKRBPbrCl3IOrRvVg,574
|
|
43
47
|
maleo_foundation/models/transfers/results/client/__init__.py,sha256=xBRuY0NUIPpQEGQ2qoBnqLZGX4W1YSrQ0VnDf5OYJBo,290
|
|
44
48
|
maleo_foundation/models/transfers/results/client/service.py,sha256=TO_U53vmUEnFWiiyuu33ao3BUidt6KFxvk3GC9uo8JE,1108
|
|
45
49
|
maleo_foundation/models/transfers/results/client/controllers/__init__.py,sha256=x5pcJ33rsG8SqecwL1g762DFoySisTLbZqOqKqKoaKU,173
|
|
@@ -49,6 +53,8 @@ maleo_foundation/models/transfers/results/service/general.py,sha256=G4x-MhQI7Km9
|
|
|
49
53
|
maleo_foundation/models/transfers/results/service/query.py,sha256=G5A4FRkHyRRlpuGWrPV5-vqgyyBjMqu8f-Ka9BjD0lA,1828
|
|
50
54
|
maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256=HZJWMy2dskzOCzLmp_UaL9rjbQ-sDMI7sd2bXb-4QOU,175
|
|
51
55
|
maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
|
|
56
|
+
maleo_foundation/services/__init__.py,sha256=Ho5zJSA89xdGFKIwOdzjmd8sm23cIuwrqYAxCEBBTIU,120
|
|
57
|
+
maleo_foundation/services/token.py,sha256=mULGv3wEeeFdNtk0k5pY3g7htFQM9EZBI1QIJdjfLy8,2348
|
|
52
58
|
maleo_foundation/utils/__init__.py,sha256=FavmL5XYGCm955EAKiWWcXYeU15p5rSzfcglpV2yI6c,387
|
|
53
59
|
maleo_foundation/utils/controller.py,sha256=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUUX6ipXBg,6396
|
|
54
60
|
maleo_foundation/utils/exceptions.py,sha256=nk3rD57fDR-D7BQkU1JEKV-Mu7FGMpLSEsqxdDZdKjU,4532
|
|
@@ -57,7 +63,7 @@ maleo_foundation/utils/logger.py,sha256=978P57JOhGR-WIu7xdPXBIwd3JrfLLA8WerVzxhE
|
|
|
57
63
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
|
58
64
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
|
59
65
|
maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
|
|
60
|
-
maleo_foundation-0.0.
|
|
61
|
-
maleo_foundation-0.0.
|
|
62
|
-
maleo_foundation-0.0.
|
|
63
|
-
maleo_foundation-0.0.
|
|
66
|
+
maleo_foundation-0.0.83.dist-info/METADATA,sha256=hcQI1xP2pmn5LhuQN-C33rh4M8WbI6jWz1hf2pauIw8,3190
|
|
67
|
+
maleo_foundation-0.0.83.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
|
68
|
+
maleo_foundation-0.0.83.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
|
69
|
+
maleo_foundation-0.0.83.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|