Skip to content

Commit 8f83e50

Browse files
authored
Merge pull request #713 from MetaCell/release/2.2.0
Release/2.2.0
2 parents 8f52735 + d877554 commit 8f83e50

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

libraries/cloudharness-common/cloudharness/auth/keycloak.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,19 @@ def get_user(self, user_id, with_details=False) -> User:
442442
raise UserNotFound(user_id)
443443
except InvalidToken as e:
444444
raise UserNotFound(user_id)
445+
445446

446447
else:
447-
found_users = admin_client.get_users({"username": user_id})
448+
found_users = admin_client.get_users({"username": user_id, "exact": True})
448449
if len(found_users) == 0:
449450
raise UserNotFound(user_id)
450-
user = admin_client.get_user(found_users[0]['id']) # Load full data
451-
451+
try:
452+
user = admin_client.get_user(found_users[0]['id']) # Load full data
453+
except KeycloakGetError as e:
454+
raise UserNotFound(user_id)
455+
except InvalidToken as e:
456+
raise UserNotFound(user_id)
457+
452458
user.update({
453459
"userGroups": admin_client.get_user_groups(user_id=user['id'], brief_representation=not with_details),
454460
'realmRoles': admin_client.get_realm_roles_of_user(user['id'])

libraries/cloudharness-common/cloudharness/auth/quota.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from keycloak import KeycloakError
23
from .keycloak import AuthClient
34
from cloudharness.applications import get_current_configuration
@@ -93,17 +94,23 @@ def _compute_quotas_from_tree(node: QuotaNode):
9394
child_attrs = _compute_quotas_from_tree(child)
9495
for key in child_attrs:
9596
try:
96-
child_val = float(child_attrs[key])
97+
# we expect all quota values to be numbers: the unit is implicit and
98+
# defined at usage time
99+
child_val = attribute_to_quota(child_attrs[key])
97100
except:
98-
# value not a float, skip (use 0)
99-
child_val = 0
101+
# value not a float, skip
102+
continue
100103
if not key in new_attrs or new_attrs[key] < child_val:
101104
new_attrs.update({key: child_val})
102105
for key in new_attrs:
103106
node.attrs.update({key: new_attrs[key]})
104107
return node.attrs
105108

106109

110+
def attribute_to_quota(attr_value: str):
111+
return float(re.sub("[^0-9.]", "", attr_value) if type(attr_value) is str else attr_value)
112+
113+
107114
def get_user_quotas(application_config: ApplicationConfig = None, user_id: str = None) -> dict:
108115
"""Get the user quota from Keycloak and application
109116
@@ -142,5 +149,5 @@ def get_user_quotas(application_config: ApplicationConfig = None, user_id: str =
142149
user_quotas.update({key: group_quotas[key]})
143150
for key in base_quotas:
144151
if key not in user_quotas:
145-
user_quotas.update({key: base_quotas[key]})
152+
user_quotas.update({key: attribute_to_quota(base_quotas[key])})
146153
return user_quotas

0 commit comments

Comments
 (0)