rb-commons 0.1.8__py3-none-any.whl → 0.1.9__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.
rb_commons/schemes/jwt.py CHANGED
@@ -13,41 +13,38 @@ class UserRole(str, Enum):
13
13
  class Claims(BaseModel):
14
14
  model_config = ConfigDict(extra="ignore")
15
15
 
16
- class Claims(BaseModel):
17
- model_config = ConfigDict(extra="ignore")
18
-
19
- user_id: Optional[int] = Field(None, alias="x-user-id")
20
- user_role: UserRole = Field(UserRole.GUEST, alias="x-user-role")
21
- shop_id: Optional[uuid.UUID] = Field(None, alias="x-shop-id")
22
-
23
- @classmethod
24
- def from_headers(cls, headers: dict) -> 'Claims':
25
- raw_claims = {
26
- "x-user-id": headers.get("x-user-id"),
27
- "x-user-role": headers.get("x-user-role"),
28
- "x-shop-id": headers.get("x-shop-id")
29
- }
30
-
31
- try:
32
- if raw_claims["x-user-id"]:
33
- try:
34
- raw_claims["x-user-id"] = int(raw_claims["x-user-id"])
35
- except ValueError as e:
36
- raise ValueError(f"Invalid user_id format: {e}")
37
-
38
- if raw_claims["x-shop-id"]:
39
- try:
40
- raw_claims["x-shop-id"] = uuid.UUID(raw_claims["x-shop-id"])
41
- except ValueError as e:
42
- raise ValueError(f"Invalid shop_id format: {e}")
43
-
44
- if raw_claims["x-user-role"]:
45
- try:
46
- UserRole(raw_claims["x-user-role"].lower())
47
- except ValueError as e:
48
- raise ValueError(f"Invalid user_role: {e}")
49
-
50
- return cls(**raw_claims)
51
-
52
- except Exception as e:
53
- raise ValueError(f"Failed to parse claims: {str(e)}")
16
+ user_id: Optional[int] = Field(None, alias="x-user-id")
17
+ user_role: UserRole = Field(UserRole.GUEST, alias="x-user-role")
18
+ shop_id: Optional[uuid.UUID] = Field(None, alias="x-shop-id")
19
+
20
+ @classmethod
21
+ def from_headers(cls, headers: dict) -> 'Claims':
22
+ raw_claims = {
23
+ "x-user-id": headers.get("x-user-id"),
24
+ "x-user-role": headers.get("x-user-role"),
25
+ "x-shop-id": headers.get("x-shop-id")
26
+ }
27
+
28
+ try:
29
+ if raw_claims["x-user-id"]:
30
+ try:
31
+ raw_claims["x-user-id"] = int(raw_claims["x-user-id"])
32
+ except ValueError as e:
33
+ raise ValueError(f"Invalid user_id format: {e}")
34
+
35
+ if raw_claims["x-shop-id"]:
36
+ try:
37
+ raw_claims["x-shop-id"] = uuid.UUID(raw_claims["x-shop-id"])
38
+ except ValueError as e:
39
+ raise ValueError(f"Invalid shop_id format: {e}")
40
+
41
+ if raw_claims["x-user-role"]:
42
+ try:
43
+ UserRole(raw_claims["x-user-role"].lower())
44
+ except ValueError as e:
45
+ raise ValueError(f"Invalid user_role: {e}")
46
+
47
+ return cls(**raw_claims)
48
+
49
+ except Exception as e:
50
+ raise ValueError(f"Failed to parse claims: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rb-commons
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/Abdulvoris101/rb-commons
6
6
  Author: Abdulvoris
@@ -5,8 +5,8 @@ rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
6
6
  rb_commons/orm/managers.py,sha256=VopUw29sCXrPTriBALR9qwkG5yCu6BDHRgR7cCygNiE,6726
7
7
  rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- rb_commons/schemes/jwt.py,sha256=ZyUtcZuYmBoEpmnurArs0gWoYGhZ3y-0NsirHfxlnAo,1865
9
- rb_commons-0.1.8.dist-info/METADATA,sha256=VXmiZwkYkGQZ36sBl1yZkcuYA4ismeXsxjuAk5Z_aUo,6276
10
- rb_commons-0.1.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
11
- rb_commons-0.1.8.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
12
- rb_commons-0.1.8.dist-info/RECORD,,
8
+ rb_commons/schemes/jwt.py,sha256=4dYL0Bg9kO7kiNgV0J1gBdhh8bYxm75cuqrWCwkV4iE,1666
9
+ rb_commons-0.1.9.dist-info/METADATA,sha256=rMgfARa41IWEQsTE3AuMYtds_-n4DO_nJM0Lz3sMjDk,6276
10
+ rb_commons-0.1.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
11
+ rb_commons-0.1.9.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
12
+ rb_commons-0.1.9.dist-info/RECORD,,