Skip to content

Commit

Permalink
checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
jctanner committed Oct 5, 2023
1 parent 3bf8c62 commit bca9099
Showing 1 changed file with 62 additions and 8 deletions.
70 changes: 62 additions & 8 deletions dev/scripts.community/check_validated_user_namespace_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from galaxy_ng.app.models import Namespace
from galaxy_ng.app.api.v1.models import LegacyNamespace
from galaxy_ng.app.utils.namespaces import generate_v3_namespace_from_attributes
from galaxy_ng.app.utils import rbac


User = get_user_model()
Expand All @@ -25,29 +27,81 @@ def do_check():
uids = list(umap.keys())
uids = sorted(uids, key=lambda x: int(x))
for uid in uids:
print(uid)

old_data = umap[uid]
print(f"{uid} {old_data['galaxy_username']}")

# worry about these later ...
if not old_data.get('github_login_verified'):
continue

# worry about these later ...
if old_data['galaxy_username'] != old_data['github_login'] or \
(old_data.get('gitub_login_new') and old_data.get('gitub_login_new') != old_data['galaxy_username']):
continue

galaxy_username = old_data['galaxy_username']
github_login = old_data['github_login']
github_id = old_data['github_id']
if old_data['github_login_new']:
github_login = old_data['github_login_new']

# worry about this later ...
if galaxy_username != github_login:
continue

# find or make the user ...
found_user = User.objects.filter(username=galaxy_username).first()
if not found_user:
print(f'\tFIX - create user {galaxy_username}')
if not checkmode:
print(f'\t\tcheckmode:{checkmode} do user create ...')
found_user, _ = User.objects.get_or_create(username=galaxy_username)

#import epdb; epdb.st()
else:
continue

# check each owned namespace (v1+v3) ...
for ns_name in old_data.get('owned_namespaces', []):
found_v1_namespace = LegacyNamespace.objects.filter(name=ns_name).first()
if not found_v1_namespace:
print(f'\tFIX - create legacy namespace {ns_name}')
if not checkmode:
print(f'\t\tcheckmode:{checkmode} do legacy ns create ...')
found_v1_namespace,_ = LegacyNamespace.objects.get_or_create(name=ns_name)
else:
continue

# the v3 namespace has to be valid ...
v3_ns_name = generate_v3_namespace_from_attributes(username=ns_name)
# print(f'\tv3:{v3_ns_name}')

found_v3_namespace = Namespace.objects.filter(name=v3_ns_name).first()
if not found_v3_namespace:
print(f'\tFIX - create v3 namespace {v3_ns_name}')
if not checkmode:
print(f'\t\tcheckmode:{checkmode} do v3 ns create ...')
found_v3_namespace,_ = Namespace.objects.get_or_create(name=v3_ns_name)
else:
continue

# bind v3 to v1 ...
if found_v1_namespace.namespace != found_v3_namespace:
print(f'\tFIX - bind v3:{found_v3_namespace} to v1:{found_v1_namespace}')
if not checkmode:
print(f'\t\tcheckmode:{checkmode} do v3->v1 bind ...')
try:
found_v1_namespace.namespace = found_v3_namespace
found_v1_namespace.save()
except ValueError:
import epdb; epdb.st()
else:
continue

current_owners = rbac.get_v3_namespace_owners(found_v3_namespace)
if found_user not in current_owners:
print(f'\tFIX - add {found_user} as owner of v3:{found_v3_namespace}')
if not checkmode:
print(f'\t\tcheckmode:{checkmode} do owner add...')
rbac.add_user_to_v3_namespace(found_user, found_v3_namespace)
else:
continue

#import epdb; epdb.st()



Expand Down

0 comments on commit bca9099

Please sign in to comment.