From 3d4edad989c5d00ed3180f84675f074f7a0807e0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 13 Sep 2023 16:02:29 +0200 Subject: [PATCH] Fixed error with group users addition --- add_group_users.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 add_group_users.py diff --git a/add_group_users.py b/add_group_users.py new file mode 100755 index 0000000..51b46b2 --- /dev/null +++ b/add_group_users.py @@ -0,0 +1,36 @@ +import psycopg2 +import bioblend.galaxy +import sys + +conn = psycopg2.connect(database="galaxy", user="postgres") +cursor = conn.cursor() +cursor.execute("SELECT * FROM galaxy_user") +users = cursor.fetchall() +user_dict = dict() + +for user in users: + user_dict[user[0]] = user[3] # id is key, email is value + +cursor.execute("SELECT * FROM custos_authnz_token") +einfra_users = cursor.fetchall() + +einfra_emails = [] +for einfra_user in einfra_users: + einfra_emails.append(user_dict[einfra_user[1]]) + +server = 'https://' + sys.argv[1] +api_key = sys.argv[2] +gi = bioblend.galaxy.GalaxyInstance(url=server, key=api_key) + +api_users = gi.users.get_users() +id_dict = dict() +for user in api_users: + id_dict[user['email']] = user['id'] + +groups = gi.groups.get_groups() +for group in groups: + if group['name'] == 'E-infra': + group_id = group['id'] + +for mail in einfra_emails: + gi.groups.add_group_user(group_id=group_id, user_id=id_dict[mail])