Skip to content

Commit

Permalink
YDA-5414 : added function to generate unique short name for SRAM groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kaur16 authored Oct 10, 2023
1 parent b4ba301 commit 9aa720d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion sram.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ 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

# 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,
Expand Down
19 changes: 19 additions & 0 deletions util/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__license__ = 'GPLv3, see LICENSE'

import genquery
from pyblake2 import blake2b

import user

Expand Down Expand Up @@ -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()

0 comments on commit 9aa720d

Please sign in to comment.