Skip to content

Commit

Permalink
Fixed error with group users addition
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Sep 13, 2023
1 parent 2f8e01d commit 3d4edad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions add_group_users.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit 3d4edad

Please sign in to comment.