Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YDA-5414 - Added function to generate unique short name for groups. #343

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()