[docs]classTuoniUser:""" A class that provides data and functionality for users. Attributes: username (str): The username of the user. enabled (bool): Indicates whether the user is enabled. authorities (list[str]): A list of authorities or roles assigned to the user. """def__init__(self,conf,c2):""" Constructor for the result part class. Args: conf (dict): Data from the server. c2 (TuoniC2): The related server object that manages communication. """self._load_conf(conf)self.c2=c2def_load_conf(self,conf):self.username=conf["username"]self.enabled=conf["enabled"]self.authorities=conf["authorities"]
[docs]defreload(self):""" Reload the user data from the C2 server. """ifself.alias_idisNone:raiseExceptionTuoniDeleted("")data=self.c2.request_get("/api/v1/users/%s"%self.username)self._load_conf(data)
[docs]defdisable(self):""" Disable the user. """data={"enabled":False,"authorities":self.authorities}data=self.c2.request_put("/api/v1/users/%s"%self.username,data)self._load_conf(data)
[docs]defenable(self):""" Enable the user. """data={"enabled":True,"authorities":self.authorities}data=self.c2.request_put("/api/v1/users/%s"%self.username,data)self._load_conf(data)
[docs]defset_authorities(self,authorities):""" Change the authorities assigned to the user. """data={"authorities":authorities,"enabled":self.enabled}data=self.c2.request_put("/api/v1/users/%s"%self.username,data)self._load_conf(data)
[docs]defset_password(self,new_password):""" Set a new password for the user. """data={"newPassword":new_password}data=self.c2.request_put("/api/v1/users/%s/password"%self.username,data)