From 9aa720ddaa358ffed751856762b880e94c78627f Mon Sep 17 00:00:00 2001 From: kaur16 <126662478+kaur16@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:09:24 +0200 Subject: [PATCH] YDA-5414 : added function to generate unique short name for SRAM groups --- requirements.txt | 1 + sram.py | 5 ++++- util/group.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7cfc35673..f77c3c25d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ pysqlcipher3==1.0.4 execnet==1.9.0 deepdiff==3.3.0 persist-queue==0.8.1 +pyblake2==1.1.2 diff --git a/sram.py b/sram.py index 2e17b332c..db33bd221 100644 --- a/sram.py +++ b/sram.py @@ -36,6 +36,9 @@ def sram_post_collaboration(ctx, group_name, description, expiration_date): epoch = datetime.datetime.utcfromtimestamp(0) epoch_date = int((date - epoch).total_seconds()) + # Create unique short name of group + short_name = group.unique_short_name(ctx, group_name) + disable_join_requests = True if config.sram_flow == 'join_request': disable_join_requests = False @@ -43,7 +46,7 @@ def sram_post_collaboration(ctx, group_name, description, expiration_date): # Build SRAM payload. payload = { "name": 'yoda-' + group_name, - "short_name": group_name, + "short_name": short_name, "description": description, "disable_join_requests": disable_join_requests, "disclose_member_information": True, diff --git a/util/group.py b/util/group.py index 801d0e81a..fe355ffa1 100644 --- a/util/group.py +++ b/util/group.py @@ -5,6 +5,7 @@ __license__ = 'GPLv3, see LICENSE' import genquery +from pyblake2 import blake2b import user @@ -57,3 +58,21 @@ def get_category(ctx, grp): ret = ctx.uuGroupGetCategory(grp, '', '') x = ret['arguments'][1] return None if x == '' else x + + +def unique_short_name(ctx, grp): + """Create unique short name for group in SRAM. + + :param ctx: Combined type of a callback and rei struct + :param grp: Group name + + :returns: blake2b conversion of zone and group name + """ + zone = user.zone(ctx) + concat_string = zone + grp + + # Create hash of 16 characters + short_name = blake2b(digest_size=8) + short_name.update(concat_string.encode()) + + return short_name.hexdigest()