System: aio_register, performs all neccessary steps to create user...

BUT will NOT catch ANY exceptions. Therefore the caller script itself is
REQUIRED to catch.
feature-admin-split
Darksider3 5 years ago
parent dd01acf801
commit f31117e940

@ -44,10 +44,7 @@ def import_from_file(file_path: str, db: str, user_ids: tuple = tuple([])) -> bo
if row["status"] == "1":
try:
sys_ctl.setUser(row["username"])
sys_ctl.register()
sys_ctl.lock_user_pw()
sys_ctl.add_to_usergroup()
sys_ctl.make_ssh_usable(row["pubkey"])
sys_ctl.aio_register(row["pubkey"])
print(row['username'], "====> Registered.")
except lib.UserExceptions.UserExistsAlready as UEA:
pass # @TODO User was determined to exists already, shouldn't happen but is possible

@ -141,10 +141,7 @@ if __name__ == "__main__":
print(f"Could not update Users status in database")
exit(1)
try:
sys_ctl.register()
sys_ctl.lock_user_pw()
sys_ctl.add_to_usergroup()
sys_ctl.make_ssh_usable(CurrentUser["pubkey"])
sys_ctl.aio_register(CurrentUser["pubkey"])
except lib.UserExceptions.UserExistsAlready as UEA:
print(f"Somehow the user exists already on the system! {UEA}")
exit(1)

@ -45,6 +45,26 @@ class System:
self.home = home
self.user = username
def aio_register(self, pubkey, group="tilde"):
""" Executes all neccessary steps to create a user from itself. Raises ALOT of possible exceptions
:Note: CAREFULL! You MUST except the exceptions!
:param pubkey: Users public ssh key
:type pubkey: str
:param group: User-group. Defaults to tilde
:type group: str
:return: None
:raises:
lib.UserExceptions.UserExistsAlready: User Exists already on system
lib.UserExceptions.UnknownReturnCode: Unknown Return Code from useradd
lib.UserExceptions.SSHDirUncreatable: Users SSH Dir couldnt be created
lib.UserExceptions.ModifyFilesystem: Something with CHMOD failed
"""
self.register()
self.lock_user_pw()
self.add_to_usergroup(group)
self.make_ssh_usable(pubkey)
def register(self, cc: tuple = tuple(["useradd", "-m"])) -> bool:
"""Creates an local account for the given username
@ -226,14 +246,6 @@ class System:
return True
def AIO(username, pubkey, group="tilde"):
sys_ctl = System(username, dryrun=False)
sys_ctl.register()
sys_ctl.lock_user_pw()
sys_ctl.add_to_usergroup(group)
sys_ctl.make_ssh_usable(pubkey)
if __name__ == "__main__":
try:
S = System("dar", dryrun=True)

Loading…
Cancel
Save