Update validate.py

fix https://github.com/vmario89/fabaccess-users-toml-validator/issues/3
This commit is contained in:
Mario Voigt 2025-01-03 16:39:22 +01:00 committed by GitHub
parent bd9bfe28fe
commit ca75ec2f3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,6 +43,7 @@ def main():
countUsersWithoutCardkeyOrPassword = 0
uniqueRoles = []
countUserWithoutRoles = 0
countUserWithDuplicateRoles = 0
countPassword = 0
countPasswordUnencrypted = 0
countPasswordEncrypted = 0
@ -101,7 +102,16 @@ def main():
if type(roles) != list:
print("Warning: roles for user '{}' are not defined as array! BFFH will fail to load".format(user))
countWarnings += 1
userRoles = []
for role in roles:
# check if a role is duplicate in the array for the user
if role not in userRoles:
userRoles.append(role)
else:
print("Warning: duplicate role '{}' for user '{}'".format(role, user))
countUserWithDuplicateRoles += 1
countWarnings += 1
# collect all unique roles for the toml file
if role not in uniqueRoles:
uniqueRoles.append(role)
if roles is None: #if role key is defined but empty
@ -172,6 +182,9 @@ def main():
if countUserWithoutRoles > 0:
print("- {} users without any roles. They won't be able to do something as client!".format(countUserWithoutRoles))
if countUserWithDuplicateRoles > 0:
print("- {} users with duplicate roles. Please clean up!".format(countUserWithDuplicateRoles))
if len(uniqueRoles) == 0:
print("- Globally, there are no roles assigned for any user. They won't be able to do something as client!")