def key_handler(self, username, user_type, list_name, key):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("{0} user list before the change: {1}".format(user_type, json.dumps(user_list)))
     if user_list:
         self.logger.debug("The {0} user list exists!".format(user_type))
         for val in user_list:
             if val["name"] == username:
                 val["public_key"] = key
                 break
         self.logger.debug("{0} user list after the change: {1}".format(user_type, json.dumps(user_list)))
         cmc.set_property(list_name, json.dumps(user_list))
Example #2
0
 def check_chroot_linux_state(self, username, list_name, state):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("Start the user list check")
     self.logger.debug("Checked {0} user list : {1}".format(
         list_name, json.dumps(user_list)))
     for val in user_list:
         if val["name"] == username and val["state"] == state:
             self.logger.debug("{0} checked!".format(username))
             return True
     self.logger.debug("{0} failed to check!".format(username))
     return False
Example #3
0
 def check_chroot_linux_pass_state(self, username, list_name, password):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("Start the user list check")
     for val in user_list:
         if val["name"] == username and val["password"] == password:
             self.logger.debug(
                 "{0} user's password changed!".format(username))
             return True
     self.logger.debug(
         "{0} user's password is not changed!".format(username))
     return False
 def lock_state_handler(self, username, user_type, list_name, state):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("{0} user list before the change: {1}".format(
         user_type, json.dumps(user_list)))
     if user_list is not None:
         self.logger.debug("The {0} user list exists!".format(user_type))
         for val in user_list:
             if val["name"] == username:
                 val["lock_state"] = state
                 break
         self.logger.debug("{0} user list after the change: {1}".format(
             user_type, json.dumps(user_list)))
         cmc.set_property(list_name, json.dumps(user_list))
Example #5
0
 def linux_chroot_pass_handling(self, username, user_type, list_name,
                                passwd):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("{0} user list before the change: {1}".format(
         user_type, json.dumps(user_list)))
     if user_list is not None:
         self.logger.debug("The {0} user list exist!".format(user_type))
         for val in user_list:
             if val["name"] == username:
                 val["password"] = passwd
                 break
         self.logger.debug("{0} user list after the change: {1}".format(
             user_type, json.dumps(user_list)))
         cmc.set_property(list_name, json.dumps(user_list))
Example #6
0
 def add_chroot_linux_role_handling(self, user_id, user_type, list_name,
                                    group):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     if user_list is None:
         cmc.set_property(list_name, json.dumps([]))
         user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("{0} user list before the change: {1}".format(
         user_type, json.dumps(user_list)))
     add = True
     self.logger.debug("The {0} user list exists!".format(user_type))
     username, def_project = self.get_user_from_uuid(user_id)
     self.logger.debug("Username: {0}".format(username))
     for element in user_list:
         if element["name"] == username:
             if element["state"] == "present":
                 self.logger.error(
                     "The {0} user has an active {1} chroot role".format(
                         username, element["group"]))
                 self.db.delete_user_role(user_id, group)
                 return False, "The {0} users have an active {1} chroot role".format(
                     username, element["group"])
             else:
                 self.logger.debug(
                     "The {0} user has an active linux_user role".format(
                         username))
                 if group is not None:
                     element["group"] = group
                 element["state"] = "present"
                 element["remove"] = "no"
                 add = False
     if add:
         new_user = {
             "name": username,
             "password": "",
             "state": "present",
             "remove": "no",
             "lock_state": "-u",
             "public_key": ""
         }
         if group is not None:
             new_user["group"] = group
         user_list.append(new_user)
     self.logger.debug("{0} user list after the change: {1}".format(
         user_type, json.dumps(user_list)))
     cmc.set_property(list_name, json.dumps(user_list))
Example #7
0
 def remove_chroot_linux_role_handling(self, username, user_type,
                                       list_name):
     cmc = cmclient.CMClient()
     user_list = cmc.get_property(list_name)
     user_list = json.loads(user_list)
     self.logger.debug("{0} user list before the change: {1}".format(
         user_type, json.dumps(user_list)))
     if user_list is not None:
         self.logger.debug("The {0} user list exists!".format(user_type))
         for val in user_list:
             if val["name"] == username:
                 val["public_key"] = ""
                 val["state"] = "absent"
                 val["remove"] = "yes"
                 val["password"] = ""
                 break
         self.logger.debug("{0} user list after the change: {1}".format(
             user_type, json.dumps(user_list)))
         cmc.set_property(list_name, json.dumps(user_list))
Example #8
0
 def _update_caas_config(self, updated):
     api = cmclient.CMClient()
     api.set_property(self.KEY_CAAS, json.dumps(updated))
Example #9
0
 def _get_caas_config(self):
     api = cmclient.CMClient()
     return json.loads(api.get_property(self.KEY_CAAS))