Skip to content

Commit aacfe5d

Browse files
committed
Merge branch 'feature/CH-152' of github.com:MetaCell/cloud-harness into feature/CH-152
2 parents bf2b204 + 59446a2 commit aacfe5d

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_user_quotas(application_config: ApplicationConfig = None, user_id: str =
3939
valid_keys_map = {key for key in base_quotas}
4040

4141
try:
42-
return get_user_attributes(user_id, valid_keys_map=valid_keys_map, default_attributes=base_quotas)
42+
return get_user_attributes(user_id, valid_keys=valid_keys_map, default_attributes=base_quotas)
4343

4444
except UserNotFound as e:
4545
log.warning("Quotas not available: error retrieving user: %s", user_id)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ def addChild(self, child):
1616
self.children.append(child)
1717

1818

19-
def _filter_attrs(attrs, valid_keys_map):
19+
def _filter_attrs(attrs, valid_keys):
2020
# only use the attributes defined by the valid keys map
2121
valid_attrs = {}
2222
if attrs is None:
2323
return valid_attrs
2424
for key in attrs:
25-
if key in valid_keys_map:
25+
if key in valid_keys:
2626
# map to value
2727
valid_attrs.update({key: attrs[key][0]})
2828
return valid_attrs
2929

3030

31-
def _construct_attribute_tree(groups, valid_keys_map) -> KCAttributeNode:
31+
def _construct_attribute_tree(groups, valid_keys) -> KCAttributeNode:
3232
"""Construct a tree of attributes from the user groups"""
3333
root = KCAttributeNode("root", {})
3434
for group in groups:
@@ -49,7 +49,7 @@ def _construct_attribute_tree(groups, valid_keys_map) -> KCAttributeNode:
4949
# add the child with it's attributes and last segment name
5050
n = KCAttributeNode(
5151
paths[len(paths) - 1],
52-
_filter_attrs(group["attributes"], valid_keys_map)
52+
_filter_attrs(group["attributes"], valid_keys)
5353
)
5454
r.addChild(n)
5555
return root
@@ -103,12 +103,12 @@ def _compute_attributes_from_tree(node: KCAttributeNode, transform_value_fn=lamb
103103
return node.attrs
104104

105105

106-
def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attributes={}, transform_value_fn=lambda x: x) -> dict:
106+
def get_user_attributes(user_id: str = None, valid_keys={}, default_attributes={}, transform_value_fn=lambda x: x) -> dict:
107107
"""Get the user attributes from Keycloak recursively from the user attributes and groups
108108
109109
Args:
110110
user_id (str): the Keycloak user id or username to get the quotas for
111-
valid_keys_map (dict): the valid keys to use for the attributes
111+
valid_keys (iterable): the valid keys to use for the attributes
112112
default_attributes (dict): the default attributes to use if the user does not have the attribute
113113
114114
Returns:
@@ -130,8 +130,8 @@ def get_user_attributes(user_id: str = None, valid_keys_map={}, default_attribut
130130
group_quotas = _compute_attributes_from_tree(
131131
_construct_attribute_tree(
132132
user["userGroups"],
133-
valid_keys_map), transform_value_fn)
134-
user_attrs = _filter_attrs(user["attributes"], valid_keys_map)
133+
valid_keys), transform_value_fn)
134+
user_attrs = _filter_attrs(user["attributes"], valid_keys)
135135
for key in group_quotas:
136136
if key not in user_attrs:
137137
user_attrs.update({key: group_quotas[key]})

0 commit comments

Comments
 (0)