Esempio n. 1
0
 def add_role_group(self, group_name, roles, ldap_ref, host):
     log.info("Group name -- {0} :: Roles -- {1} :: LDAP REF -- {2}".format(
         group_name, roles, ldap_ref))
     rest = RestConnection(host)
     # group_name, description, roles, ldap_group_ref = None)
     if ldap_ref == None:
         status, content = rest.add_group_role(group_name, group_name,
                                               roles, None)
     if ldap_ref != None:
         status, content = rest.add_group_role(group_name, group_name,
                                               roles, ldap_ref)
     log.info("Output of adding group to roles is {0} - {1}".format(
         status, content))
Esempio n. 2
0
    def remove_role_existing_grp(self, group_names, groles, ldap_ref, host):
        for index, group_name in enumerate(group_names):
            Gcontent = self.get_group_detail(group_name, host)
            Gcontent = Gcontent[1]
            Groles = Gcontent['roles']
            roles = ""
            for role in Groles:
                roles = roles + "," + role['role']
            if (roles[0] == ","):
                roles = roles[1:]
            final_roles = roles.split("," + groles[index])
            if (len(final_roles) == 1 and final_roles[0] == groles[0]):
                final_roles = ""
            roles = ""
            for i in final_roles:
                roles = roles + i

            log.info(
                "Group name -- {0} :: Roles -- {1} :: LDAP REF -- {2}".format(
                    group_name, roles, ldap_ref))
            rest = RestConnection(host)
            status, content = rest.add_group_role(group_name, group_name,
                                                  roles, ldap_ref)
            log.info("Output of adding group to roles is {0} - {1}".format(
                status, content))
            rest = RestConnection(host)
            content = rbacmain(master_ip=host,
                               auth_type='builtin')._retrieve_user_roles()
            content = rbacmain(master_ip=host,
                               auth_type='builtin')._retrieve_user_roles()
            return content
Esempio n. 3
0
    def create_ldap_grp_user(self,
                             group_no,
                             user_no,
                             roles,
                             host,
                             grp_prefix='grp',
                             usr_prefix='usr',
                             external=False):
        user_list = []
        grp_list = []
        final_usr_list = []
        for i in range(0, int(group_no)):
            for j in range(0, len(user_no)):
                user_name = usr_prefix + str(i) + str(j)
                self.create_grp_usr_ldap(user_name, host)
                user_list.append(user_name)
            LdapGroup().group_setup(grp_prefix + str(i), user_list, host)
            grp_list.append(grp_prefix + str(i))
            final_usr_list.append(user_list)
            user_list = []
        final_roles = ""
        for i in range(0, int(group_no)):
            if '?' in roles[i]:
                current_role = roles[i].split('?')
            else:
                current_role = [roles[i]]
            if len(current_role) == 1:
                final_roles = current_role[0]
            else:
                for role in current_role:
                    final_roles = role + "," + final_roles
            group_dn = 'cn=' + grp_list[i] + ',' + self.LDAP_GROUP_DN

            rest = RestConnection(host)
            status, content = rest.add_group_role(grp_list[i], grp_list[i],
                                                  final_roles, group_dn)

        if external:
            for i, group in enumerate(grp_list):
                self.create_grp_usr_external(final_usr_list[i], host,
                                             [''] * len(final_usr_list[i]),
                                             group)

        return grp_list, final_usr_list