Skip to content

Commit

Permalink
fix core-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
shay-te committed Nov 28, 2023
1 parent 4aa2005 commit b4df702
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core_lib/helpers/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def is_int(val) -> bool:
#
# complex
#
EMAIL_CHECK_REGEX = r'^\b[\w\D][^<>\[\]]+@[\w.-]+\.[A-Z|a-z]{2,}\b$'
def is_email(email: str) -> bool:
regex = r'\b[\w\D][^<>\[\]]+@[\w.-]+\.[A-Z|a-z]{2,}\b'
if email is None:
return False
return True if re.fullmatch(regex, email) else False
return True if re.fullmatch(EMAIL_CHECK_REGEX, email) else False


def is_int_enum(int_value: int, enum: IntEnum) -> bool:
Expand Down
5 changes: 4 additions & 1 deletion core_lib/rule_validator/rule_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def __init__(
self.prohibited_keys = prohibited_keys

self.rules = {}
for rule_validator in value_rule_validators:
self.update(value_rule_validators)

def update(self, additional_validators):
for rule_validator in additional_validators:
if not isinstance(rule_validator, ValueRuleValidator):
raise ValueError(
f'RuleValidator.value_rule_validators can only be from type '
Expand Down
3 changes: 3 additions & 0 deletions core_lib/rule_validator/rule_validator_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __wrapper(*args, **kwargs):
f'Apply only when updating the database with `dict` parameters '
)

if 'additional_validators' in kwargs and type(kwargs['additional_validators']) is list:
self.rule_validator.update(kwargs['additional_validators'])

updated_dict = self.rule_validator.validate_dict(
update_dict,
strict_mode=self.strict_mode,
Expand Down
3 changes: 2 additions & 1 deletion core_lib/session/jwt_token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def __init__(self, secret, expiration_time: timedelta, verify: bool = False, alg
self._logger = logging.getLogger(self.__class__.__name__)

def encode(self, message: dict) -> str:
if 'exp' not in message and self._expiration_time:
if self._expiration_time:
message['exp'] = (datetime.utcnow() + self._expiration_time).timestamp()

return jwt.encode(message, self._secret, algorithm=self._algorithm)

def decode(self, encoded):
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Core lib
hydra-core
hydra-core==1.2
python-dateutil
PyJWT
argh
Expand Down Expand Up @@ -37,5 +37,4 @@ python-dotenv
moto
freezegun
mongomock
flask_wtf
elasticsearch~=8.9.0
flask_wtf

0 comments on commit b4df702

Please sign in to comment.