def get_all_users(args): """ Gets the users from the server. :param args: The command line arguments. :return: The list of users and groups from the server. :rtype: list of User """ sync = SyncUserAndGroups( tsurl=args.ts_url, username=args.username, password=args.password, disable_ssl=args.disable_ssl, ) return sync.get_user_metadata()
def main(): """ Synchronize users and groups with ThoughtSpot from a properly formatted Excel file. """ args = parse_args() if valid_args(args): uags = UGXLSReader().read_from_excel(args.filename) sync = SyncUserAndGroups( tsurl=args.ts_url, username=args.username, password=args.password, disable_ssl=args.disable_ssl, ) sync.sync_users_and_groups(users_and_groups=uags, remove_deleted=args.purge)
def test_delete_one_group(self): """Tests deleting a single groups.""" self.create_common_users_and_groups() sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) sync.delete_group(groupname="Group1") auag = sync.get_all_users_and_groups() self.assertFalse(auag.has_group("Group1")) self.assertTrue(auag.has_group("Group2")) self.assertTrue(auag.has_group('Group"3"'))
def test_delete_user_list(self): """Tests deleting of a list of users.""" self.create_common_users_and_groups() sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) sync.delete_users(usernames=["User1", "User2", "UserX"]) auag = sync.get_all_users_and_groups() self.assertFalse(auag.has_user("User1")) self.assertFalse(auag.has_user("User2")) self.assertTrue(auag.has_user('User"3"'))
def test_syncing_user_and_groups_without_password(self): """ Tests adding users and groups to ThoughtSpot. """ auag = UsersAndGroups() auag.add_group( Group( name="Group 1", display_name="This is Group 1", description="A group for testing.", group_names=[], )) auag.add_group( Group( name="Group 2", display_name="This is Group 2", description="Another group for testing.", group_names=["Group 1"], )) auag.add_user( User( name="User1", password="******", display_name="User 1", group_names=["Group 1"], )) auag.add_user( User( name="User2", password="******", display_name="User 2", group_names=["Group 1", "Group 2"], )) # only works on Bill's AWS instance. sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, global_password="******", disable_ssl=True, ) sync.sync_users_and_groups(auag)
def test_update_password(self): """ Tests updating a user password. """ sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) auag = UsersAndGroups() auag.add_user( User(name="userx", display_name="User X", password="******")) sync.update_user_password(userid="userx", currentpassword="******", password="******")
def test_getting_all(self): """ Tests getting all users from the server. """ self.create_common_users_and_groups() sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) auag = sync.get_all_users_and_groups() # There are four constant users, tsadmin, guest, su, system self.assertEqual(auag.number_users(), 7) # There are two constant groups, Administrator and System self.assertEqual(auag.number_groups(), 6)
def test_update_non_shareable(self): """ Tests updating groups that are non-shareable. """ self.create_common_users_and_groups() sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) auag = sync.get_all_users_and_groups() # Change Group 1 and Group 2 and verify change took. group1 = auag.get_group("Group 1") group1.visibility = Visibility.NON_SHAREABLE group2 = auag.get_group("Group 2") group2.visibility = Visibility.DEFAULT # sync updates sync.sync_users_and_groups(users_and_groups=auag) # verify changes auag = sync.get_all_users_and_groups() self.assertEqual( auag.get_group("Group 1").visibility, Visibility.NON_SHAREABLE) self.assertEqual( auag.get_group("Group 2").visibility, Visibility.DEFAULT) self.assertEqual( auag.get_group('Group "3"').visibility, Visibility.NON_SHAREABLE)
def test_syncing_user_and_groups(self): """ Tests adding users and groups to ThoughtSpot. """ sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) auag = sync.get_all_users_and_groups() group1 = auag.get_group("Group 1") self.assertEqual("Group 1", group1.name) self.assertEqual("This is Group 1", group1.displayName) self.assertEqual("A group for testing.", group1.description) self.assertEqual([], group1.groupNames) self.assertEqual(Visibility.DEFAULT, group1.visibility) group2 = auag.get_group("Group 2") self.assertEqual("Group 2", group2.name) self.assertEqual("This is Group 2", group2.displayName) self.assertEqual("Another group for testing.", group2.description) self.assertEqual(["Group 1"], group2.groupNames) self.assertEqual(Visibility.NON_SHAREABLE, group2.visibility) user1 = auag.get_user("User1") self.assertEqual("User1", user1.name) self.assertEqual("User 1", user1.displayName) self.assertEqual(["All", "Group 1"], user1.groupNames) self.assertEqual(Visibility.DEFAULT, user1.visibility) user2 = auag.get_user("User2") self.assertEqual("User2", user2.name) self.assertEqual("User 2", user2.displayName) self.assertEqual(sorted(["All", "Group 1", "Group 2"]), sorted(user2.groupNames)) self.assertEqual(Visibility.NON_SHAREABLE, user2.visibility)
def dump_users_and_groups(args): """ Gets users and groups from the server and dumps them in the correct format. :param args: The command line arguments. """ sync = SyncUserAndGroups( tsurl=args.ts_url, username=args.username, password=args.password, disable_ssl=args.disable_ssl, ) all_users_and_groups = sync.get_all_users_and_groups() print("writing to %s" % args.filename) if args.output_type == "json": with open(args.filename, "w") as outfile: outfile.write(all_users_and_groups.to_json()) else: writer = UGXLSWriter() writer.write(users_and_groups=all_users_and_groups, filename=args.filename)
def main(): """Main function for the script.""" args = parse_args() if valid_args(args): sync = SyncUserAndGroups( tsurl=args.ts_url, username=args.username, password=args.password, disable_ssl=args.disable_ssl, ) if args.users is not None: delete_users(args, sync) if args.user_file is not None: delete_users_from_file(args, sync) if args.groups is not None: delete_groups(args, sync) if args.group_file is not None: delete_groups_from_file(args, sync)
def create_common_users_and_groups(self): """ Creates a set of users and groups that can be used in multiple tests. """ auag = UsersAndGroups() auag.add_group( Group( name="Group 1", display_name="This is Group 1", description="A group for testing.", group_names=[], visibility=Visibility.DEFAULT, )) auag.add_group( Group( name="Group 2", display_name="This is Group 2", description="Another group for testing.", group_names=["Group 1"], visibility=Visibility.NON_SHAREABLE, )) # Testing for ability to handle embedded quotes. auag.add_group( Group( name='Group "3"', display_name='This is Group "3"', description='Another "group" for testing.', group_names=["Group 1"], visibility=Visibility.NON_SHAREABLE, )) auag.add_user( User( name="User1", password="******", display_name="User 1", mail="*****@*****.**", group_names=["Group 1"], )) auag.add_user( User( name="User2", password="******", display_name="User 2", mail="*****@*****.**", group_names=["Group 1", "Group 2"], visibility=Visibility.NON_SHAREABLE, )) # Testing for ability to handle embedded quotes. auag.add_user( User( name='User "3"', password="******", display_name='User "3"', mail="*****@*****.**", group_names=['Group "3"'], )) print(auag) sync = SyncUserAndGroups( tsurl=TS_URL, username=TS_USER, password=TS_PASSWORD, disable_ssl=True, ) sync.sync_users_and_groups(auag, remove_deleted=True)