implement a command to test for a user's existence

This commit is contained in:
Jakob Ketterl 2021-02-18 15:42:12 +01:00
parent 06d4b24b09
commit c09f17579c
2 changed files with 21 additions and 1 deletions

View File

@ -1,5 +1,5 @@
from owrx.version import openwebrx_version
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser, HasUser
import argparse
import sys
import traceback
@ -36,6 +36,10 @@ def main():
enableuser_parser.add_argument("user", help="Username to be enabled")
enableuser_parser.set_defaults(cls=EnableUser)
hasuser_parser = subparsers.add_parser("hasuser", help="Test if a user exists")
hasuser_parser.add_argument("user", help="Username to be checked")
hasuser_parser.set_defaults(cls=HasUser)
parser.add_argument("-v", "--version", action="store_true", help="Show the software version")
parser.add_argument(
"--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)"

View File

@ -97,3 +97,19 @@ class ListUsers(Command):
for u in userList.values():
if args.all or u.enabled:
print(" {name}".format(name=u.name))
class HasUser(Command):
"""
internal command used by the debian config scripts to test if the admin user has already been created
"""
def run(self, args):
userList = UserList()
if args.user in userList:
if not args.silent:
print('User "{name}" exists.'.format(name=args.user))
else:
if not args.silent:
print('User "{name}" does not exist.'.format(name=args.user))
# in bash, a return code > 0 is interpreted as "false"
sys.exit(1)