Skip to content

Commit

Permalink
SRAM: do not generate short names for collaborations
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Dec 14, 2023
1 parent d2eb561 commit a01bec9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
6 changes: 4 additions & 2 deletions groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,9 @@ def group_create(ctx, group_name, category, subcategory, schema_id, expiration_d
return api.Error('sram_error', message)
else:
co_identifier = response_sram['identifier']
short_name = response_sram['short_name']

if not sram.sram_connect_service_collaboration(ctx, group_name):
if not sram.sram_connect_service_collaboration(ctx, short_name):
return api.Error('sram_error', 'Something went wrong connecting service to group "{}" in SRAM'.format(group_name))

response = ctx.uuGroupAdd(group_name, category, subcategory, schema_id, expiration_date, description, data_classification, co_identifier, '', '')['arguments']
Expand Down Expand Up @@ -1337,9 +1338,10 @@ def rule_group_sram_sync(ctx):
break
else:
co_identifier = response_sram['identifier']
short_name = response_sram['short_name']
avu.associate_to_group(ctx, group_name, "co_identifier", co_identifier)

if not sram.sram_connect_service_collaboration(ctx, group_name):
if not sram.sram_connect_service_collaboration(ctx, short_name):
log.write(ctx, "Something went wrong connecting service to group {} in SRAM".format(group_name))
break

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ pysqlcipher3==1.0.4
execnet==1.9.0
deepdiff==3.3.0
persist-queue==0.8.1
pyblake2==1.1.2
redis==3.5.3
psutil==5.9.6
11 changes: 2 additions & 9 deletions sram.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ 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": short_name,
"description": description,
"disable_join_requests": disable_join_requests,
"disclose_member_information": True,
Expand Down Expand Up @@ -190,20 +186,17 @@ def sram_put_collaboration_invitation(ctx, group_name, username, co_identifier):
return response.status_code == 201


def sram_connect_service_collaboration(ctx, group_name):
def sram_connect_service_collaboration(ctx, short_name):
"""Connect a service to an existing SRAM collaboration.
:param ctx: Combined type of a ctx and rei struct
:param group_name: Name of the group
:param short_name: Short name of the group collaboration
:returns: Boolean indicating if connecting a service to an existing collaboration succeeded
"""
url = "{}/api/collaborations_services/v1/connect_collaboration_service".format(config.sram_rest_api_url)
headers = {'Content-Type': 'application/json', 'charset': 'UTF-8', 'Authorization': 'bearer ' + config.sram_api_key}

# Create unique short name of group
short_name = group.unique_short_name(ctx, group_name)

# Build SRAM payload.
payload = {
"short_name": short_name,
Expand Down
21 changes: 1 addition & 20 deletions util/group.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
"""Utility / convenience functions for querying user info."""

__copyright__ = 'Copyright (c) 2019-2021, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2023, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import genquery
from pyblake2 import blake2b

import user

Expand Down Expand Up @@ -58,21 +57,3 @@ def get_category(ctx, grp):
ret = ctx.uuGroupGetCategory(grp, '', '')
x = ret['arguments'][1]
return None if x == '' else x


def unique_short_name(ctx, group_name):
"""Create unique short name for group in SRAM.
:param ctx: Combined type of a callback and rei struct
:param group_name: Group name
:returns: Blake2b hash of zone and group name prefixed with y
"""
zone = user.zone(ctx)
concat_string = zone + group_name

# Create hash of 16 characters
short_name = blake2b(digest_size=7)
short_name.update(concat_string.encode())

return "y_{}".format(short_name.hexdigest())

0 comments on commit a01bec9

Please sign in to comment.