From 720fa26bcfef3bbd2c8f0cbb29fb043d859c2a2c Mon Sep 17 00:00:00 2001 From: Nicholas Albion Date: Fri, 8 Sep 2023 03:56:17 +1000 Subject: [PATCH 1/2] user_id defaults to OS username --- pilot/utils/arguments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pilot/utils/arguments.py b/pilot/utils/arguments.py index 8590373..79a66b9 100644 --- a/pilot/utils/arguments.py +++ b/pilot/utils/arguments.py @@ -1,3 +1,4 @@ +import getpass import sys import uuid @@ -36,7 +37,7 @@ def get_arguments(): arguments['app_id'] = str(uuid.uuid4()) if 'user_id' not in arguments: - arguments['user_id'] = str(uuid.uuid4()) + arguments['user_id'] = getpass.getuser() if 'email' not in arguments: # todo change email so its not uuid4 but make sure to fix storing of development steps where From e33616450da4131751062c80cbbf2e526f219203 Mon Sep 17 00:00:00 2001 From: Nicholas Albion Date: Fri, 8 Sep 2023 15:14:49 +1000 Subject: [PATCH 2/2] BaseModel.id is a UUIDField, create UUID from username --- pilot/utils/arguments.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pilot/utils/arguments.py b/pilot/utils/arguments.py index 79a66b9..cb1aa89 100644 --- a/pilot/utils/arguments.py +++ b/pilot/utils/arguments.py @@ -1,4 +1,5 @@ import getpass +import hashlib import sys import uuid @@ -37,7 +38,7 @@ def get_arguments(): arguments['app_id'] = str(uuid.uuid4()) if 'user_id' not in arguments: - arguments['user_id'] = getpass.getuser() + arguments['user_id'] = username_to_uuid(getpass.getuser()) if 'email' not in arguments: # todo change email so its not uuid4 but make sure to fix storing of development steps where @@ -55,3 +56,10 @@ def get_arguments(): print(colored(f'python main.py app_id={arguments["app_id"]}', 'green', attrs=['bold'])) print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold'])) return arguments + + +# TODO can we make BaseModel.id a CharField with default=uuid4? +def username_to_uuid(username): + sha1 = hashlib.sha1(username.encode()).hexdigest() + uuid_str = "{}-{}-{}-{}-{}".format(sha1[:8], sha1[8:12], sha1[12:16], sha1[16:20], sha1[20:32]) + return str(uuid.UUID(uuid_str))