scruby 2.7.1__py3-none-any.whl → 2.7.2__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.
- scruby/db.py +1 -1
- scruby/models/crypt_model.py +24 -10
- {scruby-2.7.1.dist-info → scruby-2.7.2.dist-info}/METADATA +1 -1
- {scruby-2.7.1.dist-info → scruby-2.7.2.dist-info}/RECORD +7 -7
- {scruby-2.7.1.dist-info → scruby-2.7.2.dist-info}/WHEEL +0 -0
- {scruby-2.7.1.dist-info → scruby-2.7.2.dist-info}/licenses/GPL-3.0-LICENSE +0 -0
- {scruby-2.7.1.dist-info → scruby-2.7.2.dist-info}/licenses/MIT-LICENSE +0 -0
scruby/db.py
CHANGED
|
@@ -46,7 +46,7 @@ class Scruby(
|
|
|
46
46
|
#
|
|
47
47
|
if __debug__:
|
|
48
48
|
if ScrubyModel not in class_model.__bases__:
|
|
49
|
-
msg = "
|
|
49
|
+
msg = "Argument `class_model` does not contain the base class `ScrubyModel`."
|
|
50
50
|
raise AssertionError(msg)
|
|
51
51
|
if "key" not in self.key_list:
|
|
52
52
|
msg = f"Model: {class_model.__name__} => The `key` field is missing."
|
scruby/models/crypt_model.py
CHANGED
|
@@ -34,7 +34,7 @@ class CryptModel(BaseModel):
|
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
def hash_raw_password(self, password: str | SecretStr) -> str:
|
|
37
|
-
"""Takes
|
|
37
|
+
"""Takes the raw password string and converts it into a hash.
|
|
38
38
|
|
|
39
39
|
Uses the bcrypt library.
|
|
40
40
|
|
|
@@ -54,7 +54,7 @@ class CryptModel(BaseModel):
|
|
|
54
54
|
return hashed_bytes.decode("utf-8")
|
|
55
55
|
|
|
56
56
|
def set_password(self, password: str | SecretStr) -> None:
|
|
57
|
-
"""Converts the
|
|
57
|
+
"""Converts the raw password to a hash and adds it to the password field.
|
|
58
58
|
|
|
59
59
|
Uses the bcrypt library.
|
|
60
60
|
|
|
@@ -64,10 +64,16 @@ class CryptModel(BaseModel):
|
|
|
64
64
|
Returns:
|
|
65
65
|
None
|
|
66
66
|
"""
|
|
67
|
-
assert isinstance(password, (str, SecretStr)), "Valid type: str | SecretStr"
|
|
67
|
+
assert isinstance(password, (str, SecretStr)), "Valid type: str | SecretStr."
|
|
68
|
+
#
|
|
69
|
+
# Throw an exception if the password is present
|
|
70
|
+
if bool(self.password):
|
|
71
|
+
msg = "The password already exists. To update it, use the `update_password` method."
|
|
72
|
+
raise ValueError(msg)
|
|
68
73
|
#
|
|
69
74
|
hashed_password = self.hash_raw_password(password)
|
|
70
|
-
#
|
|
75
|
+
# Set user password.
|
|
76
|
+
# Hint: To temporarily bypass the `frozen=True` limitation.
|
|
71
77
|
object.__setattr__(self, "password", hashed_password) # noqa: PLC2801
|
|
72
78
|
|
|
73
79
|
def password_is_valid(self, password: str | SecretStr) -> bool:
|
|
@@ -82,7 +88,7 @@ class CryptModel(BaseModel):
|
|
|
82
88
|
Returns:
|
|
83
89
|
True if the passwords are the same and False if they are not the same.
|
|
84
90
|
"""
|
|
85
|
-
assert isinstance(password, (str, SecretStr)), "Valid type: str | SecretStr"
|
|
91
|
+
assert isinstance(password, (str, SecretStr)), "Valid type: str | SecretStr."
|
|
86
92
|
#
|
|
87
93
|
if not bool(self.password):
|
|
88
94
|
return False
|
|
@@ -107,15 +113,23 @@ class CryptModel(BaseModel):
|
|
|
107
113
|
ValueError: If the current password cannot be updated because it is missing.
|
|
108
114
|
ValueError: If the old password does not match the current one.
|
|
109
115
|
"""
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
if __debug__:
|
|
117
|
+
if not isinstance(old_password, (str, SecretStr)):
|
|
118
|
+
msg = "Argument: `old_password` => Valid type: str | SecretStr."
|
|
119
|
+
raise AssertionError(msg)
|
|
120
|
+
if not isinstance(new_password, (str, SecretStr)):
|
|
121
|
+
msg = "Argument: `new_password` => Valid type: str | SecretStr."
|
|
122
|
+
raise AssertionError(msg)
|
|
112
123
|
#
|
|
113
124
|
# Throw an exception if the current password is missing
|
|
114
|
-
if self.password
|
|
115
|
-
msg = "The current password cannot be updated because it is missing"
|
|
125
|
+
if not bool(self.password):
|
|
126
|
+
msg = "The current password cannot be updated because it is missing."
|
|
116
127
|
raise ValueError(msg)
|
|
117
128
|
# Throw an exception if the old password does not match the current one
|
|
118
129
|
if not self.password_is_valid(old_password):
|
|
119
|
-
raise ValueError("Old password doesn't match")
|
|
130
|
+
raise ValueError("Old password doesn't match.")
|
|
131
|
+
# Pre-reset the password to default state.
|
|
132
|
+
# Hint: To temporarily bypass the `frozen=True` limitation.
|
|
133
|
+
object.__setattr__(self, "password", None) # noqa: PLC2801
|
|
120
134
|
# Replace the current password with a new one
|
|
121
135
|
self.set_password(new_password)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 2.7.
|
|
3
|
+
Version: 2.7.2
|
|
4
4
|
Summary: Asynchronous library for building and managing a hybrid database, by scheme of key-value.
|
|
5
5
|
Project-URL: Bug Tracker, https://github.com/kebasyaty/scruby/issues
|
|
6
6
|
Project-URL: Changelog, https://github.com/kebasyaty/scruby/blob/v2/CHANGELOG.md
|
|
@@ -2,7 +2,7 @@ scruby/__init__.py,sha256=rHX2oQahEBft6ZDh1lLE2YxP5ZoMfP4m7PBBUfEGuJw,1399
|
|
|
2
2
|
scruby/aggregation.py,sha256=NBFxQqyRqUG2KIuD9fbl4uzSHJWTaskjiZ1YNBa-Zbo,3575
|
|
3
3
|
scruby/cache.py,sha256=DRcTdQbh1DhTQDGK5oC_mZrjcQg6g06vJ1e61RfNX94,3864
|
|
4
4
|
scruby/config.py,sha256=clGj5_CyHEejmQUvtV0fD9PoQoPeYoh0Wge_i2BIMsg,5255
|
|
5
|
-
scruby/db.py,sha256=
|
|
5
|
+
scruby/db.py,sha256=J1WldCYoWtNTo1T6QGQ4n0rVYR6D8Kv6oesOBUejn60,8423
|
|
6
6
|
scruby/errors.py,sha256=lTWiHzyO5Es9Nkf7quODJjONGn6ifcL95qlpA4epQQM,1386
|
|
7
7
|
scruby/meta.py,sha256=6HPgqqlKH7Vo6ibyGzxR3DzNcnc_DmjaP5q8s6kl4yA,1230
|
|
8
8
|
scruby/migration.py,sha256=mmJkqVBd_eoufWD8YsRq09VCZFZzEwfxsU1gtvJnjvU,1730
|
|
@@ -17,10 +17,10 @@ scruby/mixins/find.py,sha256=YlK8L5R5qnjooDR_WDkd6ckPgE8dNTTee31S4P8-Wuo,10504
|
|
|
17
17
|
scruby/mixins/keys.py,sha256=sd8vcM0YXouVwwgsQwtYFaV3RyAEfygpPf4a77_hN6A,11305
|
|
18
18
|
scruby/mixins/update.py,sha256=TyxvxB-gNijlfzTmhwrq0ydvu0C3R-RihW5h5tJ96bM,4964
|
|
19
19
|
scruby/models/__init__.py,sha256=Xqk48ZYWzmrygqoi7R9O8dJdd40ochwTg-vmCDkZUY8,418
|
|
20
|
-
scruby/models/crypt_model.py,sha256=
|
|
20
|
+
scruby/models/crypt_model.py,sha256=6ia-fZzvPh0fxDIkBXp1m3E538xtjeI0OoxaY25tnNE,4564
|
|
21
21
|
scruby/models/scruby_model.py,sha256=u9uAF1_aBvaooSeKPzQRmVYHPy4XWusLX85xfzc6oVM,608
|
|
22
|
-
scruby-2.7.
|
|
23
|
-
scruby-2.7.
|
|
24
|
-
scruby-2.7.
|
|
25
|
-
scruby-2.7.
|
|
26
|
-
scruby-2.7.
|
|
22
|
+
scruby-2.7.2.dist-info/METADATA,sha256=2thGMIKe3ytqOQgHERbvC5ef74T_0JDozEjpJ8QgX1I,15272
|
|
23
|
+
scruby-2.7.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
24
|
+
scruby-2.7.2.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
25
|
+
scruby-2.7.2.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
|
|
26
|
+
scruby-2.7.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|