Add some more convenience to validator

This commit is contained in:
Mario Voigt 2025-03-04 01:14:43 +01:00
parent ca75ec2f3a
commit ccfd1ed924

15
validate.py Normal file → Executable file
View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
''' '''
This script validates users.toml for several aspects This script validates users.toml for several aspects
The script requires at least Python 3.11 The script requires at least Python 3.11
@ -36,8 +38,15 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if args.db is None: if args.db is None:
print("Error: no users.toml given. Please add with '--db </path/to/users.toml>'") usertoml = args.db
sys.exit(1) print("No custom users.toml given. You may add it with '--db </path/to/users.toml>'")
default_usertoml = "/etc/bffh/users.toml"
if os.path.isfile(default_usertoml):
print("Found default file: {}. Using this ...".format(default_usertoml))
usertoml = default_usertoml
else:
print("Error: no (default) users.toml file given or found. Cannot continue!".format(default_usertoml))
sys.exit(1)
countUsers = 0 countUsers = 0
countUsersWithoutCardkeyOrPassword = 0 countUsersWithoutCardkeyOrPassword = 0
@ -58,8 +67,6 @@ def main():
#a definition of valid keys within a user section of FabAccess #a definition of valid keys within a user section of FabAccess
knownKeys = ['roles', 'passwd', 'cardkey'] knownKeys = ['roles', 'passwd', 'cardkey']
usertoml = args.db
print("{} Checking database {}\n".format("*"*25, "*"*25)) print("{} Checking database {}\n".format("*"*25, "*"*25))
file_stats = os.stat(usertoml) file_stats = os.stat(usertoml)