fix register_user_dlt when there are more than one user

This commit is contained in:
Cayo Puigdefabregas 2024-02-22 11:57:05 +01:00
parent e5dbb09025
commit 39f0300a28
1 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import json import json
import requests
import click import click
@ -11,7 +12,7 @@ from ereuse_devicehub.modules.dpp.utils import encrypt
class RegisterUserDlt: class RegisterUserDlt:
# "Operator", "Verifier" or "Witness" # "operator", "verifier" or "witness"
def __init__(self, app) -> None: def __init__(self, app) -> None:
super().__init__() super().__init__()
@ -59,18 +60,28 @@ class RegisterUserDlt:
roles = [] roles = []
try: try:
# TODO Not works abac_tk = app.config.get('ABAC_TOKEN')
with app.app_context(): domain = app.config.get('ABAC_URL')
ses = g.get('session', None) eth_pub_key = eth_pub_key
ses["eth_pub_key"] = eth_pub_key
attributes = user.get_abac_attributes() header = {
for c in attributes: 'Authorization': f'Bearer {abac_tk}',
if 'role' in c.get('attributeURI'): }
roles.append(c.get('attributeValue')) url = f'{domain}{eth_pub_key}/attributes'
r = requests.get(url, headers=header)
attributes = {}
for j in r.json():
k = j.get('attributeURI', '').split('/')[-1].split("#")[-1]
v = j.get('attributeValue', '').strip()
if not (k and v):
continue
attributes[k] = v
if attributes.get('role'):
roles.append(attributes.get('role'))
except Exception: except Exception:
roles = ["Operator"] roles = ["operator"]
user.rols_dlt = json.dumps(roles) user.rols_dlt = json.dumps(roles)
# if not user.id:
db.session.add(user) db.session.add(user)