Skip to content

Commit

Permalink
Merge pull request #50 from lionick/add_user_not_exists
Browse files Browse the repository at this point in the history
Add user if not exists, when ingesting a login and add warning messages
  • Loading branch information
lionick authored Jan 16, 2024
2 parents 642c19d + 81eb2c6 commit 64a4517
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 11 additions & 1 deletion app/ingester/loginsIngester.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def ingestLoginDataPerTenenv(cls, tenenv, session):
hash {0} as he is at the blacklist""". format(login[0]['voPersonId']))
continue

if (not login[0]['failedLogin']
if ((not login[0]['failedLogin'] or login[0]['failedLogin'] == 'false')
and utilsIngester.validateTenenv(login[0]['tenenvId'], session)
and 'voPersonId' in login[0]
and utilsIngester.validateHashedUser(login[0]['voPersonId'],
Expand Down Expand Up @@ -237,6 +237,16 @@ def ingestLoginDataPerTenenv(cls, tenenv, session):
loginMappedItems += 1
else:
cls.logger.warning("The record {0} was not imported due to validation errors".format(repr(login[0])))
cls.logger.warning("validateTenenv:")
cls.logger.warning(utilsIngester.validateTenenv(login[0]['tenenvId'], session))
cls.logger.warning("voPersonId in login[0]:")
cls.logger.warning('voPersonId' in login[0])
cls.logger.warning("validateHashedUser:")
cls.logger.warning(utilsIngester.validateHashedUser(login[0]['voPersonId'],
login[0]['tenenvId'],
session))
cls.logger.warning("validate if login is successful:")
cls.logger.warning(not login[0]['failedLogin'] or login[0]['failedLogin'] == 'false')

cls.logger.info("""
{0} new logins ingested""".format(loginMappedItems))
Expand Down
12 changes: 10 additions & 2 deletions app/ingester/utilsIngester.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def validateHashedUser(cls, hashedUser, tenenvId, session):
)
).one()
except NoResultFound:
cls.logger.info("User {0} not found".format(hashedUser))
return False
cls.logger.warning("""User {0} not found, we are going to create it
with default values.""".format(hashedUser))
now = date.today().strftime('%Y-%m-%d %H:%M:%S')
session.exec("""INSERT INTO users(hasheduserid, created, updated,
status, tenenv_id)
VALUES ('{0}','{1}','{1}', '{2}', {3})
""". format(
hashedUser, now, 'A',
tenenvId))
session.commit()
return True

0 comments on commit 64a4517

Please sign in to comment.